Let me explain why this bug happened.
It is related to the "initial search scope" in the CC's source code of AI() function.
// Start an Artificial Intelligence (!) sequence to gather all the matching tokens..
// The actual AI is in FindAIMatches() below...
size_t NativeParser::AI(TokenIdxSet& result,
cbEditor* editor,
const wxString& lineText,
bool noPartialMatch,
bool caseSensitive,
TokenIdxSet* search_scope,
int caretPos)
{
......
......
if (result.size()<1) // found nothing in the search_scope, add global namespace
{
if (s_DebugSmartSense)
Manager::Get()->GetLogManager()->DebugLog(F(_T("AI() result is zero. Adding global namespace.")));
search_scope->insert(-1);
FindAIMatches(components, result, -1, noPartialMatch, caseSensitive, true, 0xffff, search_scope);
}
......
In the AI function, we firstly collect the "initial search scope", then do the recursive matching stage. I have already written some steps in the wiki, you can see here:
5 Automatic Code Completion, so, the "global namespace scope" is not added by default.( if I can remember, in a earlier revision, when we were collecting initial search scopes", global namespace is always added)
You can see the "if" condition.
For example, when we do the AI function in the code below:
struct TestStruct
{
int test_3;
int Test()
{
int test_1, test_2;
te
}
};
We firstly add the initial scope is "struct TestStruct", then do the AIMatch routing in this scope. Too bad that when the "local parser" parsing the local statement, both "test_1" and "test_2" will added to the "global scope namespace":
{
int test_1, test_2;
te
}
So, when we do a AIMatch in the "strct TestStruct", we find we get the two matches: "Test()" and the member variable "test_3". At this time, we have already get the matching result size >1, so, due to the if condition, global namespace is not searched any more.
Solution:We can have two solutions:
One: we can force to add the "global search scope" to the initial search, so that we can get the right matching result. the Pros is it is quite simple, the cons is that you will loose the performance and cause other issue.
For example:
int abcd;
int main()
{
int abcd;
ab
}
Here, both global variable and auto variable name will be prompted. In CB forum, some people just suggest the "auto variable" in the function body.
Two:We don't need to add the global namespace in the initial search scope.
When the "local parser" parse the function body, the "auto variable" added as the
children of the function body.
For example:
struct TestStruct
{
int test_3;
int Test()
{
int test_1, test_2;
te
}
};
This time, the initial search scope should be: "struct TestStruct" and the "Test()".
So, when we do an AIMatch under "TestStruct" scope, we get the "test_3" and "Test()" matches.
Also, when we do an AIMatch under "Test()", we get the "test_1" and "test_2" matches.
So, we get the expected prompted list.
I have tried to using this method, but I didn't get success, because, when a parserthread attached with a "local body" is initialed, the defualt m_Parent Token is always the "global namespace", so the "test_2" and "test_1" will always be added to the "global namespace".
If we can supply a way that we can "set" m_Parent pointer to "Test() Token", we can totally solved this problem.