forked from jeapostrophe/racket-langserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfaces.rkt
More file actions
296 lines (249 loc) · 7.82 KB
/
interfaces.rkt
File metadata and controls
296 lines (249 loc) · 7.82 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
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
#lang racket/base
;; Interface and protocol-facing data types.
;;
;; Placement rule:
;; - Put JSON-serializable structs here when they are part of LSP request/response
;; payloads or otherwise cross protocol boundaries.
;; - Put shared interface structs here when they are consumed across module
;; boundaries (for example formatting options and semantic-token metadata).
;; - JSON payload structs are expected to be encoded with `->jsexpr`.
;;
;; Internal-only runtime/domain structs belong in `internal-types.rkt`.
(require racket/class
racket/contract
racket/match
"json-util.rkt")
(provide (json-type-out Pos)
(json-type-out Range)
char-range-intersect?
(json-type-out TextEdit)
(json-type-out WorkspaceEdit)
(json-type-out CodeAction)
(json-type-out DiagnosticSeverity)
(json-type-out ErrorCode)
(json-type-out Diagnostic)
(json-type-out Location)
(json-type-out DocumentHighlight)
(json-type-out SymbolKind)
(json-type-out SymbolInformation)
(json-type-out Hover)
(json-type-out SignatureInformation)
(json-type-out SignatureHelp)
(json-type-out CompletionItem)
(json-type-out CompletionList)
(json-type-out ContentChangeEvent-Incremental)
(json-type-out ContentChangeEvent-Full)
(json-type-out ContentChangeEvent)
(json-type-out DocIdentifier)
(json-type-out DocItem)
(json-type-out InlayHint)
(json-type-out ConfigurationItem)
(json-type-out ConfigurationParams)
(json-type-out FileRename)
(json-type-out RenameFilesParams)
(json-type-out WorkspaceFolder)
(json-type-out WorkspaceFoldersChangeEvent)
(json-type-out DidChangeWorkspaceFoldersParams)
(json-type-out FileChangeType)
(json-type-out FileEvent)
(json-type-out DidChangeWatchedFilesParams)
(json-type-out FormattingOptions)
(json-type-out SemanticTokenType)
(json-type-out SemanticTokenModifier)
(struct-out SemanticToken)
*semantic-token-types*
*semantic-token-modifiers*
abs-pos->Pos
(json-type-out Resyntax-Result))
(define-json-struct Pos
[line exact-nonnegative-integer?]
[char exact-nonnegative-integer? #:json character])
(define-json-struct Range
[start Pos]
[end Pos])
(define/contract (char-range-intersect? left-start left-end right-start right-end)
(-> exact-nonnegative-integer?
exact-nonnegative-integer?
exact-nonnegative-integer?
exact-nonnegative-integer?
boolean?)
(and (< left-start right-end)
(< right-start left-end)))
(define-json-struct TextEdit
[range Range]
[newText string?])
(define-json-struct WorkspaceEdit
[changes (hash/c symbol? (listof TextEdit))])
(define-json-enum DiagnosticSeverity
[Error 1]
[Warning 2]
[Information 3]
[Hint 4])
(define-json-enum 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 LSP protocol
[RequestCancelled -32800])
(define-json-struct Diagnostic
[range Range]
[severity DiagnosticSeverity]
[source string?]
[message string?])
(define-json-struct CodeAction
[title string?]
[kind string?]
[diagnostics (listof Diagnostic)]
[isPreferred boolean?]
[edit WorkspaceEdit])
(define-json-struct Location
[uri string?]
[range Range])
(define-json-struct DocumentHighlight
[range Range])
(define-json-enum SymbolKind
[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]
[TypeParameter 26])
(define-json-struct SymbolInformation
[name string?]
[kind SymbolKind]
[location Location])
(define-json-struct Hover
[contents string?]
[range Range])
(define-json-struct SignatureInformation
[label string?]
[documentation string?])
(define-json-struct SignatureHelp
[signatures (listof SignatureInformation)])
(define-json-struct CompletionItem
[label string?])
(define-json-struct CompletionList
[isIncomplete boolean?]
[items (listof CompletionItem)])
(define-json-struct ContentChangeEvent-Incremental
[range Range]
[rangeLength (optional exact-nonnegative-integer?)]
[text string?])
(define-json-struct ContentChangeEvent-Full
[text string?])
(define-json-union ContentChangeEvent
ContentChangeEvent-Incremental
ContentChangeEvent-Full)
;; VersionedTextDocumentIdentifier
(define-json-struct DocIdentifier
[version exact-nonnegative-integer?]
[uri string?])
;; TextDocumentItem
(define-json-struct DocItem
[uri string?]
[languageId string?]
[version exact-nonnegative-integer?]
[text string?])
(define-json-struct InlayHint
[position Pos]
[label string?])
(define-json-struct ConfigurationItem
[scopeUri string?]
[section string?])
(define-json-struct ConfigurationParams
[items (listof ConfigurationItem)])
(define-json-struct FileRename
[oldUri string?]
[newUri string?])
(define-json-struct RenameFilesParams
[files (listof FileRename)])
(define-json-struct WorkspaceFolder
[uri string?]
[name string?])
(define-json-struct WorkspaceFoldersChangeEvent
[added (listof WorkspaceFolder)]
[removed (listof WorkspaceFolder)])
(define-json-struct DidChangeWorkspaceFoldersParams
[event WorkspaceFoldersChangeEvent])
(define-json-enum FileChangeType
[created 1]
[changed 2]
[deleted 3])
(define-json-struct FileEvent
[uri string?]
[type FileChangeType])
(define-json-struct DidChangeWatchedFilesParams
[changes (listof FileEvent)])
(define uinteger-upper-limit (sub1 (expt 2 31)))
(define (uinteger? x)
(and (integer? x) (<= 0 x uinteger-upper-limit)))
(define-json-struct FormattingOptions
[tab-size uinteger? #:json tabSize]
[insert-spaces boolean? #:json insertSpaces]
[trim-trailing-whitespace (optional boolean?) #:json trimTrailingWhitespace]
[insert-final-newline (optional boolean?) #:json insertFinalNewline]
[trim-final-newlines (optional boolean?) #:json trimFinalNewlines]
[key (or/c false/c (optional/c hash?))])
(define-json-enum SemanticTokenType
[variable "variable"]
[function "function"]
[string "string"]
[number "number"]
[regexp "regexp"])
(define-json-enum SemanticTokenModifier
[definition "definition"])
(struct SemanticToken
(start end type modifiers)
#:transparent)
;; The order of this list is irrelevant.
;; The client receives this list from server ability declaration during
;; initialize handshake then use it to decode server semantic tokens messages.
;; Different order produces different encoding results of semantic tokens,
;; but does not affect client and server behavior.
;; To change the order, simply change it here, don't need to change other code.
(define *semantic-token-types*
(list SemanticTokenType-variable
SemanticTokenType-function
SemanticTokenType-string
SemanticTokenType-number
SemanticTokenType-regexp))
;; The order of this list is irrelevant, similar to *semantic-token-types*.
(define *semantic-token-modifiers*
(list SemanticTokenModifier-definition))
(define (abs-pos->Pos editor pos)
(match-define (list line char) (send editor pos->line/char pos))
(Pos #:line line #:char char))
;; Resyntax-Result: result of a resyntax refactoring suggestion
(define-json-struct Resyntax-Result
[start exact-nonnegative-integer?]
[end exact-nonnegative-integer?]
[message string?]
[rule-name symbol?]
[new-text string?])