forked from MaskRay/ccls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lsp.hh
273 lines (234 loc) · 6.2 KB
/
lsp.hh
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
// Copyright 2017-2018 ccls Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "config.hh"
#include "serializer.hh"
#include "utils.hh"
#include <rapidjson/fwd.h>
#include <chrono>
#include <iosfwd>
#include <string>
namespace ccls {
struct RequestId {
// The client can send the request id as an int or a string. We should output
// the same format we received.
enum Type { kNone, kInt, kString };
Type type = kNone;
std::string value;
bool valid() const { return type != kNone; }
};
void reflect(JsonReader &visitor, RequestId &value);
void reflect(JsonWriter &visitor, RequestId &value);
struct InMessage {
RequestId id;
std::string method;
std::unique_ptr<char[]> message;
std::unique_ptr<rapidjson::Document> document;
std::chrono::steady_clock::time_point deadline;
std::string backlog_path;
};
enum class ErrorCode {
// Defined by JSON RPC
ParseError = -32700,
InvalidRequest = -32600,
MethodNotFound = -32601,
InvalidParams = -32602,
InternalError = -32603,
serverErrorStart = -32099,
serverErrorEnd = -32000,
ServerNotInitialized = -32002,
UnknownErrorCode = -32001,
// Defined by the protocol.
RequestCancelled = -32800,
};
struct ResponseError {
ErrorCode code;
std::string message;
};
constexpr char ccls_xref[] = "ccls.xref";
constexpr char window_showMessage[] = "window/showMessage";
struct DocumentUri {
static DocumentUri fromPath(const std::string &path);
bool operator==(const DocumentUri &o) const { return raw_uri == o.raw_uri; }
bool operator<(const DocumentUri &o) const { return raw_uri < o.raw_uri; }
void setPath(const std::string &path);
std::string getPath() const;
std::string raw_uri;
};
struct Position {
int line = 0;
int character = 0;
bool operator==(const Position &o) const {
return line == o.line && character == o.character;
}
bool operator<(const Position &o) const {
return line != o.line ? line < o.line : character < o.character;
}
bool operator<=(const Position &o) const {
return line != o.line ? line < o.line : character <= o.character;
}
std::string toString() const;
};
struct lsRange {
Position start;
Position end;
bool operator==(const lsRange &o) const {
return start == o.start && end == o.end;
}
bool operator<(const lsRange &o) const {
return !(start == o.start) ? start < o.start : end < o.end;
}
bool includes(const lsRange &o) const {
return start <= o.start && o.end <= end;
}
bool intersects(const lsRange &o) const {
return start < o.end && o.start < end;
}
};
struct Location {
DocumentUri uri;
lsRange range;
bool operator==(const Location &o) const {
return uri == o.uri && range == o.range;
}
bool operator<(const Location &o) const {
return !(uri == o.uri) ? uri < o.uri : range < o.range;
}
};
struct LocationLink {
std::string targetUri;
lsRange targetRange;
lsRange targetSelectionRange;
explicit operator bool() const { return targetUri.size(); }
explicit operator Location() && {
return {DocumentUri{std::move(targetUri)}, targetSelectionRange};
}
bool operator==(const LocationLink &o) const {
return targetUri == o.targetUri &&
targetSelectionRange == o.targetSelectionRange;
}
bool operator<(const LocationLink &o) const {
return !(targetUri == o.targetUri)
? targetUri < o.targetUri
: targetSelectionRange < o.targetSelectionRange;
}
};
enum class SymbolKind : uint8_t {
Unknown = 0,
File = 1,
Module = 2,
Namespace = 3,
Package = 4,
Class = 5,
Method = 6,
Property = 7,
Field = 8,
Constructor = 9,
Enum = 10,
Interface = 11,
Function = 12,
Variable = 13,
Constant = 14,
String = 15,
Number = 16,
Boolean = 17,
Array = 18,
Object = 19,
Key = 20,
Null = 21,
EnumMember = 22,
Struct = 23,
Event = 24,
Operator = 25,
// For C++, this is interpreted as "template parameter" (including
// non-type template parameters).
TypeParameter = 26,
// ccls extensions
// See also https://github.com/Microsoft/language-server-protocol/issues/344
// for new SymbolKind clang/Index/IndexSymbol.h clang::index::SymbolKind
TypeAlias = 252,
Parameter = 253,
StaticMethod = 254,
Macro = 255,
};
struct SymbolInformation {
std::string_view name;
SymbolKind kind;
Location location;
std::optional<std::string_view> containerName;
};
struct TextDocumentIdentifier {
DocumentUri uri;
};
struct VersionedTextDocumentIdentifier {
DocumentUri uri;
// The version number of this document. number | null
std::optional<int> version;
};
struct TextEdit {
lsRange range;
std::string newText;
};
struct TextDocumentItem {
DocumentUri uri;
std::string languageId;
int version;
std::string text;
};
struct TextDocumentContentChangeEvent {
// The range of the document that changed.
std::optional<lsRange> range;
// The length of the range that got replaced.
std::optional<int> rangeLength;
// The new text of the range/document.
std::string text;
};
struct TextDocumentDidChangeParam {
VersionedTextDocumentIdentifier textDocument;
std::vector<TextDocumentContentChangeEvent> contentChanges;
};
struct WorkDoneProgress {
const char *kind;
std::optional<std::string> title;
std::optional<std::string> message;
std::optional<int> percentage;
};
struct WorkDoneProgressParam {
const char *token;
WorkDoneProgress value;
};
struct WorkspaceFolder {
DocumentUri uri;
std::string name;
};
enum class MessageType : int { Error = 1, Warning = 2, Info = 3, Log = 4 };
REFLECT_UNDERLYING(MessageType)
struct DiagnosticRelatedInformation {
Location location;
std::string message;
};
struct Diagnostic {
lsRange range;
int severity = 0;
int code = 0;
std::string source = "ccls";
std::string message;
std::vector<DiagnosticRelatedInformation> relatedInformation;
std::vector<TextEdit> fixits_;
};
struct ShowMessageParam {
MessageType type = MessageType::Error;
std::string message;
};
// Used to identify the language at a file level. The ordering is important, as
// a file previously identified as `C`, will be changed to `Cpp` if it
// encounters a c++ declaration.
enum class LanguageId {
Unknown = -1,
C = 0,
Cpp = 1,
ObjC = 2,
ObjCpp = 3,
Cuda = 4,
};
} // namespace ccls