forked from alpha0010/ClangLib
-
Notifications
You must be signed in to change notification settings - Fork 4
/
clangpluginapi.h
300 lines (274 loc) · 10.3 KB
/
clangpluginapi.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#ifndef __CLANGPLUGINAPI_H
#define __CLANGPLUGINAPI_H
#include <cbplugin.h>
typedef int8_t ClTranslUnitId;
typedef int ClTokenId;
/** @brief Category of a token to identify what a token represents
*/
enum ClTokenCategory
{
tcClassFolder,
tcClass, tcClassPrivate,
tcClassProtected, tcClassPublic,
tcCtorPrivate, tcCtorProtected,
tcCtorPublic,
tcDtorPrivate, tcDtorProtected,
tcDtorPublic,
tcFuncPrivate, tcFuncProtected,
tcFuncPublic,
tcVarPrivate, tcVarProtected,
tcVarPublic,
tcMacroDef,
tcEnum, tcEnumPrivate,
tcEnumProtected, tcEnumPublic,
tcEnumerator,
tcNamespace,
tcTypedef, tcTypedefPrivate,
tcTypedefProtected, tcTypedefPublic,
tcSymbolsFolder,
tcVarsFolder,
tcFuncsFolder,
tcEnumsFolder,
tcPreprocFolder,
tcOthersFolder,
tcTypedefFolder,
tcMacroUse, tcMacroPrivate,
tcMacroProtected, tcMacroPublic,
tcMacroFolder,
tcLangKeyword, // added
tcNone = -1
};
/** @brief Token structure. Contains a token for code-completion.
*/
struct ClToken
{
ClToken(const wxString& nm, int _id, int _weight, ClTokenCategory categ) :
id(_id), category(categ), weight(_weight), name(nm) {}
int id;
ClTokenCategory category;
int weight;
wxString name;
};
/** @brief TokenPosition structure. Contains line and column information. First line is '1'
*/
struct ClTokenPosition
{
ClTokenPosition(unsigned int ln, unsigned int col)
{
line = ln;
column = col;
}
bool operator==(const ClTokenPosition& other) const
{
return ((line == other.line)&&(column == other.column));
}
bool operator!=(const ClTokenPosition& other) const
{
return !(*this == other);
}
unsigned int line;
unsigned int column;
};
/** @brief Level of diagnostic
*/
enum ClDiagnosticLevel { dlPartial, dlFull };
enum ClDiagnosticSeverity { sWarning, sError, sNote };
struct ClDiagnostic
{
ClDiagnostic(const int ln, const int rgStart, const int rgEnd, const ClDiagnosticSeverity level, const wxString& fl, const wxString& msg) :
line(ln), range(rgStart, rgEnd), severity(level), file(fl), message(msg) {}
int line;
std::pair<int, int> range;
ClDiagnosticSeverity severity;
wxString file;
wxString message;
};
typedef enum _TokenType
{
ClTokenType_Unknown = 0,
ClTokenType_DeclGroup = 0,
ClTokenType_DefGroup = 1<<9,
ClTokenType_FuncDecl = 1 | ClTokenType_DeclGroup,
ClTokenType_VarDecl = 2 | ClTokenType_DeclGroup,
ClTokenType_ParmDecl = 3 | ClTokenType_DeclGroup,
ClTokenType_ScopeDecl = 4 | ClTokenType_DeclGroup,
ClTokenType_FuncDef = ClTokenType_FuncDecl | ClTokenType_DefGroup,
} ClTokenType;
/** @brief Event used in wxWidgets command event returned by the plugin.
*/
class ClangEvent : public wxCommandEvent
{
public:
ClangEvent( const wxEventType evtId, const ClTranslUnitId id, const wxString& filename ) :
wxCommandEvent(wxEVT_NULL, evtId),
m_TranslationUnitId(id),
m_Filename(filename),
m_Location(0,0) {}
ClangEvent( const wxEventType evtId, const ClTranslUnitId id, const wxString& filename,
const ClTokenPosition& pos, const std::vector< std::pair<int, int> >& occurrences ) :
wxCommandEvent(wxEVT_NULL, evtId),
m_TranslationUnitId(id),
m_Filename(filename),
m_Location(pos),
m_GetOccurrencesResults(occurrences) {}
ClangEvent( const wxEventType evtId, const ClTranslUnitId id, const wxString& filename,
const ClTokenPosition& pos, const std::vector<ClToken>& completions ) :
wxCommandEvent(wxEVT_NULL, evtId),
m_TranslationUnitId(id),
m_Filename(filename),
m_Location(pos),
m_GetCodeCompletionResults(completions) {}
ClangEvent( const wxEventType evtId, const ClTranslUnitId id, const wxString& filename,
const ClTokenPosition& loc, const std::vector<ClDiagnostic>& diag ) :
wxCommandEvent(wxEVT_NULL, evtId),
m_TranslationUnitId(id),
m_Filename(filename),
m_Location(loc),
m_DiagnosticResults(diag) {}
ClangEvent( const wxEventType evtId, const ClTranslUnitId id, const wxString& filename,
const ClTokenPosition& loc, const wxString& documentation ) :
wxCommandEvent(wxEVT_NULL, evtId),
m_TranslationUnitId(id),
m_Filename(filename),
m_Location(loc),
m_DocumentationResults(documentation) {}
/** @brief Copy constructor
*
* @param other The other ClangEvent
*
*/
ClangEvent( const ClangEvent& other) :
wxCommandEvent(other),
m_TranslationUnitId(other.m_TranslationUnitId),
m_Filename(other.m_Filename),
m_Location(other.m_Location),
m_GetOccurrencesResults(other.m_GetOccurrencesResults),
m_GetCodeCompletionResults(other.m_GetCodeCompletionResults),
m_DiagnosticResults(other.m_DiagnosticResults),
m_DocumentationResults(other.m_DocumentationResults) {}
virtual ~ClangEvent() {}
virtual wxEvent *Clone() const
{
return new ClangEvent(*this);
}
ClTranslUnitId GetTranslationUnitId() const
{
return m_TranslationUnitId;
}
const ClTokenPosition& GetLocation() const
{
return m_Location;
}
const std::vector< std::pair<int, int> >& GetOccurrencesResults()
{
return m_GetOccurrencesResults;
}
const std::vector<ClToken>& GetCodeCompletionResults()
{
return m_GetCodeCompletionResults;
}
const std::vector<ClDiagnostic>& GetDiagnosticResults()
{
return m_DiagnosticResults;
}
const wxString& GetDocumentationResults()
{
return m_DocumentationResults;
}
private:
const ClTranslUnitId m_TranslationUnitId;
const wxString m_Filename;
const ClTokenPosition m_Location;
const std::vector< std::pair<int, int> > m_GetOccurrencesResults;
const std::vector<ClToken> m_GetCodeCompletionResults;
const std::vector<ClDiagnostic> m_DiagnosticResults;
const wxString m_DocumentationResults;
};
extern const wxEventType clEVT_TRANSLATIONUNIT_CREATED;
extern const wxEventType clEVT_REPARSE_FINISHED;
extern const wxEventType clEVT_TOKENDATABASE_UPDATED;
extern const wxEventType clEVT_GETCODECOMPLETE_FINISHED;
extern const wxEventType clEVT_GETOCCURRENCES_FINISHED;
extern const wxEventType clEVT_GETDOCUMENTATION_FINISHED;
extern const wxEventType clEVT_DIAGNOSTICS_UPDATED;
/* interface */
class IClangPlugin
{
public:
virtual ~IClangPlugin() {};
virtual bool IsProviderFor(cbEditor* ed) = 0;
virtual ClTranslUnitId GetTranslationUnitId(const wxString& filename) = 0;
virtual const wxImageList& GetImageList(const ClTranslUnitId id) = 0;
virtual const wxStringVec& GetKeywords(const ClTranslUnitId id) = 0;
/* Events */
virtual void RegisterEventSink(wxEventType, IEventFunctorBase<ClangEvent>* functor) = 0;
virtual void RemoveAllEventSinksFor(void* owner) = 0;
/** Request reparsing of a Translation unit */
virtual void RequestReparse(const ClTranslUnitId id, const wxString& filename) = 0;
/** Retrieve unction scope */
virtual std::pair<wxString, wxString> GetFunctionScopeAt(const ClTranslUnitId id, const wxString& filename,
const ClTokenPosition& location) = 0;
virtual void GetFunctionScopeLocation(const ClTranslUnitId id, const wxString& filename,
const wxString& scope, const wxString& functioname, ClTokenPosition& out_Location) = 0;
virtual void GetFunctionScopes(const ClTranslUnitId, const wxString& filename,
std::vector<std::pair<wxString, wxString> >& out_scopes) = 0;
/** Occurrences highlighting
* Performs an asynchronous request for occurences highlight. Will send an event with */
virtual void GetOccurrencesOf(const ClTranslUnitId, const wxString& filename, const ClTokenPosition& loc) = 0;
/** Code completion */
virtual wxCondError GetCodeCompletionAt(const ClTranslUnitId id, const wxString& filename, const ClTokenPosition& loc,
bool includeCtors, unsigned long timeout, std::vector<ClToken>& out_tknResults) = 0;
virtual wxString GetCodeCompletionTokenDocumentation(const ClTranslUnitId id, const wxString& filename,
const ClTokenPosition& location, ClTokenId tokenId) = 0;
virtual wxString GetCodeCompletionInsertSuffix(const ClTranslUnitId translId, int tknId, const wxString& newLine,
std::vector< std::pair<int, int> >& offsets) = 0;
};
/** @brief Base class for ClangPlugin components.
*
*/
/* abstract */
class ClangPluginComponent : public wxEvtHandler
{
protected:
ClangPluginComponent() {}
public:
virtual void OnAttach( IClangPlugin *pClangPlugin )
{
m_pClangPlugin = pClangPlugin;
}
virtual void OnRelease(IClangPlugin* WXUNUSED(pClangPlugin))
{
m_pClangPlugin = NULL;
}
virtual bool IsAttached()
{
return m_pClangPlugin != NULL;
}
virtual bool BuildToolBar(wxToolBar* WXUNUSED(toolBar))
{
return false;
}
virtual void BuildMenu(wxMenuBar* WXUNUSED(menuBar)) {}
// Does this plugin handle code completion for the editor ed?
virtual cbCodeCompletionPlugin::CCProviderStatus GetProviderStatusFor(cbEditor* WXUNUSED(ed))
{
return cbCodeCompletionPlugin::ccpsInactive;
}
// Request code completion
virtual std::vector<cbCodeCompletionPlugin::CCToken> GetAutocompList(bool WXUNUSED(isAuto), cbEditor* WXUNUSED(ed),
int& WXUNUSED(tknStart), int& WXUNUSED(tknEnd))
{
return std::vector<cbCodeCompletionPlugin::CCToken>();
}
virtual bool DoAutocomplete(const cbCodeCompletionPlugin::CCToken& WXUNUSED(token), cbEditor* WXUNUSED(ed))
{
return false;
}
virtual wxString GetDocumentation(const cbCodeCompletionPlugin::CCToken& WXUNUSED(token))
{
return wxEmptyString;
}
protected:
IClangPlugin* m_pClangPlugin;
};
#endif // __CLANGPLUGINAPI_H