Debug for a while, I found that the function:
bool NativeParser::ParseLocalBlock(ccSearchData* searchData, TokenIdxSet& search_scope, int caretPos)
{
if (s_DebugSmartSense)
CCLogger::Get()->DebugLog(_T("ParseLocalBlock() Parse local block"));
TRACE(_T("NativeParser::ParseLocalBlock()"));
int parentIdx = -1;
int blockStart = FindCurrentFunctionStart(searchData, nullptr, nullptr, &parentIdx, caretPos);
int initLine = 0;
if (parentIdx != -1)
{
TokenTree* tree = m_Parser->GetTokenTree();
CC_LOCKER_TRACK_TT_MTX_LOCK(s_TokenTreeMutex)
const Token* parent = tree->at(parentIdx);
if (parent && (parent->m_TokenKind & tkAnyFunction))
{
m_LastFuncTokenIdx = parent->m_Index;
initLine = parent->m_ImplLineStart;
}
CC_LOCKER_TRACK_TT_MTX_UNLOCK(s_TokenTreeMutex)
if (!parent)
return false;
}
if (blockStart != -1)
{
++blockStart; // skip {
cbStyledTextCtrl* stc = searchData->control;
const int pos = (caretPos == -1 ? stc->GetCurrentPos() : caretPos);
const int line = stc->LineFromPosition(pos);
const int blockEnd = stc->GetLineEndPosition(line);
if (blockEnd < 0 || blockEnd > stc->GetLength())
{
if (s_DebugSmartSense)
{
CCLogger::Get()->DebugLog(F(_T("ParseLocalBlock() ERROR blockEnd=%d and edLength=%d?!"),
blockEnd, stc->GetLength()));
}
return false;
}
if (blockStart >= blockEnd)
blockStart = blockEnd;
// wxString buffer = searchData->control->GetTextRange(blockStart, blockEnd);
wxString buffer;
// condense out-of-scope braces {...}
int scanPos = blockEnd;
for (int curPos = pos; curPos > blockStart; --curPos)
{
if (stc->GetCharAt(curPos) != wxT('}'))
continue;
const int style = stc->GetStyleAt(curPos);
if ( stc->IsString(style)
|| stc->IsCharacter(style)
|| stc->IsComment(style))
{
continue;
}
const int scopeStart = stc->BraceMatch(curPos);
if (scopeStart < blockStart)
break;
buffer.Prepend(stc->GetTextRange(curPos, scanPos));
int startLn = stc->LineFromPosition(scopeStart);
int endLn = stc->LineFromPosition(curPos);
if (startLn < endLn) // maintain correct line numbers for parsed tokens
buffer.Prepend( wxString(wxT('\n'), endLn - startLn) );
scanPos = scopeStart + 1;
curPos = scopeStart;
// condense out-of-scope for/if/while declarations
int prevCharIdx = scopeStart - 1;
for (; prevCharIdx > blockStart; --prevCharIdx)
{
if (stc->IsComment(stc->GetStyleAt(prevCharIdx)))
continue;
if (!wxIsspace(stc->GetCharAt(prevCharIdx)))
break;
}
if (stc->GetCharAt(prevCharIdx) != wxT(')'))
continue;
const int paramStart = stc->BraceMatch(prevCharIdx);
if (paramStart < blockStart)
continue;
for (prevCharIdx = paramStart - 1; prevCharIdx > blockStart; --prevCharIdx)
{
if (stc->IsComment(stc->GetStyleAt(prevCharIdx)))
continue;
if (!wxIsspace(stc->GetCharAt(prevCharIdx)))
break;
}
const wxString text = stc->GetTextRange(stc->WordStartPosition(prevCharIdx, true),
stc->WordEndPosition( prevCharIdx, true));
if (text == wxT("for"))
buffer.Prepend(wxT("(;;){"));
else if (text == wxT("if") || text == wxT("while"))
buffer.Prepend(wxT("(0){"));
else
continue;
startLn = stc->LineFromPosition(prevCharIdx);
endLn = stc->LineFromPosition(scopeStart);
if (startLn < endLn)
buffer.Prepend( wxString(wxT('\n'), endLn - startLn) );
curPos = stc->WordStartPosition(prevCharIdx, true);
scanPos = stc->WordEndPosition( prevCharIdx, true);
}
buffer.Prepend(stc->GetTextRange(blockStart, scanPos));
buffer.Trim();
The "buffer" is start with "lass". ???
EDIT
Oh, I see the code
if (blockStart != -1)
{
++blockStart; // skip {
But apparently, it was not "{", so the "c" of "class" was removed.
Index: E:/code/cb/cb_trunk_sf/src/plugins/codecompletion/nativeparser.cpp
===================================================================
--- E:/code/cb/cb_trunk_sf/src/plugins/codecompletion/nativeparser.cpp (revision 9090)
+++ E:/code/cb/cb_trunk_sf/src/plugins/codecompletion/nativeparser.cpp (working copy)
@@ -1857,8 +1857,9 @@
if (blockStart != -1)
{
- ++blockStart; // skip {
cbStyledTextCtrl* stc = searchData->control;
+ if (stc->GetCharAt(blockStart) == wxT('{'))
+ ++blockStart; // skip { if we are in a function body
const int pos = (caretPos == -1 ? stc->GetCurrentPos() : caretPos);
const int line = stc->LineFromPosition(pos);
const int blockEnd = stc->GetLineEndPosition(line);
The patch above should fix this bug.