Code::Blocks  SVN r11506
codecompletion.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3  * http://www.gnu.org/licenses/gpl-3.0.html
4  */
5 
6 #ifndef CODECOMPLETION_H
7 #define CODECOMPLETION_H
8 
9 #include <settings.h> // SDK
10 #include <cbplugin.h>
11 #include <cbproject.h>
12 #include <sdk_events.h>
13 
14 #include "coderefactoring.h"
15 #include "nativeparser.h"
16 #include "systemheadersthread.h"
17 #include "doxygen_parser.h"
18 
19 #include <wx/arrstr.h>
20 #include <wx/listctrl.h>
21 #include <wx/string.h>
22 #include <wx/timer.h>
23 
24 #include <map>
25 #include <vector>
26 #include <set>
27 
28 class cbEditor;
29 class wxScintillaEvent;
30 class wxChoice;
32 
45 {
46 public:
51  {
53 
56  StartLine(ns.StartLine), EndLine(ns.EndLine), Scope(ns.Name) {}
57 
58  int StartLine;
59  int EndLine;
63  };
64 
66  typedef std::vector<FunctionScope> FunctionsScopeVec;
67 
69  typedef std::vector<int> ScopeMarksVec;
70 
71 
73  {
74  FunctionsScopeVec m_FunctionsScope; // all functions in the file
75  NameSpaceVec m_NameSpaces; // all namespaces in the file
76  bool parsed; // indicates whether this file is parsed or not
77  };
79  typedef std::map<wxString, FunctionsScopePerFile> FunctionsScopeMap;
80 
84  virtual ~CodeCompletion();
85 
86  // the function below were virtual functions from the base class
87  virtual void OnAttach();
88  virtual void OnRelease(bool appShutDown);
89  virtual int GetConfigurationGroup() const { return cgEditor; }
90 
96  virtual void BuildMenu(wxMenuBar* menuBar);
98  virtual void BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data = 0);
100  virtual bool BuildToolBar(wxToolBar* toolBar);
102  virtual int GetToolBarPriority() { return 10; }
103 
104  // override virtual functions in cbCodeCompletionPlugin class
106  virtual std::vector<CCToken> GetAutocompList(bool isAuto, cbEditor* ed, int& tknStart, int& tknEnd);
107  virtual std::vector<CCCallTip> GetCallTips(int pos, int style, cbEditor* ed, int& argsPos);
108  virtual wxString GetDocumentation(const CCToken& token);
109  virtual std::vector<CCToken> GetTokenAt(int pos, cbEditor* ed, bool& allowCallTip);
110  virtual wxString OnDocumentationLink(wxHtmlLinkEvent& event, bool& dismissPopup);
111  virtual void DoAutocomplete(const CCToken& token, cbEditor* ed);
112 
123  wxArrayString GetLocalIncludeDirs(cbProject* project, const wxArrayString& buildTargets);
124 
131  wxArrayString& GetSystemIncludeDirs(cbProject* project, bool force);
132 
141  void GetAbsolutePath(const wxString& basePath, const wxArrayString& targets, wxArrayString& dirs);
142 
144  void EditorEventHook(cbEditor* editor, wxScintillaEvent& event);
145 
147  void RereadOptions(); // called by the configuration panel
148 
149 private:
153  void UpdateToolBar();
154 
156  void OnUpdateUI(wxUpdateUIEvent& event);
157 
159  void OnViewClassBrowser(wxCommandEvent& event);
160 
162  void OnGotoFunction(wxCommandEvent& event);
163 
165  void OnGotoPrevFunction(wxCommandEvent& event);
166 
168  void OnGotoNextFunction(wxCommandEvent& event);
169 
171  void OnClassMethod(wxCommandEvent& event);
172 
175 
177  void OnGotoDeclaration(wxCommandEvent& event);
178 
180  void OnFindReferences(wxCommandEvent& event);
181 
183  void OnRenameSymbols(wxCommandEvent& event);
184 
186  void OnOpenIncludeFile(wxCommandEvent& event);
187 
192 
193  // event handlers for the standard events sent from sdk core
195  void OnAppDoneStartup(CodeBlocksEvent& event);
197  void OnWorkspaceChanged(CodeBlocksEvent& event);
199  void OnProjectActivated(CodeBlocksEvent& event);
200  void OnProjectClosed(CodeBlocksEvent& event);
201  void OnProjectSaved(CodeBlocksEvent& event);
202  void OnProjectFileAdded(CodeBlocksEvent& event);
206  void OnEditorSave(CodeBlocksEvent& event);
207  void OnEditorOpen(CodeBlocksEvent& event);
208  void OnEditorActivated(CodeBlocksEvent& event);
209  void OnEditorClosed(CodeBlocksEvent& event);
210 
214  void OnCCLogger(CodeBlocksThreadEvent& event);
219 
224  void OnParserStart(wxCommandEvent& event);
225 
229  void OnParserEnd(wxCommandEvent& event);
230 
234 
241  void DoCodeComplete(int caretPos, cbEditor* ed, std::vector<CCToken>& tokens, bool preprocessorOnly = false);
242 
249  void DoCodeCompletePreprocessor(int tknStart, int tknEnd, cbEditor* ed, std::vector<CCToken>& tokens);
250 
257  void DoCodeCompleteIncludes(cbEditor* ed, int& tknStart, int tknEnd, std::vector<CCToken>& tokens);
258 
260  int DoClassMethodDeclImpl();
261 
263  int DoAllMethodsImpl();
264 
273  void MatchCodeStyle(wxString& str, int eolStyle = wxSCI_EOL_LF, const wxString& indent = wxEmptyString, bool useTabs = false, int tabSize = 4);
274 
275  // CC's toolbar related functions
277  void FunctionPosition(int &scopeItem, int &functionItem) const;
278 
280  void GotoFunctionPrevNext(bool next = false);
281 
286  int NameSpacePosition() const;
287 
289  void OnScope(wxCommandEvent& event);
290 
292  void OnFunction(wxCommandEvent& event);
293 
298 
302  void FindFunctionAndUpdate(int currentLine);
303 
308  void UpdateFunctions(unsigned int scopeItem);
309 
311  void EnableToolbarTools(bool enable = true);
312 
317 
319  void UpdateEditorSyntax(cbEditor* ed = NULL);
320 
322  void OnToolbarTimer(wxTimerEvent& event);
323 
326 
328  void OnProjectSavedTimer(wxTimerEvent& event);
329 
331  void OnReparsingTimer(wxTimerEvent& event);
332 
335 
338 
344 
347 
350 
352 
355 
361 
362  /* FIXME (ollydbg#1#03/20/15): This timer is added by rev 6510, but I don't know what is the
363  * exact reason to delay the reparsing by a timer
364  * Note that we also save the project pointer in the m_TimerProjectSaved, so that we can
365  * see which project is saved in the timer event handler, it looks like a bug here, which means
366  * if two Project Saved event happens continuously, the first one will be overwritten because we
367  * save the project pointer member of m_TimerProjectSaved.
368  */
369 
372 
375 
382 
388 
389  // The variables below were related to CC's toolbar
396 
401  FunctionsScopeVec m_FunctionsScope;
402 
405 
410  ScopeMarksVec m_ScopeMarks;
411 
413  FunctionsScopeMap m_AllFunctionsScopes;
414 
419 
425 
428 
431 
434 
437 
442 
445 
446  //options on code completion (auto suggestion list) feature
447 
450 
453 
458 
463 
466 
471 
472  /* dir to files map, for example, there are two dirs c:/a and c:/b
473  * so the map looks like: (usually the relative file path is stored)
474  * c:/a ---> {c:/a/a1.h, c:/a/a2.h} ---> {a1.h, a2.h}
475  * c:/b ---> {c:/b/b1.h, c:/b/b2.h} ---> {b1.h, b2.h}
476  */
478 
482  std::list<SystemHeadersThread*> m_SystemHeadersThreads;
483 
486 
500  typedef std::map<cbProject*, wxArrayString> ReparsingMap;
501 
503  ReparsingMap m_ReparsingMap;
504 
507 
508  // requires access to: m_NativeParser.GetParser().GetTokenTree()
509  friend wxString DocumentationHelper::OnDocumentationLink(wxHtmlLinkEvent&, bool&);
510 
511  DECLARE_EVENT_TABLE()
512 };
513 
514 #endif // CODECOMPLETION_H
virtual cbConfigurationPanel * GetConfigurationPanel(wxWindow *parent)
CC&#39;s config dialog.
int m_CurrentLine
current caret line, this is actually the saved caret line
bool m_NeedsBatchColour
batch run UpdateEditorSyntax() after first parsing
void OnSystemHeadersThreadFinish(CodeBlocksThreadEvent &event)
void OnEditorActivated(CodeBlocksEvent &event)
int EndLine
function body (implementation) end line
bool m_InitDone
Indicates CC&#39;s initialization is done.
void OnSystemHeadersThreadMessage(CodeBlocksThreadEvent &event)
receive event from SystemHeadersThread
wxArrayString GetLocalIncludeDirs(cbProject *project, const wxArrayString &buildTargets)
Get the include paths setting (usually set by user for each C::B project).
bool m_CCDetectImplementation
add function arguments&#39; types and names when autocompleted outside function.
Base class for code-completion plugins.
Definition: cbplugin.h:732
void OnFunction(wxCommandEvent &event)
Toolbar select event.
wxCriticalSection m_SystemHeadersThreadCS
critical section to protect accessing m_SystemHeadersMap
void OnReparsingTimer(wxTimerEvent &event)
delayed for re-parsing
virtual void OnAttach()
Any descendent plugin should override this virtual method and perform any necessary initialization...
virtual cbConfigurationPanel * GetProjectConfigurationPanel(wxWindow *parent, cbProject *project)
CC&#39;s config dialog which show in the project options panel.
std::map< wxString, FunctionsScopePerFile > FunctionsScopeMap
filename -> FunctionsScopePerFile map, contains all the opened files scope info
CCProviderStatus
Level of functionality a CC plugin is able to provide.
Definition: cbplugin.h:738
wxMenu * m_ViewMenu
std::vector< FunctionScope > FunctionsScopeVec
vector containing all the function information of a single source file
void GetAbsolutePath(const wxString &basePath, const wxArrayString &targets, wxArrayString &dirs)
search target file names (mostly relative names) under basePath, then return the absolute dirs the re...
void OnOpenIncludeFile(wxCommandEvent &event)
open the include file under the caret position
virtual void DoAutocomplete(const CCToken &token, cbEditor *ed)
Callback for inserting the selected autocomplete entry into the editor.
wxArrayString & GetSystemIncludeDirs(cbProject *project, bool force)
get the whole search dirs except the ones locally belong to the c::b project, note this function is u...
int StartLine
function body (implementation) start line
wxString m_CCFillupChars
user defined characters that work like Tab (empty by Default).
bool m_ToolbarNeedRefresh
indicate whether the CC&#39;s toolbar need a refresh, this means the toolbar list will be reconstructed ...
virtual bool BuildToolBar(wxToolBar *toolBar)
build CC Toolbar
std::vector< int > ScopeMarksVec
helper class to support FunctionsScopeVec
void EditorEventHook(cbEditor *editor, wxScintillaEvent &event)
handle all the editor event
void DoCodeComplete(int caretPos, cbEditor *ed, std::vector< CCToken > &tokens, bool preprocessorOnly=false)
fill the tokens with correct code complete words
#define wxSCI_EOL_LF
Definition: wxscintilla.h:85
cbEditor * m_LastEditor
the last valid editor it is saved in editor activated event handler, and will be verified in editor a...
void OnEditorActivatedTimer(wxTimerEvent &event)
delayed running of editor activated event, only the last activated editor should be considered ...
CodeCompletion()
Constructor.
SystemHeadersMap m_SystemHeadersMap
wxMenu * m_SearchMenu
void OnProjectSavedTimer(wxTimerEvent &event)
delayed running after saving project, while many projects&#39; saving
wxTimer m_TimerRealtimeParsing
timer triggered by editor hook function to delay the real-time parse
wxTimer m_TimerToolbar
timer for toolbar we only show an updated item in CC&#39;s toolbar&#39;s item list when caret position is sta...
wxString m_LastFile
the file updating the toolbar info
int NameSpacePosition() const
find the namespace whose scope covers the current line the m_CurrentLine is used
FunctionsScopeMap m_AllFunctionsScopes
this is a "filename->info" map containing all the opening files choice info
void UpdateFunctions(unsigned int scopeItem)
the scope item has changed or becomes invalid, so the associated function wxChoice should be updated...
Identify a function body&#39;s position, the underline data structure of the second wxChoice of CC&#39;s tool...
void OnCurrentProjectReparse(wxCommandEvent &event)
event handler when user select context menu->reparse file/projects
bool m_CCEnablePlatformCheck
do not allow code completion to add include files of projects/targets to the parser that are not supp...
static const int cgEditor
Editor related.
Definition: cbplugin.h:69
wxString Name
function&#39;s long name (including arguments and return type)
virtual ~CodeCompletion()
Destructor.
virtual std::vector< CCCallTip > GetCallTips(int pos, int style, cbEditor *ed, int &argsPos)
Supply content for the calltip at the specified location.
void OnAppDoneStartup(CodeBlocksEvent &event)
SDK event when application has started up.
A generic Code::Blocks event.
Definition: sdk_events.h:20
void OnRenameSymbols(wxCommandEvent &event)
CC&#39;s re-factoring function, rename a symbol.
Code completion plugin has those features: show tool-tip when the mouse hover over the variables/func...
void OnProjectClosed(CodeBlocksEvent &event)
bool m_LexerKeywordsToInclude[9]
indicate whether the predefined keywords set should be added in the suggestion list ...
void OnEditorSave(CodeBlocksEvent &event)
SDK editor related events.
CodeRefactoring m_CodeRefactoring
code re-factoring tool
std::vector< NameSpace > NameSpaceVec
Definition: parserthread.h:34
wxTimer m_TimerReparsing
delay after receive a project save/modified event
Represents a Code::Blocks project.
Definition: cbproject.h:96
wxToolBar * m_ToolBar
the CC&#39;s toolbar
virtual CCProviderStatus GetProviderStatusFor(cbEditor *ed)
Does this plugin handle code completion for the editor ed?
wxTimer m_TimerProjectSaved
delay after project saved event
bool m_CCEnableHeaders
give code completion list for header files, it happens after the #include directive ...
virtual std::vector< CCToken > GetTokenAt(int pos, cbEditor *ed, bool &allowCallTip)
Supply the definition of the token at the specified location.
ModuleType
The type of module offering a context menu.
Definition: globals.h:38
void OnViewClassBrowser(wxCommandEvent &event)
event handler when user click Menu->View->Symbols browser
void DoCodeCompleteIncludes(cbEditor *ed, int &tknStart, int tknEnd, std::vector< CCToken > &tokens)
fill the tokens with correct include file names
void ParseFunctionsAndFillToolbar()
normally the editor has changed, then CC need to parse the document again, and (re)construct the inte...
bool m_ToolbarNeedReparse
force to re-collect the CC toolbar&#39;s item information this means we will parse the buffer to collect ...
int DoAllMethodsImpl()
ContextMenu->Insert-> All class methods.
int m_CurrentLength
remember the number of bytes in the current editor/document this is actually the saved editor or file...
wxMenu * m_EditMenu
menu pointers to the frame&#39;s main menu
wxString ShortName
function&#39;s base name (without scope prefix)
wxString Scope
class or namespace
virtual void OnRelease(bool appShutDown)
void OnGotoPrevFunction(wxCommandEvent &event)
navigate to the previous function body
void OnProjectSaved(CodeBlocksEvent &event)
Structure representing a generic token, passed between CC plugins and CCManager.
Definition: cbplugin.h:746
void OnGotoDeclaration(wxCommandEvent &event)
handle both goto declaration and implementation event
bool m_CCAutoAddParentheses
whether add parentheses after user selects a function name in the code-completion suggestion list ...
void OnProjectFileChanged(CodeBlocksEvent &event)
void OnUnimplementedClassMethods(wxCommandEvent &event)
handle CC&#39;s context menu->insert "All class methods without implementation..."
wxString wxEmptyString
virtual int GetConfigurationGroup() const
Return the configuration group for this plugin.
void OnFindReferences(wxCommandEvent &event)
CC&#39;s re-factoring function, find all the reference place.
void OnUpdateUI(wxUpdateUIEvent &event)
event handler for updating UI e.g.
FunctionScope(const NameSpace &ns)
a namespace token can be convert to a FunctionScope type
virtual int GetToolBarPriority()
toolbar priority value
void OnProjectFileAdded(CodeBlocksEvent &event)
Base class for plugin configuration panels.
void OnSelectedFileReparse(wxCommandEvent &event)
void GotoFunctionPrevNext(bool next=false)
navigate between function bodies
void OnWorkspaceChanged(CodeBlocksEvent &event)
SDK workspace related events.
void OnRealtimeParsingTimer(wxTimerEvent &event)
event fired from the edit event hook function to indicate parsing while editing
void EnableToolbarTools(bool enable=true)
enable the two wxChoices
NativeParser class is just like a manager class to control Parser objects.
Definition: nativeparser.h:55
int DoClassMethodDeclImpl()
ContextMenu->Insert-> declaration/implementation.
virtual void BuildMenu(wxMenuBar *menuBar)
build menus in the main frame
wxChoice * m_Function
function choice control of CC&#39;s toolbar, it is the second choice
void UpdateEditorSyntax(cbEditor *ed=NULL)
highlight member variables
void OnProjectActivated(CodeBlocksEvent &event)
SDK project related events.
FunctionsScopeVec m_FunctionsScope
current active file&#39;s function body info
A file editor.
Definition: cbeditor.h:43
wxTimer m_TimerEditorActivated
delay after receive editor activated event the reason we need a timer is that we want to get a stable...
void OnToolbarTimer(wxTimerEvent &event)
delayed for toolbar update
ScopeMarksVec m_ScopeMarks
current active file&#39;s line info, helper member to access function scopes
void OnEditorClosed(CodeBlocksEvent &event)
DocumentationHelper m_DocHelper
Provider of documentation for the popup window.
void OnProjectFileRemoved(CodeBlocksEvent &event)
wxChoice * m_Scope
namespace/scope choice control, it is the first choice control
std::list< SystemHeadersThread * > m_SystemHeadersThreads
thread to collect header file names, these header file names can be prompt for auto suggestion after ...
void OnCCDebugLogger(CodeBlocksThreadEvent &event)
CC&#39;s own debug logger, to handle log event sent from other worker threads or itself(the main GUI thre...
void OnGotoFunction(wxCommandEvent &event)
event handler when user click Menu->Search->Goto function
void FindFunctionAndUpdate(int currentLine)
the caret has changed, so the wxChoice need to be updated to indicates which scope and function in wh...
wxMenu * m_ProjectMenu
ReparsingMap m_ReparsingMap
all the files need to be parsed and their associated projects
void OnGotoNextFunction(wxCommandEvent &event)
navigate to the next function body
void OnCCLogger(CodeBlocksThreadEvent &event)
CC&#39;s own logger, to handle log events sent from other worker threads or itself(the main GUI thread)...
void OnSelectedProjectReparse(wxCommandEvent &event)
void OnParserStart(wxCommandEvent &event)
batch parsing start event this event usually be fired when an Parser object try to start parsing task...
void DoParseOpenedProjectAndActiveEditor()
if C::B starts up with some projects opened, this function will be called to parse the already opened...
void OnParserEnd(wxCommandEvent &event)
batch parsing end event this event usually be fired when the task pool becomes empty ...
virtual void BuildModuleMenu(const ModuleType type, wxMenu *menu, const FileTreeData *data=0)
build context popup menu
virtual wxString GetDocumentation(const CCToken &token)
Supply html formatted documentation for the passed token.
void OnScope(wxCommandEvent &event)
Toolbar select event.
NameSpaceVec m_NameSpaces
current active file&#39;s namespace/scope info
void RereadOptions()
read CC&#39;s options, mostly happens the user change some setting and press APPLY
void UpdateToolBar()
update CC&#39;s ToolBar, the user may disable the first wxChoice, so we need to recreate the wxChoice and...
virtual std::vector< CCToken > GetAutocompList(bool isAuto, cbEditor *ed, int &tknStart, int &tknEnd)
Supply content for the autocompletion list.
std::map< cbProject *, wxArrayString > ReparsingMap
map to record all re-parsing files
void MatchCodeStyle(wxString &str, int eolStyle=wxSCI_EOL_LF, const wxString &indent=wxEmptyString, bool useTabs=false, int tabSize=4)
modify the string content to follow the current editor&#39;s code style The code style includes the EOL...
void OnEditorOpen(CodeBlocksEvent &event)
void OnClassMethod(wxCommandEvent &event)
handle CC&#39;s context menu->insert "Class method declaration/implementation..."
bool m_NeedReparse
indicate the editor has modified by the user and a real-time parse should be start ...
void FunctionPosition(int &scopeItem, int &functionItem) const
helper method in finding the function position in the vector for the function containing the current ...
#define NULL
Definition: prefix.cpp:59
void DoCodeCompletePreprocessor(int tknStart, int tknEnd, cbEditor *ed, std::vector< CCToken > &tokens)
fill the tokens with correct preprocessor directives, such as #i will prompt "if", "include"
std::map< wxString, StringSet > SystemHeadersMap
dir to files map, for example, you have two dirs c:/a and c:/b so the map looks like: c:/a —> {c:/a/...
size_t m_CCMaxMatches
maximum allowed code-completion list entries
NativeParser m_NativeParser
this member will actually manage all the Parser instances