After having no code completion problems for ages, I'm experiencing some after installing the latest nightly. This is from my project CSVfix at http://code.google.com/p/csvfix/
int ExcludeCommand :: Execute( ALib::CommandLine & cmd ) {
ProcessFlags( cmd );
....
Here, code completion on the "cmd" parameter works just fine. But if I move down in the source about 30 lines to:
void ExcludeCommand :: ProcessFlags( const ALib::CommandLine & cmd ) {
string es = cmd.GetValue( FLAG_IF, "" );
....
code completion on the "cmd" parameter no longer works (though completion on things like "this" does). Note the parameters of both functions are of the same type, though the one that doesn't work is const, and the first (working) function calls the second (non-working) one. I am experiencing similar problems with other classes.
This is quite old code, which compiles perfectly well, and I think did code-complete before (though I can't be 100% sure of that).
Any ideas?
Edit: I have tried making the second function non-const WRT the "cmd" parameter (in both the header and the implementation file), and if I do that code completion in that function starts working. If I revert to the const parameter, it stops working. Also, should have said Win7, 64-bit.
Ok, I can confirm this, here is the test code:
namespace ALib
{
class CommandLine
{
int a;
int b;
};
};
void ExcludeCommand :: ProcessFlags( const ALib::CommandLine & cmd ) {
cmd;
}
void ExcludeCommand :: ProcessFlags1( ALib::CommandLine & cmd ) {
cmd;
}
When I hit the "." (dot) after "cmd", It only works in the second function body.
Enable the smart debug, I see:
MarkItemsByAI_1()
ParseUsingNamespace() Parse file scope for "using namespace"
BreakUpComponents() Breaking up 'ALib'
BreakUpComponents() Found component: 'ALib' (SearchText)
BreakUpComponents() Adding component: 'ALib'.
ParseUsingNamespace() Found ALib
ParseFunctionArguments() Parse function arguments
FindCurrentFunctionStart() Looking for tokens in 'E:\code\cb\test_code\mortenr2012-01-15\main.cpp'
FindCurrentFunctionStart() Found 4 results
FindCurrentFunctionStart() Current function: 'void ExcludeCommand::ProcessFlags(const ALib::CommandLine& cmd)' (at line 11)
FindCurrentFunctionStart() Namespace='ExcludeCommand::', proc='ProcessFlags' (returning 166)
BreakUpComponents() Breaking up 'ExcludeCommand'
BreakUpComponents() Found component: 'ExcludeCommand' (SearchText)
BreakUpComponents() Adding component: 'ExcludeCommand'.
FindAIMatches() ----- FindAIMatches - enter -----
FindAIMatches() Search for ExcludeCommand, isLast = 1
GenerateResultSet() search 'ExcludeCommand', parent='Global namespace (id:0, type:(null)), isPrefix=0'
FindAIMatches() Looping 1 results
FindAIMatches() Match: 'ExcludeCommand' (ID='497') : type=''
FindAIMatches() ----- FindAIMatches - leave -----
GenerateResultSet() search 'ProcessFlags', parent='ExcludeCommand (id:497, type:class), isPrefix=0'
ParseFunctionArguments() + Function match: ProcessFlags
ParseFunctionArguments() Parsing arguments: "const ALib::CommandLine& cmd;"
ParseLocalBlock() Parse local block
FindCurrentFunctionStart() Looking for tokens in 'E:\code\cb\test_code\mortenr2012-01-15\main.cpp'
FindCurrentFunctionStart() Found 4 results
FindCurrentFunctionStart() Current function: 'void ExcludeCommand::ProcessFlags(const ALib::CommandLine& cmd)' (at line 11)
FindCurrentFunctionStart() Namespace='ExcludeCommand::', proc='ProcessFlags' (returning 166)
ParseLocalBlock() Block:
cmd.;
ParseLocalBlock() Local tokens:
+ constCommandLine & ExcludeCommand::ProcessFlags::cmd Parent = ProcessFlags
AI() =========================================================
AI() Doing AI for 'cmd.':
FindCurrentFunctionStart() Looking for tokens in 'E:\code\cb\test_code\mortenr2012-01-15\main.cpp'
FindCurrentFunctionStart() Found 4 results
FindCurrentFunctionStart() Current function: 'void ExcludeCommand::ProcessFlags(const ALib::CommandLine& cmd)' (at line 11)
FindCurrentFunctionStart() Namespace='ExcludeCommand::', proc='ProcessFlags' (returning 166)
BreakUpComponents() Breaking up 'ExcludeCommand'
BreakUpComponents() Found component: 'ExcludeCommand' (SearchText)
BreakUpComponents() Adding component: 'ExcludeCommand'.
FindAIMatches() ----- FindAIMatches - enter -----
FindAIMatches() Search for ExcludeCommand, isLast = 1
GenerateResultSet() search 'ExcludeCommand', parent='Global namespace (id:0, type:(null)), isPrefix=0'
FindAIMatches() Looping 1 results
FindAIMatches() Match: 'ExcludeCommand' (ID='497') : type=''
FindAIMatches() ----- FindAIMatches - leave -----
GenerateResultSet() search 'ProcessFlags', parent='ExcludeCommand (id:497, type:class), isPrefix=0'
AI() Adding search namespace: ExcludeCommand
BreakUpComponents() Breaking up 'cmd.'
BreakUpComponents() Found component: 'cmd' (Class)
BreakUpComponents() Adding component: 'cmd'.
BreakUpComponents() Found component: '' (SearchText)
BreakUpComponents() Adding component: ''.
ResolveExpression() search scope is 4 result.
search scope: -1
search scope: 492
search scope: 494
search scope: 497
ResolveExpression() Looping 1 result.
ResolvExpression() Match:'cmd(ID=498) : type='ALib::constCommandLine'
BreakUpComponents() Breaking up 'ALib::constCommandLine'
BreakUpComponents() Found component: 'ALib' (Namespace)
BreakUpComponents() Adding component: 'ALib'.
BreakUpComponents() Found component: 'constCommandLine' (SearchText)
BreakUpComponents() Adding component: 'constCommandLine'.
ResolveExpression() search scope is 0 result.
ResolveExpression() Looping 0 result.
AI() AI leave, returned 0 results
0 results
See, there is a wrong string "constCommandLine".
This bug also happens in the tip window when the mouse hover the "cmd".
Ok, after debug for some time, I found that this problem happened at:
else if (peek==ParserConsts::dcolon)
{
if ( m_Str.IsEmpty()
|| m_Str.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_const)
|| m_Str.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_volatile) ) // what else?!
m_EncounteredTypeNamespaces.push(token); // it's a type's namespace
else
m_EncounteredNamespaces.push(token);
m_Tokenizer.GetToken(); // eat ::
}
When parsing the argument string:
const ALib::CommandLine & cmd
The "stack" variable "m_Str" is originally "const ", and after that, it becomes "const", the last space is removed.
And later, the CommandLine is added, and "m_Str" becomes "constCommandLine".
This is the patch to fix this issue:
Index: E:/code/cb/cb_trunk/src/plugins/codecompletion/parser/parserthread.cpp
===================================================================
--- E:/code/cb/cb_trunk/src/plugins/codecompletion/parser/parserthread.cpp (revision 7991)
+++ E:/code/cb/cb_trunk/src/plugins/codecompletion/parser/parserthread.cpp (working copy)
@@ -1058,7 +1058,12 @@
if ( m_Str.IsEmpty()
|| m_Str.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_const)
|| m_Str.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_volatile) ) // what else?!
+ {
+ if (!m_Str.IsEmpty())
+ m_Str << _T(" ");
m_EncounteredTypeNamespaces.push(token); // it's a type's namespace
+ }
+
else
m_EncounteredNamespaces.push(token);
m_Tokenizer.GetToken(); // eat ::
But I'm not satisfied with the logic on changing m_Str. Any ideas?
But I'm not satisfied with the logic on changing m_Str. Any ideas?
I think the issue is that the space is removed.
Yes, the m_Str is like a "stack", when you push(add) something to it, you need a trailing space.
Where and why does that happen?
m_Str.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_const)
This code removed the trailing space, so my patch adds the space again.
Yes, the m_Str is like a "stack", when you push(add) something to it, you need a tailing space.
[...]
m_Str.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_const)
This code removed the tailing space, so my patch adds the space again.
So, doing something like:
wxString str_stripped(m_Str); if (str_stripped.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_const)) ...
...wouldn't that be better?
...or even:
wxString str_stripped(m_Str); str_stripped.Trim(true).Trim(false); if (str_stripped.IsSameAs(ParserConsts::kw_const)) ...
Edit: Edited the second code snippet so it is syntax-correct.
Ok, I'm going to commit the patch below (in a few hours):
Index: E:/code/cb/cb_trunk/src/plugins/codecompletion/parser/parserthread.cpp
===================================================================
--- E:/code/cb/cb_trunk/src/plugins/codecompletion/parser/parserthread.cpp (revision 7991)
+++ E:/code/cb/cb_trunk/src/plugins/codecompletion/parser/parserthread.cpp (working copy)
@@ -1055,9 +1055,11 @@
}
else if (peek==ParserConsts::dcolon)
{
- if ( m_Str.IsEmpty()
- || m_Str.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_const)
- || m_Str.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_volatile) ) // what else?!
+ wxString str_stripped(m_Str);
+ str_stripped.Trim(true).Trim(false);
+ if ( str_stripped.IsEmpty()
+ || str_stripped.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_const)
+ || str_stripped.Trim(true).Trim(false).IsSameAs(ParserConsts::kw_volatile) ) // what else?!
m_EncounteredTypeNamespaces.push(token); // it's a type's namespace
else
m_EncounteredNamespaces.push(token);