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

make cc real-time parse

<< < (3/4) > >>

blueshake:

--- Quote from: ollydbg on December 14, 2009, 02:25:40 pm ---But this bug CC fail after A class's static method called. still exist. :(

--- End quote ---

I think it is something wrong with parsethread.

blueshake:
Another patch for improvement.

Patch:




Note:

All of these improvments are based on the real-time parse.

blueshake:
Some modifations.


1.remove the type conditions which were done by the search.
2.adjust the update logic.

patch:



--- Code: ---Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp (revision 5986)
+++ src/plugins/codecompletion/codecompletion.cpp (working copy)
@@ -1410,16 +1410,23 @@
         funcdata->m_NameSpaces.clear();
         funcdata->parsed = true;
 
-        Parser parser(this);
+        /*Parser parser(this);
         TokensTree* tmptree = parser.GetTempTokens();
         tmptree->clear();
         parser.ParseBufferForFunctions(ed->GetControl()->GetText());
 
         for(size_t i = 0; i < tmptree->size(); ++i)
+        */
+        Parser* parser = m_NativeParser.FindParserFromEditor(ed);
+        if (!parser)
+            return;
+        TokenIdxSet result;
+        TokensTree* tmptree = parser->GetTokens();
+        parser->FindTokensInFile(filename, result, tkFunction|tkConstructor|tkDestructor);
+        for (TokenIdxSet::iterator it =result.begin(); it != result.end(); ++it)
         {
-            const Token* token = tmptree->at(i);
-            if (token && (token->m_TokenKind == tkFunction || token->m_TokenKind == tkConstructor || token->m_TokenKind == tkDestructor)
-                && token->m_ImplLine != 0)
+            const Token* token = tmptree->at(*it);
+            if (token && token->m_ImplLine != 0)//&& (token->m_TokenKind == tkFunction || token->m_TokenKind == tkConstructor || token->m_TokenKind == tkDestructor)
             {
                 FunctionScope func;
                 func.StartLine = token->m_ImplLine - 1;
@@ -2077,28 +2084,6 @@
     }
     if( control->GetCurrentLine() != m_CurrentLine)
     {
-        m_CurrentLine = control->GetCurrentLine();
-        int sel = FunctionPosition();
-        if(sel != -1 && sel != m_Function->GetSelection())
-        {
-            m_Function->SetSelection(sel);
-            m_Scope->SetSelection(sel);
-        }
-        else if(sel == -1)
-        {
-            m_Function->SetSelection(wxNOT_FOUND);
-            // TO DO : set scope correctly
-            int NsSel = NameSpacePosition();
-            if(NsSel != -1)
-            {
-                m_Scope->SetSelection(NsSel + m_StartIdxNameSpaceInScope);
-            }
-            else
-            {
-                m_Scope->SetSelection(wxNOT_FOUND);
-            }
-        }
-
         if (m_NeedReparse)
         {
             Parser* parser = m_NativeParser.FindParserFromActiveEditor();
@@ -2107,7 +2092,32 @@
                 parser->Reparse(editor->GetFilename());
             }
             m_NeedReparse= false;
+            //m_CurrentLine = control->GetCurrentLine();
         }
+        else
+        {
+            m_CurrentLine = control->GetCurrentLine();
+            int sel = FunctionPosition();
+            if(sel != -1 && sel != m_Function->GetSelection())
+            {
+                m_Function->SetSelection(sel);
+                m_Scope->SetSelection(sel);
+            }
+            else if(sel == -1)
+            {
+                m_Function->SetSelection(wxNOT_FOUND);
+                // TO DO : set scope correctly
+                int NsSel = NameSpacePosition();
+                if(NsSel != -1)
+                {
+                    m_Scope->SetSelection(NsSel + m_StartIdxNameSpaceInScope);
+                }
+                else
+                {
+                    m_Scope->SetSelection(wxNOT_FOUND);
+                }
+            }
+        }
     }
 
     // allow others to handle this event
@@ -2133,4 +2143,5 @@
 void CodeCompletion::OnParserEnd(wxCommandEvent& event)
 {
     // nothing for now
+    ParseFunctionsAndFillToolbar(true);
 }

--- End code ---

ollydbg:
I will test this patch, Thanks for the contribution!!! :D

MortenMacFly:

--- Quote from: blueshake on December 14, 2009, 01:40:41 am ---optimize the cc search process based on real-time parse.
[...]

--- Code: ---Index: src/include/filemanager.h
===================================================================
--- src/plugins/codecompletion/nativeparser.cpp (revision 5973)
+++ src/plugins/codecompletion/nativeparser.cpp (working copy)
@@ -2152,18 +2152,13 @@
     }
     s_LastEditor = editor;
     s_LastLine = line;
-
-    Parser parser(this);
-    parser.ParseBufferForFunctions(control->GetTextRange(0, pos));
-
-    wxArrayString funcs;
-    TokensTree* tmptree = parser.GetTempTokens();
-
-    // look for implementation functions that enclose our current line number
-    for(size_t i = 0; i < tmptree->size();i++)
+    TokenIdxSet result;
+    m_Parser.FindTokensInFile(editor->GetFilename(), result, tkFunction|tkConstructor|tkDestructor);
+    TokensTree* tree = m_Parser.GetTokens();
+    for (TokenIdxSet::iterator it = result.begin(); it != result.end(); ++it)
     {
-        Token* token = tmptree->at(i);
-        if (token && (token->m_TokenKind == tkFunction || token->m_TokenKind == tkConstructor || token->m_TokenKind == tkDestructor))
+        Token* token = tree->at(*it);
+        if (token)
         {
             // found a function; check its bounds
             if (token->m_ImplLineStart <= (size_t)line && token->m_ImplLineEnd >= (size_t)line)
@@ -2174,6 +2169,7 @@
                                                                 token->DisplayName().wx_str(),
                                                                 token->m_ImplLine));
 
+
                 s_LastNS = token->GetNamespace();
                 s_LastPROC = token->m_Name;
                 s_LastResult = control->PositionFromLine(token->m_ImplLine - 1);

--- End code ---

--- End quote ---
This is certainly the cause for the wrong file being returned which I've reported here:
http://forums.codeblocks.org/index.php/topic,11800.msg80076.html#msg80076
Look: Previously the parser was created based on the native parsers current state. Now you just use the attached parser which maybe wrong because it may point to the wrong file!
I believe something like FindParserFromEditor needs to be used here...

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version