-
Notifications
You must be signed in to change notification settings - Fork 7
/
types.ts
290 lines (273 loc) · 7.7 KB
/
types.ts
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
import * as lsProtocol from 'vscode-languageserver-protocol';
import { Location, LocationLink } from 'vscode-languageserver-protocol';
export interface IPosition {
line: number;
ch: number;
}
export interface ITokenInfo {
start: IPosition;
end: IPosition;
text: string;
}
type ConnectionEvent = 'completion' | 'completionResolved' | 'hover' | 'diagnostic' | 'highlight' |
'signature' | 'goTo' | 'error' | 'logging';
export interface ILspConnection {
on(event: 'completion', callback: (items: lsProtocol.CompletionItem[]) => void): void;
on(event: 'completionResolved', callback: (item: lsProtocol.CompletionItem) => void): void;
on(event: 'hover', callback: (hover: lsProtocol.Hover) => void): void;
on(event: 'diagnostic', callback: (diagnostic: lsProtocol.PublishDiagnosticsParams) => void): void;
on(event: 'highlight', callback: (highlights: lsProtocol.DocumentHighlight[]) => void): void;
on(event: 'signature', callback: (signatures: lsProtocol.SignatureHelp) => void): void;
on(event: 'goTo', callback: (location: Location | Location[] | LocationLink[] | null) => void): void;
on(event: 'error', callback: (error: any) => void): void;
on(event: 'logging', callback: (log: any) => void): void;
off(event: ConnectionEvent, listener: (arg: any) => void): void;
/**
* Close the connection
*/
close(): void;
// This should support every method from https://microsoft.github.io/language-server-protocol/specification
/**
* The initialize request tells the server which options the client supports
*/
sendInitialize(): void;
/**
* Sends the full text of the document to the server
*/
sendChange(): void;
/**
* Requests additional information for a particular character
*/
getHoverTooltip(position: IPosition): void;
/**
* Request possible completions from the server
*/
getCompletion(
location: IPosition,
token: ITokenInfo,
triggerCharacter?: string,
triggerKind?: lsProtocol.CompletionTriggerKind,
): void;
/**
* If the server returns incomplete information for completion items, more information can be requested
*/
getDetailedCompletion(item: lsProtocol.CompletionItem): void;
/**
* Request possible signatures for the current method
*/
getSignatureHelp(position: IPosition): void;
/**
* Request all matching symbols in the document scope
*/
getDocumentHighlights(position: IPosition): void;
/**
* Request a link to the definition of the current symbol. The results will not be displayed
* unless they are within the same file URI
*/
getDefinition(position: IPosition): void;
/**
* Request a link to the type definition of the current symbol. The results will not be displayed
* unless they are within the same file URI
*/
getTypeDefinition(position: IPosition): void;
/**
* Request a link to the implementation of the current symbol. The results will not be displayed
* unless they are within the same file URI
*/
getImplementation(position: IPosition): void;
/**
* Request a link to all references to the current symbol. The results will not be displayed
* unless they are within the same file URI
*/
getReferences(position: IPosition): void;
// TODO:
// Workspaces: Not in scope
// Text Synchronization:
// willSave
// willSaveWaitUntil
// didSave
// didClose
// Language features:
// getDocumentSymbols
// codeAction
// codeLens
// codeLensResolve
// documentLink
// documentLinkResolve
// documentColor
// colorPresentation
// formatting
// rangeFormatting
// onTypeFormatting
// rename
// prepareRename
// foldingRange
getLanguageCompletionCharacters(): string[];
getLanguageSignatureCharacters(): string[];
getDocumentUri(): string;
/**
* Does the server support go to definition?
*/
isDefinitionSupported(): boolean;
/**
* Does the server support go to type definition?
*/
isTypeDefinitionSupported(): boolean;
/**
* Does the server support go to implementation?
*/
isImplementationSupported(): boolean;
/**
* Does the server support find all references?
*/
isReferencesSupported(): boolean;
}
/**
* Configuration map for codeActionsOnSave
*/
export interface ICodeActionsOnSaveOptions {
[kind: string]: boolean;
}
export interface ITextEditorOptions {
/**
* Enable the suggestion box to pop-up on trigger characters.
* Defaults to true.
*/
suggestOnTriggerCharacters?: boolean;
/**
* Accept suggestions on ENTER.
* Defaults to 'on'.
*/
acceptSuggestionOnEnter?: boolean | 'on' | 'smart' | 'off';
/**
* Accept suggestions on TAB.
* Defaults to 'on'.
*/
acceptSuggestionOnTab?: boolean | 'on' | 'smart' | 'off';
/**
* Accept suggestions on provider defined characters.
* Defaults to true.
*/
acceptSuggestionOnCommitCharacter?: boolean;
/**
* Enable selection highlight.
* Defaults to true.
*/
selectionHighlight?: boolean;
/**
* Enable semantic occurrences highlight.
* Defaults to true.
*/
occurrencesHighlight?: boolean;
/**
* Show code lens
* Defaults to true.
*/
codeLens?: boolean;
/**
* Code action kinds to be run on save.
*/
codeActionsOnSave?: ICodeActionsOnSaveOptions;
/**
* Timeout for running code actions on save.
*/
codeActionsOnSaveTimeout?: number;
/**
* Enable code folding
* Defaults to true.
*/
folding?: boolean;
/**
* Selects the folding strategy. 'auto' uses the strategies contributed for the current document,
* 'indentation' uses the indentation based folding strategy.
* Defaults to 'auto'.
*/
foldingStrategy?: 'auto' | 'indentation';
/**
* Controls whether the fold actions in the gutter stay always visible or hide unless the mouse is over the gutter.
* Defaults to 'mouseover'.
*/
showFoldingControls?: 'always' | 'mouseover';
/**
* Whether to suggest while typing
*/
suggest?: boolean;
/**
* Debounce (in ms) for suggestions while typing.
* Defaults to 200ms
*/
debounceSuggestionsWhileTyping?: number;
/**
* Enable quick suggestions (shadow suggestions)
* Defaults to true.
*/
quickSuggestions?: boolean | {
other: boolean;
comments: boolean;
strings: boolean;
};
/**
* Quick suggestions show delay (in ms)
* Defaults to 200 (ms)
*/
quickSuggestionsDelay?: number;
/**
* Parameter hint options. Defaults to true.
*/
enableParameterHints?: boolean;
/**
* Render icons in suggestions box.
* Defaults to true.
*/
iconsInSuggestions?: boolean;
/**
* Enable format on type.
* Defaults to false.
*/
formatOnType?: boolean;
/**
* Enable format on paste.
* Defaults to false.
*/
formatOnPaste?: boolean;
}
export interface ILspOptions {
serverUri: string;
languageId: string;
documentUri: string;
documentText: (() => string);
rootUri: string;
}
/**
* An adapter is responsible for connecting a particular text editor with a LSP connection
* and will send messages over the connection and display responses in the editor
*/
export abstract class IEditorAdapter<T> {
constructor(connection: ILspConnection, options: ITextEditorOptions, editor: T) {}
/**
* Removes the adapter from the editor and closes the connection
*/
public abstract remove(): void;
}
export function getFilledDefaults(options: ITextEditorOptions): ITextEditorOptions {
return Object.assign({}, {
suggestOnTriggerCharacters: true,
acceptSuggestionOnEnter: true,
acceptSuggestionOnTab: true,
acceptSuggestionOnCommitCharacter: true,
selectionHighlight: true,
occurrencesHighlight: true,
codeLens: true,
folding: true,
foldingStrategy: 'auto',
showFoldingControls: 'mouseover',
suggest: true,
debounceSuggestionsWhileTyping: 200,
quickSuggestions: true,
quickSuggestionsDelay: 200,
enableParameterHints: true,
iconsInSuggestions: true,
formatOnType: false,
formatOnPaste: false,
}, options);
}