1, if you remove the whole "{" block, you will remove all the EOL characters "\n", so after parsing the buffer, you variable location (line information) may be changed.
I never thought of that... I will see what I can do.
This should deal with it:
Index: src/plugins/codecompletion/nativeparser.cpp
===================================================================
--- src/plugins/codecompletion/nativeparser.cpp (revision 8585)
+++ src/plugins/codecompletion/nativeparser.cpp (working copy)
@@ -1857,7 +1857,33 @@
if (blockStart >= blockEnd)
blockStart = blockEnd;
- wxString buffer = searchData->control->GetTextRange(blockStart, blockEnd);
+ wxString buffer; // = searchData->control->GetTextRange(blockStart, blockEnd);
+ // condense out-of-scope braces {...}
+ int scanPos = blockEnd;
+ for (int curPos = pos; curPos > blockStart; --curPos)
+ {
+ if (searchData->control->GetCharAt(curPos) != wxT('}'))
+ continue;
+ const int style = searchData->control->GetStyleAt(curPos);
+ if ( searchData->control->IsString(style)
+ || searchData->control->IsCharacter(style)
+ || searchData->control->IsComment(style))
+ {
+ continue;
+ }
+ const int scopeStart = searchData->control->BraceMatch(curPos);
+ if (scopeStart < blockStart)
+ break;
+ buffer.Prepend(searchData->control->GetTextRange(curPos, scanPos));
+ const int startLn = searchData->control->LineFromPosition(scopeStart);
+ const int endLn = searchData->control->LineFromPosition(curPos);
+ if (startLn < endLn) // maintain correct line numbers for parsed tokens
+ buffer.Prepend( wxString(wxT('\n'), endLn - startLn) );
+ scanPos = scopeStart + 1;
+ curPos = scopeStart;
+ }
+ buffer.Prepend(searchData->control->GetTextRange(blockStart, scanPos));
+
buffer.Trim();
if ( !buffer.IsEmpty()
&& !m_Parser->ParseBuffer(buffer, false, false, true, searchData->file, m_LastFuncTokenIdx, initLine) )
Yes, this patch did conflict with the one for parsing of for loops. But sorry those days I'm a little busy, so I have no time to deeply test and merge those two patches.
...maybe ALPHA can do it - what I meant is this:
http://developer.berlios.de/patch/?func=detailpatch&patch_id=3345&group_id=5358
Have not looked at that patch yet, but if it is not too complicated, I will merge them.
The only conflict I can see (are there other conflicts I have missed?) is that:
int main()
{
for (int var_it = 0; var_it < 5; ++var_it)
{
int fooBar = var_it;
}
// "fooBar" correctly does not exist here (with the above patch)
// but "var_it" does exist (from loop declaration patch)
return 0;
}
When modifying
buffer, I think the proper way to condense
for loop arguments is:
for (int var_it = 0; var_it < 5; ++var_it)
{
// stuff...
}
to:
However, I am not certain about the other cases that the loop declaration patch handles; any suggestions?