This patch can convert "." to "->" when the token is pointer.NOT smart but work. :)What would happen if I *really* would like to enter a dot? E.g. the parser has parsed incorrectly? Would it always be replaced with the pointer operator then? If yes, then this should surely be configurable.
any idea/comment is welcome.
What would happen if I *really* would like to enter a dot? E.g. the parser has parsed incorrectly? Would it always be replaced with the pointer operator then? If yes, then this should surely be configurable.The following patch can do this.for the second time ,it would not work.(just delete the "->" ,press "." again.)
struct qq
{
int x;
int y;
};
qq* abc(int aa)
{
}
int main()
{
qq* pp;
pp->
cout << "Hello world!" << endl;
return 0;
}
Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp (revision 5891)
+++ src/plugins/codecompletion/codecompletion.cpp (working copy)
@@ -2040,7 +2040,67 @@
return;
}
}
+ static bool repeat = true;
+ if (ch == '.' && repeat)
+ {
+ repeat = false;
+ Parser* parser = m_NativeParser.FindParserFromActiveEditor();
+ if (parser)
+ {
+ TokenIdxSet result;
+ int pos = control->GetCurrentPos();
+ wxString line = control->GetLine(control->LineFromPosition(pos));
+ //skip the "."
+ int startAt = control->GetColumn(pos) -2;
+ int nest = 0;
+ if (line.GetChar(startAt) == ')')
+ {
+ ++nest;
+ while ((--startAt >= 0)
+ && (nest != 0) )
+ {
+ #if wxCHECK_VERSION(2, 9, 0)
+ switch (line.GetChar(startAt).GetValue())
+ #else
+ switch (line.GetChar(startAt))
+ #endif
+ {
+ case ']':
+ case ')': ++nest; --startAt; break;
+
+ case '[':
+ case '(': --nest; --startAt; break;
+
+ }
+ }
+ if (( (startAt >= 0)
+ && ((line.GetChar(startAt) == ')')
+ || (line.GetChar(startAt) == ']') ) ))
+ ++nest;
+ ++startAt;
+
+ }
+ int endOfWord = control->WordEndPosition(pos -line.Len() + startAt, true);
+ if (m_NativeParser.MarkItemsByAI(result, true, true, true, endOfWord))
+ {
+ if (result.size() == 1)
+ {
+ Token* sel = parser->GetTokens()->at(*(result.begin()));
+ Manager::Get()->GetLogManager()->DebugLog(sel->m_Type);
+ if (sel->m_Type.find('*') != wxString::npos)
+ {
+ control->SetTargetStart(pos-1);
+ control->SetTargetEnd(pos);
+ control->ReplaceTarget(_T("->"));
+ control->GotoPos(pos +1);
+ }
+ }
+ }
+ }
+ }
+ else
+ repeat = true;
int timerDelay = cfg->ReadInt(_T("/cc_delay"), 500);
if (autoCC || timerDelay == 0)
{
would be nice if it is aware of stl iterators, and do the same trick
* in future this is going to be hell for our parsers,thanks to the auto variable (C++0x will rock, but for parsers/IDE's lofe won't get any easier ;-) )Hi, can you explain this sentence? I can't fully understand you. Thanks.
Not understood it fully too. :wink:* in future this is going to be hell for our parsers,thanks to the auto variable (C++0x will rock, but for parsers/IDE's lofe won't get any easier ;-) )Hi, can you explain this sentence? I can't fully understand you. Thanks.
BTW:My lab's networking was broken, so, I can't test this patch these days till the networking was fixed. :(
I'd very much like if no more extra smartness was added to code completion, it is already bad enough as it is now. It already hampers daily work enough the way it is now. Code completion should be the opposite, it should help.
And yes to C++0x, but it's present, not future :)
that means Thomas you have the code completion plug-in enabled ?Yes, I have it enabled for the odd hope that it might manage with a 1% chance to do a "find definition" correctly when I use a function like snprintf and want to be sure that I'm giving it the correct parameters. Never does, of course. Winning the lottery is more likely to succeed. So I find myself searching through system headers in Windows Explorer instead, every single time.
I don't understand why it already hampers daily work enough the way it is now.Because it's fucking dumb and pops up menus that only ever contain shit. And worse, you have to hit ESC to make them go away. If you type fast, it will happen once or twice per week that you type something like
or inserting some bullshit names (which will not go unnoticed).Turn it off.
Similar thing happens occasionally when changing a variable name in some function. After changing the name and hitting the "up" key 3-4 times (to get to the next line containing the name), you find yourself only scrolling through some flipping popup menu instead of moving the cursor. By the time you've stopped shouting and hitting your monitor with the keyboard, you have forgotten what you actually wanted to change.Perhaps Thomas is a little harsh, but I definitely agree with the above complaint, which is very irritating. I would much prefer to have the Up/Down keys move the cursor up or down in the file - not in the popup menu. Perhaps a different key sequence could be used for scrolling the popup menu. (By the way, I know I can turn CC off, but I often find it useful.)
Yes, sometimes, the codecompletion list windows was annoying, when I have finished enter the variable name, but they still exist there, I need to press "ESC" key to the suggestion list window closed. If not, arrow up and arrow down can only scroll the list, not the caret in the editor. :(Similar thing happens occasionally when changing a variable name in some function. After changing the name and hitting the "up" key 3-4 times (to get to the next line containing the name), you find yourself only scrolling through some flipping popup menu instead of moving the cursor. By the time you've stopped shouting and hitting your monitor with the keyboard, you have forgotten what you actually wanted to change.Perhaps Thomas is a little harsh, but I definitely agree with the above complaint, which is very irritating. I would much prefer to have the Up/Down keys move the cursor up or down in the file - not in the popup menu. Perhaps a different key sequence could be used for scrolling the popup menu. (By the way, I know I can turn CC off, but I often find it useful.)
100% make it configurable, so I can disable it :lol:If we support smart pointer fully, we need this feature.
struct some_class { int get(); }
smart_ptr<some_class> p(new some_class);
p-> <--- I want to get the list with some_class's members
p. <--- I want to get the list with smart_ptr's members
Loaden, why, can you show an example?CodeAnd p.get() is pretty valid and I don't want to be rewritten to p->get()!struct some_class { int get(); }
smart_ptr<some_class> p(new some_class);
p-> <--- I want to get the list with some_class's members
p. <--- I want to get the list with smart_ptr's members
Please don't make me fight my IDE and make this option configurable :)
If we support smart pointer fully, we need this feature.Why we need this feature? One reason please?
Why we need this feature? One reason please?I agree with oBFusCATed in this point. Especially trying to detect "smartly" if the user really means a pointer or not is really error prone. It's the job of the compiler to detect such kind of errors, not CC's.
Why we need this feature? One reason please?The only reason I can imagine, honestly, is if you can't tell the difference between pointers and objects in your code. But then you have a totally different problem.
In fact, this feature is very convenient, enter "." very easy, enter "->" have to some difficulties.If we support smart pointer fully, we need this feature.Why we need this feature? One reason please?