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));
}
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.I like such feature, thanks.
I like such feature, thanks.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
OK, but it doesn't work for C code...... hence the "pseudo" ;).
Probably you have to look in this topic: http://forums.codeblocks.org/index.php/topic,16249.0.htmlYes... the plugin there is a lot more ambitious than what I am attempting.
Is it possible to extract this code in a separate plugin or in core?Probably not; this makes use of the token tree that CC builds to decide on the set of keywords to highlight.
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... :DAlthough the code is not necessarily expensive, I would prefer it run the fewest number of times necessary. Do you have a recommended selection of events I should attach it to?
This patch currently only hooks into the editor activated event, so you need to switch editors/close reopen editors (after initial parsing has finished) for colors to show up.There is also the drawback, btw: I noticed really massive slow-downs when opening an editor of a large file with many references to highlight. Do you experience the same?
however, I do not exactly understand the concept of a mutex very well; is it needed here?A mutex is used where the tree could be accessed in parallel (i.e. from another thread), to avoid freezes. Usually accessing the token tree always requires a lock, unless it has been set from the caller function already. I'll have a look but later...
There is also the drawback, btw: I noticed really massive slow-downs when opening an editor of a large file with many references to highlight. Do you experience the same?I have not tried opening anything extremely large yet... is the slow-down constant, or is it a pause when you switch to the tab? (I could probably increase performance by switching to a hash instead of an array to insure unique entries.)
This patch currently only hooks into the editor activated event, so you need to switch editors/close reopen editors (after initial parsing has finished) for colors to show up.I forgot to mention, this second patch adds one other event: color all open editors when parsing completes.
I have not tried opening anything extremely large yet... is the slow-down constant, or is it a pause when you switch to the tab?It seems as soon as I switch... I'll report back once I have played the second one.
if (token->m_Ancestors.empty())
tree->RecalcInheritanceChain(token);
class MyFrame: public wxFrame
Basically, only type tkVariable is added. These are filtered, so that the highlighted tokens are member variables that are relevant (classes that are declared/implemented, their ancestors) to the current editor (and global variables in *.c).
- List functions in the current file
- Collect the classes they are from
- List the classes in the current file
- Iterate through the member variables of both lists of classes
- Put this list of variables in Scintilla's (previously unused by Code::Blocks) keyword set for "Global classes and typedefs"