forked from alpha0010/ClangLib
-
Notifications
You must be signed in to change notification settings - Fork 4
/
clangplugin.h
231 lines (194 loc) · 8.67 KB
/
clangplugin.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#ifndef CLANGPLUGIN_H
#define CLANGPLUGIN_H
#include <cbplugin.h>
#include <wx/imaglist.h>
#include <wx/timer.h>
#include "clangpluginapi.h"
#include "clangproxy.h"
#include "tokendatabase.h"
#include "clangtoolbar.h"
#include "clangcc.h"
#include "clangdiagnostics.h"
// milliseconds
#define CLANG_REPARSE_DELAY 10000
/* final */
class ClangPlugin : public cbCodeCompletionPlugin, public IClangPlugin
{
friend class ClangSettingsDlg;
public:
ClangPlugin();
virtual ~ClangPlugin();
bool ProcessEvent(wxEvent& event);
/*-- Public interface --*/
virtual int GetConfigurationGroup() const
{
return cgEditor;
}
virtual cbConfigurationPanel* GetConfigurationPanel(wxWindow* parent);
// Does this plugin handle code completion for the editor ed?
virtual CCProviderStatus GetProviderStatusFor(cbEditor* ed);
// Supply content for the autocompletion list.
virtual std::vector<CCToken> GetAutocompList(bool isAuto, cbEditor* ed, int& tknStart, int& tknEnd);
// Supply html formatted documentation for the passed token.
virtual wxString GetDocumentation(const CCToken& token);
// Supply content for the calltip at the specified location.
virtual std::vector<CCCallTip> GetCallTips(int pos, int style, cbEditor* ed, int& argsPos);
// Supply the definition of the token at the specified location.
virtual std::vector<CCToken> GetTokenAt(int pos, cbEditor* ed, bool& allowCallTip);
// Handle documentation link event.
virtual wxString OnDocumentationLink(wxHtmlLinkEvent& event, bool& dismissPopup);
// Callback for inserting the selected autocomplete entry into the editor.
virtual void DoAutocomplete(const CCToken& token, cbEditor* ed);
// Build menu bar
virtual void BuildMenu(wxMenuBar* menuBar);
// Build popup menu
virtual void BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data = nullptr);
/** build CC Toolbar */
virtual bool BuildToolBar(wxToolBar* toolBar);
public:
void UpdateComponents();
protected:
virtual void OnAttach();
virtual void OnRelease(bool appShutDown);
private:
/**
* Compute the locations of STL headers for the given compiler (cached)
*
* @param compId The id of the compiler
* @return Include search flags pointing to said locations
*/
wxString GetCompilerInclDirs(const wxString& compId);
#if 0
/**
* Search for the source file associated with a given header
*
* @param ed The editor representing the header file
* @return Full path to presumed source file
*/
wxString GetSourceOf(cbEditor* ed);
/**
* Find the most likely source file from a list, corresponding to a given header
*
* @param candidateFilesArray List of possibilities to check
* @param activeFile Header file to compare to
* @param[out] isCandidate Set to true if returned file may not be best match
* @return File determined to be source (or invalid)
*/
wxFileName FindSourceIn(const wxArrayString& candidateFilesArray, const wxFileName& activeFile, bool& isCandidate);
/**
* Test if a candidate source file matches a header file
*
* @param candidateFile The potential source file
* @param activeFile The header file
* @param[out] isCandidate Set to true if match is not exact
* @return true if files match close enough
*/
bool IsSourceOf(const wxFileName& candidateFile, const wxFileName& activeFile, bool& isCandidate);
#endif
void OnCCLogger(CodeBlocksThreadEvent& event);
void OnCCDebugLogger(CodeBlocksThreadEvent& event);
/// Start up parsing timers
void OnEditorOpen(CodeBlocksEvent& event);
/// Start up parsing timers
void OnEditorActivate(CodeBlocksEvent& event);
void OnEditorSave(CodeBlocksEvent& event);
void OnEditorClose(CodeBlocksEvent& event);
/// Make project-dependent setup
void OnProjectActivate(CodeBlocksEvent& event);
void OnProjectFileChanged(CodeBlocksEvent& event);
/// Update project-dependent setup
void OnProjectOptionsChanged(CodeBlocksEvent& event);
/// Close project
void OnProjectClose(CodeBlocksEvent& event);
/// Generic handler for various timers
void OnTimer(wxTimerEvent& event);
/// Start re-parse
void OnEditorHook(cbEditor* ed, wxScintillaEvent& event);
/// Resolve the token under the cursor and open the relevant location
void OnGotoDeclaration(wxCommandEvent& event);
/// Find the token implementation under the cursor and open the relevant location
void OnGotoImplementation(wxCommandEvent& event);
// Async
//void OnReparse( wxCommandEvent& evt );
// Async
void OnCreateTranslationUnit(wxCommandEvent& evt);
/**
* Update editor diagnostic mark up
*
* @param ed The editor to diagnose
* @param diagLv Update only the highlights, or highlights and text annotations
*/
//void DiagnoseEd(cbEditor* ed, DiagnosticLevel diagLv);
//void OnDiagnoseEd( wxCommandEvent& event );
/// Set the clang translation unit (callback)
void OnClangCreateTUFinished(wxEvent& event);
/// Update after clang has reparsing done (callback)
void OnClangReparseFinished(wxEvent& event);
/// Update after updating the token database has finished
void OnClangUpdateTokenDatabaseFinished(wxEvent& event);
/// Update after clang has built diagnostics
void OnClangGetDiagnosticsFinished(wxEvent& event);
/// Update after clang has finished a synchronous task
void OnClangSyncTaskFinished(wxEvent& event);
/// Update after clang has finished building the occurrences list
void OnClangGetOccurrencesFinished(wxEvent& event);
private: // Internal utility functions
// Builds compile command
int UpdateCompileCommand(cbEditor* ed);
void RequestReparse(int delayMilliseconds = CLANG_REPARSE_DELAY);
bool ActivateComponent(ClangPluginComponent* pComponent);
bool DeactivateComponent(ClangPluginComponent* pComponent);
bool ProcessEvent(ClangEvent& event);
bool HasEventSink(const wxEventType eventType);
public: // IClangPlugin
bool IsProviderFor(cbEditor* ed);
ClTranslUnitId GetTranslationUnitId(const wxString& filename);
void RegisterEventSink(wxEventType, IEventFunctorBase<ClangEvent>* functor);
void RemoveAllEventSinksFor(void* owner);
void RequestReparse(const ClTranslUnitId id, const wxString& filename);
std::pair<wxString, wxString> GetFunctionScopeAt(const ClTranslUnitId id, const wxString& filename,
const ClTokenPosition& location);
void GetFunctionScopeLocation(const ClTranslUnitId id, const wxString& filename,
const wxString& scope, const wxString& functioname, ClTokenPosition& out_Location);
void GetFunctionScopes(const ClTranslUnitId, const wxString& filename,
std::vector<std::pair<wxString, wxString> >& out_scopes);
void GetOccurrencesOf(const ClTranslUnitId, const wxString& filename, const ClTokenPosition& loc);
wxCondError GetCodeCompletionAt(const ClTranslUnitId id, const wxString& filename, const ClTokenPosition& loc,
bool includeCtors, unsigned long timeout, std::vector<ClToken>& out_tknResults);
wxString GetCodeCompletionTokenDocumentation(const ClTranslUnitId id, const wxString& filename,
const ClTokenPosition& loc, ClTokenId tokenId);
wxString GetCodeCompletionInsertSuffix(const ClTranslUnitId translId, int tknId, const wxString& newLine,
std::vector< std::pair<int, int> >& offsets);
const wxImageList& GetImageList(const ClTranslUnitId WXUNUSED(id))
{
return m_ImageList;
}
const wxStringVec& GetKeywords(const ClTranslUnitId WXUNUSED(id))
{
return m_CppKeywords;
}
private: // Members
std::vector<ClangPluginComponent*> m_ActiveComponentList;
typedef std::vector<IEventFunctorBase<ClangEvent>*> EventSinksArray;
typedef std::map<wxEventType, EventSinksArray> EventSinksMap;
EventSinksMap m_EventSinks;
ClFilenameDatabase m_FileDatabase;
ClTokenDatabase m_Database;
wxStringVec m_CppKeywords;
ClangProxy m_Proxy;
wxImageList m_ImageList;
wxTimer m_ReparseTimer;
std::map<wxString, wxString> m_compInclDirs;
cbEditor* m_pLastEditor;
int m_TranslUnitId;
int m_EditorHookId;
int m_LastCallTipPos;
std::vector<wxStringVec> m_LastCallTips;
wxString m_CompileCommand;
int m_UpdateCompileCommand;
int m_ReparseNeeded;
ClangCodeCompletion m_CodeCompletion;
ClangDiagnostics m_Diagnostics;
ClangToolbar m_Toolbar;
};
#endif // CLANGPLUGIN_H