-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathlsp.v
More file actions
232 lines (199 loc) · 5.8 KB
/
lsp.v
File metadata and controls
232 lines (199 loc) · 5.8 KB
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
// Copyright (c) 2025 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by a GPL license that can be found in the LICENSE file.
module main
struct Request {
id int
method string
jsonrpc string
params Params
}
struct Position {
line int
char int @[json: 'character']
}
struct TextDocumentIdentifier {
uri string
}
struct Params {
content_changes []ContentChange @[json: 'contentChanges']
position Position
range LSPRange
text_document TextDocumentIdentifier @[json: 'textDocument']
new_name string @[json: 'newName']
}
struct ContentChange {
text string
}
struct Response {
id int
result ResponseResult
jsonrpc string = '2.0'
}
// A Location represents a specific location in a file.
struct Location {
uri string
range LSPRange
}
type ResponseResult = string
| []Detail
| Capabilities
| SignatureHelp
| Location
| Hover
| []Location
| WorkspaceEdit
| []TextEdit
| []DocumentSymbol
| []InlayHint
struct DocumentSymbol {
name string @[json: 'name']
kind int @[json: 'kind']
range LSPRange @[json: 'range']
selection_range LSPRange @[json: 'selectionRange']
children []DocumentSymbol @[json: 'children']
}
// LSP SymbolKind constants for the most common V declarations
const sym_kind_file = 1
const sym_kind_module = 2
const sym_kind_namespace = 3
const sym_kind_package = 4
const sym_kind_class = 5
const sym_kind_method = 6
const sym_kind_property = 7
const sym_kind_field = 8
const sym_kind_enum = 10
const sym_kind_interface = 11
const sym_kind_function = 12
const sym_kind_variable = 13
const sym_kind_constant = 14
const sym_kind_string = 15
const sym_kind_struct = 23
const sym_kind_enum_member = 22
const sym_kind_type_parameter = 26
struct Notification {
method string
params PublishDiagnosticsParams
jsonrpc string = '2.0'
}
struct PublishDiagnosticsParams {
uri string
diagnostics []LSPDiagnostic
}
struct LSPDiagnostic {
range LSPRange
message string
severity int
}
struct LSPRange {
start Position
end Position
}
struct Detail {
kind int // The type of item (e.g., Method, Function, Field)
label string // The name of the completion item
detail string // Additional info like the function signature or return type
declaration string // Full fn declaration, e.g. "fn greet(name string) string"
documentation string // The documentation for the item
insert_text ?string @[json: 'insertText']
insert_text_format ?int @[json: 'insertTextFormat'] // 1 for PlainText, 2 for Snippet
}
struct Capabilities {
capabilities Capability
}
struct Capability {
completion_provider CompletionProvider @[json: 'completionProvider']
text_document_sync TextDocumentSyncOptions @[json: 'textDocumentSync']
signature_help_provider SignatureHelpOptions @[json: 'signatureHelpProvider']
definition_provider bool @[json: 'definitionProvider']
hover_provider bool @[json: 'hoverProvider']
references_provider bool @[json: 'referencesProvider']
rename_provider bool @[json: 'renameProvider']
document_formatting_provider bool @[json: 'documentFormattingProvider']
document_symbol_provider bool @[json: 'documentSymbolProvider']
inlay_hint_provider bool @[json: 'inlayHintProvider']
}
struct CompletionItemCapability {
snippet_support bool @[json: 'snippetSupport']
}
struct CompletionProvider {
trigger_characters []string @[json: 'triggerCharacters']
completion_item ?CompletionItemCapability @[json: 'completionItem']
}
struct TextDocumentSyncOptions {
open_close bool @[json: 'openClose']
change int // 1 for Full, 2 for Incremental
}
struct SignatureHelpOptions {
trigger_characters []string @[json: 'triggerCharacters']
}
struct SignatureHelp {
signatures []SignatureInformation
active_signature int @[json: 'activeSignature']
active_parameter int @[json: 'activeParameter']
}
struct SignatureInformation {
label string
parameters []ParameterInformation
}
struct ParameterInformation {
label string
}
struct Hover {
contents MarkupContent
range ?LSPRange
}
struct MarkupContent {
kind string // "plaintext" or "markdown"
value string
}
struct WorkspaceEdit {
changes map[string][]TextEdit
}
struct TextEdit {
range LSPRange
new_text string @[json: 'newText']
}
// InlayHintKind 1 = Type hint, 2 = Parameter hint
const inlay_hint_kind_type = 1
struct InlayHint {
position Position
label string
kind int @[json: 'kind']
padding_left bool @[json: 'paddingLeft']
}
enum Method {
unknown @['unknown']
initialize @['initialize']
initialized @['initialized']
did_open @['textDocument/didOpen']
did_change @['textDocument/didChange']
definition @['textDocument/definition']
completion @['textDocument/completion']
signature_help @['textDocument/signatureHelp']
hover @['textDocument/hover']
references @['textDocument/references']
rename @['textDocument/rename']
formatting @['textDocument/formatting']
document_symbols @['textDocument/documentSymbol']
inlay_hint @['textDocument/inlayHint']
set_trace @['$/setTrace']
cancel_request @['$/cancelRequest']
shutdown @['shutdown']
exit @['exit']
}
fn Method.from_string(s string) Method {
$for m in Method.values {
if s == m.attrs[0] {
return m.value
}
}
return Method.unknown
}
fn (m Method) str() string {
$for v in Method.values {
if m == v.value {
return v.attrs[0]
}
}
return 'unknown'
}