Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign

convert "." to "->"

<< < (2/6) > >>

blueshake:
update:can work with function now.

--- Code: ---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)
             {

--- End code ---

blueshake:

--- Quote ---would be nice if it is aware of stl iterators, and do the same trick
--- End quote ---

For now ,I just search "*" in token's m_Type ,it is not easy to do this for current parser. :D

ollydbg:

--- Quote from: killerbot on October 27, 2009, 11:30:06 pm ---* 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 ;-) )

--- End quote ---
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. :(

blueshake:

--- Quote from: ollydbg on October 28, 2009, 05:32:44 am ---
--- Quote from: killerbot on October 27, 2009, 11:30:06 pm ---* 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 ;-) )

--- End quote ---
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. :(

--- End quote ---
Not understood it fully too. :wink:

killerbot:
well in C++0x there will be several cases where you no longer will have to specify the type of a variable, the compiler will determine it for you.

Examples :
auto Count = 10;  // --> int

std::vector<std::string> Hello;

for(auto It = Hello.cbegin(); It != Hello.cend(); ++It)
{
  std::cout << *It; // -> std::vector<std::string>const_iterator
}

this last loop can also be written with the new foreach, and also there the compiler will deduce the type.

And so will code completion parsers have to deduce this according to the new language rules.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version