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

Pseudo semantic highlighting

(1/4) > >>

Alpha:
CC already has a fairly decent idea of the what is going on in the source, so I decided to make CC talk to Scintilla.  This implementation is fairly crude, but I would appreciate feedback from anyone who would like to see a little more color in their code.

--- Code: ---Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp (revision 8788)
+++ src/plugins/codecompletion/codecompletion.cpp (working copy)
@@ -3641,4 +3641,39 @@
     TRACE(_T("CodeCompletion::OnEditorActivatedTimer: Starting m_TimerToolbar."));
     m_TimerToolbar.Start(TOOLBAR_REFRESH_DELAY, wxTIMER_ONE_SHOT);
     TRACE(_T("OnEditorActivatedTimer() : Current activated file is %s"), curFile.wx_str());
+
+    cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinEditor(editor);
+    if (!ed || ed->GetControl()->GetLexer() != wxSCI_LEX_CPP)
+        return;
+    TokenIdxSet result;
+    m_NativeParser.GetParser().FindTokensInFile(curFile, result, tkAnyContainer | tkAnyFunction);
+    TokenTree* tree = m_NativeParser.GetParser().GetTokenTree();
+    wxArrayString varList;
+    for (TokenIdxSet::const_iterator it = result.begin(); it != result.end(); ++it)
+    {
+        Token* token = tree->at(*it);
+        if (!token)
+            continue;
+        if (token->m_TokenKind & tkAnyFunction)
+        {
+            if (token->m_ParentIndex == wxNOT_FOUND)
+                continue;
+            else
+                token = tree->at(token->m_ParentIndex);
+        }
+        if (token && token->HasChildren())
+        {
+            for (TokenIdxSet::const_iterator chIt = token->m_Children.begin();
+                 chIt != token->m_Children.end(); ++chIt)
+            {
+                 const Token* chToken = tree->at(*chIt);
+                 if (   chToken && chToken->m_TokenKind == tkVariable
+                     && varList.Index(chToken->m_Name) == wxNOT_FOUND )
+                {
+                    varList.Add(chToken->m_Name);
+                }
+            }
+        }
+    }
+    ed->GetControl()->SetKeyWords(3, GetStringFromArray(varList, wxT(" "), false));
 }

--- End code ---

daniloz:
@Alpha: your patch didn't apply on my working copy, I had to it "by hand". I'm not sure if I have some differences or you have, haven't got the time to check...

However, I like to new colors, thx!  ;D

ollydbg:

--- Quote from: Alpha on January 16, 2013, 03:25:21 am ---CC already has a fairly decent idea of the what is going on in the source, so I decided to make CC talk to Scintilla.  This implementation is fairly crude, but I would appreciate feedback from anyone who would like to see a little more color in their code.

--- End quote ---
I like such feature, thanks.

MortenMacFly:

--- Quote from: ollydbg on January 16, 2013, 11:03:31 am ---I like such feature, thanks.

--- End quote ---
Yeah, its nice. It also "highlights" where work needs to be done. For example, add a new member variable to the class in a header  file, then create an inline method to use this member variable (i.e. a getter-method). This variable will be the only one not highlighted like the others until CC scans this file again... :D

oBFusCATed:
How do I test this?
I've applied it and I see no change.

Navigation

[0] Message Index

[#] Next page

Go to full version