UNPKG

20.6 kBTypeScriptView Raw
1/// <reference types="node" />
2import * as jsonrpc from "vscode-jsonrpc";
3import * as lsp from "vscode-languageserver-protocol";
4import { EventEmitter } from "events";
5import { Logger } from "./logger";
6export * from "vscode-languageserver-protocol";
7export interface KnownNotifications {
8 "textDocument/publishDiagnostics": lsp.PublishDiagnosticsParams;
9 "telemetry/event": any;
10 "window/logMessage": lsp.LogMessageParams;
11 "window/showMessageRequest": lsp.ShowMessageRequestParams;
12 "window/showMessage": lsp.ShowMessageParams;
13 [custom: string]: object;
14}
15export interface KnownRequests {
16 "window/showDocument": [lsp.ShowDocumentParams, lsp.ShowDocumentResult];
17 "window/showMessageRequest": [lsp.ShowMessageRequestParams, lsp.MessageActionItem | null];
18 "workspace/applyEdit": [lsp.ApplyWorkspaceEditParams, lsp.ApplyWorkspaceEditResponse];
19 [custom: string]: [Record<string, any>, Record<string, any> | null];
20}
21export declare type RequestCallback<T extends keyof KnownRequests> = KnownRequests[T] extends [infer U, infer V] ? (param: U) => Promise<V> : never;
22/**
23 * TypeScript wrapper around JSONRPC to implement Microsoft Language Server Protocol v3
24 * https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md
25 */
26export declare class LanguageClientConnection extends EventEmitter {
27 private _rpc;
28 private _log;
29 isConnected: boolean;
30 constructor(rpc: jsonrpc.MessageConnection, logger?: Logger);
31 private setupLogging;
32 dispose(): void;
33 /**
34 * Public: Initialize the language server with necessary {InitializeParams}.
35 *
36 * @param params The {InitializeParams} containing processId, rootPath, options and server capabilities.
37 * @returns A {Promise} containing the {InitializeResult} with details of the server's capabilities.
38 */
39 initialize(params: lsp.InitializeParams): Promise<lsp.InitializeResult>;
40 /** Public: Send an `initialized` notification to the language server. */
41 initialized(): void;
42 /** Public: Send a `shutdown` request to the language server. */
43 shutdown(): Promise<void>;
44 /** Public: Send an `exit` notification to the language server. */
45 exit(): void;
46 /**
47 * Public: Register a callback for a custom notification
48 *
49 * @param method A string containing the name of the message to listen for.
50 * @param callback The function to be called when the message is received. The payload from the message is passed to
51 * the function.
52 */
53 onCustomNotification(method: string, callback: (obj: object) => void): void;
54 /** @deprecated Use `onCustomNotification` method instead */
55 onCustom(method: string, callback: (obj: object) => void): void;
56 /**
57 * Public: Register a callback for a custom request
58 *
59 * @param method A string containing the name of the message to listen for.
60 * @param callback The function to be called when the message is received. The payload from the message is passed to
61 * the function.
62 */
63 onCustomRequest(method: string, callback: (obj: Record<string, any>) => Promise<Record<string, any> | null>): void;
64 /**
65 * Public: Send a custom request
66 *
67 * @param method A string containing the name of the request message.
68 * @param params The method's parameters
69 */
70 sendCustomRequest(method: string, params?: any[] | object): Promise<any>;
71 /**
72 * Public: Send a custom notification
73 *
74 * @param method A string containing the name of the notification message.
75 * @param params The method's parameters
76 */
77 sendCustomNotification(method: string, params?: any[] | object): void;
78 /**
79 * Public: Register a callback for the `window/showMessage` message.
80 *
81 * @param callback The function to be called when the `window/showMessage` message is received with
82 * {ShowMessageParams} being passed.
83 */
84 onShowMessage(callback: (params: lsp.ShowMessageParams) => void): void;
85 /**
86 * Public: Register a callback for the `window/showMessageRequest` message.
87 *
88 * @param callback The function to be called when the `window/showMessageRequest` message is received with
89 * {ShowMessageRequestParam}' being passed.
90 * @returns A {Promise} containing the {MessageActionItem}.
91 */
92 onShowMessageRequest(callback: (params: lsp.ShowMessageRequestParams) => Promise<lsp.MessageActionItem | null>): void;
93 /**
94 * Public: Register a callback for the `window/showDocument` message.
95 *
96 * @param callback The function to be called when the `window/showDocument` message is received with
97 * {ShowDocumentParams} being passed.
98 */
99 onShowDocument(callback: (params: lsp.ShowDocumentParams) => Promise<lsp.ShowDocumentResult>): void;
100 /**
101 * Public: Register a callback for the `window/logMessage` message.
102 *
103 * @param callback The function to be called when the `window/logMessage` message is received with {LogMessageParams}
104 * being passed.
105 */
106 onLogMessage(callback: (params: lsp.LogMessageParams) => void): void;
107 /**
108 * Public: Register a callback for the `telemetry/event` message.
109 *
110 * @param callback The function to be called when the `telemetry/event` message is received with any parameters
111 * received being passed on.
112 */
113 onTelemetryEvent(callback: (...args: any[]) => void): void;
114 /**
115 * Public: Register a callback for the `workspace/applyEdit` message.
116 *
117 * @param callback The function to be called when the `workspace/applyEdit` message is received with
118 * {ApplyWorkspaceEditParams} being passed.
119 * @returns A {Promise} containing the {ApplyWorkspaceEditResponse}.
120 */
121 onApplyEdit(callback: (params: lsp.ApplyWorkspaceEditParams) => Promise<lsp.ApplyWorkspaceEditResponse>): void;
122 /**
123 * Public: Send a `workspace/didChangeConfiguration` notification.
124 *
125 * @param params The {DidChangeConfigurationParams} containing the new configuration.
126 */
127 didChangeConfiguration(params: lsp.DidChangeConfigurationParams): void;
128 /**
129 * Public: Send a `textDocument/didOpen` notification.
130 *
131 * @param params The {DidOpenTextDocumentParams} containing the opened text document details.
132 */
133 didOpenTextDocument(params: lsp.DidOpenTextDocumentParams): void;
134 /**
135 * Public: Send a `textDocument/didChange` notification.
136 *
137 * @param params The {DidChangeTextDocumentParams} containing the changed text document details including the version
138 * number and actual text changes.
139 */
140 didChangeTextDocument(params: lsp.DidChangeTextDocumentParams): void;
141 /**
142 * Public: Send a `textDocument/didClose` notification.
143 *
144 * @param params The {DidCloseTextDocumentParams} containing the opened text document details.
145 */
146 didCloseTextDocument(params: lsp.DidCloseTextDocumentParams): void;
147 /**
148 * Public: Send a `textDocument/willSave` notification.
149 *
150 * @param params The {WillSaveTextDocumentParams} containing the to-be-saved text document details and the reason for the save.
151 */
152 willSaveTextDocument(params: lsp.WillSaveTextDocumentParams): void;
153 /**
154 * Public: Send a `textDocument/willSaveWaitUntil` notification.
155 *
156 * @param params The {WillSaveTextDocumentParams} containing the to-be-saved text document details and the reason for the save.
157 * @returns A {Promise} containing an {Array} of {TextEdit}s to be applied to the text document before it is saved.
158 */
159 willSaveWaitUntilTextDocument(params: lsp.WillSaveTextDocumentParams): Promise<lsp.TextEdit[] | null>;
160 /**
161 * Public: Send a `textDocument/didSave` notification.
162 *
163 * @param params The {DidSaveTextDocumentParams} containing the saved text document details.
164 */
165 didSaveTextDocument(params: lsp.DidSaveTextDocumentParams): void;
166 /**
167 * Public: Send a `workspace/didChangeWatchedFiles` notification.
168 *
169 * @param params The {DidChangeWatchedFilesParams} containing the array of {FileEvent}s that have been observed upon
170 * the watched files.
171 */
172 didChangeWatchedFiles(params: lsp.DidChangeWatchedFilesParams): void;
173 /**
174 * Public: Register a callback for the `workspace.workspaceFolders` request. This request is sent from the server to
175 * Atom to fetch the current open list of workspace folders
176 *
177 * @param A Callback which returns a {Promise} containing an {Array} of {lsp.WorkspaceFolder[]} or {null} if only a
178 * single file is open in the tool.
179 */
180 onWorkspaceFolders(callback: () => Promise<lsp.WorkspaceFolder[] | null>): void;
181 /**
182 * Public: Send a `workspace/didChangeWorkspaceFolders` notification.
183 *
184 * @param {DidChangeWorkspaceFoldersParams} params An object that contains the actual workspace folder change event
185 * ({WorkspaceFoldersChangeEvent}) in its {event} property
186 */
187 didChangeWorkspaceFolders(params: lsp.DidChangeWorkspaceFoldersParams): void;
188 /**
189 * Public: Register a callback for the `textDocument/publishDiagnostics` message.
190 *
191 * @param callback The function to be called when the `textDocument/publishDiagnostics` message is received a
192 * {PublishDiagnosticsParams} containing new {Diagnostic} messages for a given uri.
193 */
194 onPublishDiagnostics(callback: (params: lsp.PublishDiagnosticsParams) => void): void;
195 /**
196 * Public: Send a `textDocument/completion` request.
197 *
198 * @param params The {TextDocumentPositionParams} or {CompletionParams} for which {CompletionItem}s are desired.
199 * @param cancellationToken The {CancellationToken} that is used to cancel this request if necessary.
200 * @returns A {Promise} containing either a {CompletionList} or an {Array} of {CompletionItem}s.
201 */
202 completion(params: lsp.TextDocumentPositionParams | CompletionParams, cancellationToken?: jsonrpc.CancellationToken): Promise<lsp.CompletionItem[] | lsp.CompletionList | null>;
203 /**
204 * Public: Send a `completionItem/resolve` request.
205 *
206 * @param params The {CompletionItem} for which a fully resolved {CompletionItem} is desired.
207 * @returns A {Promise} containing a fully resolved {CompletionItem}.
208 */
209 completionItemResolve(params: lsp.CompletionItem): Promise<lsp.CompletionItem>;
210 /**
211 * Public: Send a `textDocument/hover` request.
212 *
213 * @param params The {TextDocumentPositionParams} for which a {Hover} is desired.
214 * @returns A {Promise} containing a {Hover}.
215 */
216 hover(params: lsp.TextDocumentPositionParams): Promise<lsp.Hover | null>;
217 /**
218 * Public: Send a `textDocument/signatureHelp` request.
219 *
220 * @param params The {TextDocumentPositionParams} for which a {SignatureHelp} is desired.
221 * @returns A {Promise} containing a {SignatureHelp}.
222 */
223 signatureHelp(params: lsp.TextDocumentPositionParams): Promise<lsp.SignatureHelp | null>;
224 /**
225 * Public: Send a `textDocument/definition` request.
226 *
227 * @param params The {TextDocumentPositionParams} of a symbol for which one or more {Location}s that define that
228 * symbol are required.
229 * @returns A {Promise} containing either a single {Location} or an {Array} of many {Location}s.
230 */
231 gotoDefinition(params: lsp.TextDocumentPositionParams): Promise<lsp.Location | lsp.Location[] | lsp.LocationLink[] | null>;
232 /**
233 * Public: Send a `textDocument/references` request.
234 *
235 * @param params The {TextDocumentPositionParams} of a symbol for which all referring {Location}s are desired.
236 * @returns A {Promise} containing an {Array} of {Location}s that reference this symbol.
237 */
238 findReferences(params: lsp.ReferenceParams): Promise<lsp.Location[] | null>;
239 /**
240 * Public: Send a `textDocument/documentHighlight` request.
241 *
242 * @param params The {TextDocumentPositionParams} of a symbol for which all highlights are desired.
243 * @returns A {Promise} containing an {Array} of {DocumentHighlight}s that can be used to highlight this symbol.
244 */
245 documentHighlight(params: lsp.TextDocumentPositionParams): Promise<lsp.DocumentHighlight[] | null>;
246 /**
247 * Public: Send a `textDocument/documentSymbol` request.
248 *
249 * @param params The {DocumentSymbolParams} that identifies the document for which symbols are desired.
250 * @param cancellationToken The {CancellationToken} that is used to cancel this request if necessary.
251 * @returns A {Promise} containing an {Array} of {SymbolInformation}s that can be used to navigate this document.
252 */
253 documentSymbol(params: lsp.DocumentSymbolParams, _cancellationToken?: jsonrpc.CancellationToken): Promise<lsp.SymbolInformation[] | lsp.DocumentSymbol[] | null>;
254 /**
255 * Public: Send a `workspace/symbol` request.
256 *
257 * @param params The {WorkspaceSymbolParams} containing the query string to search the workspace for.
258 * @returns A {Promise} containing an {Array} of {SymbolInformation}s that identify where the query string occurs
259 * within the workspace.
260 */
261 workspaceSymbol(params: lsp.WorkspaceSymbolParams): Promise<lsp.SymbolInformation[] | null>;
262 /**
263 * Public: Send a `textDocument/codeAction` request.
264 *
265 * @param params The {CodeActionParams} identifying the document, range and context for the code action.
266 * @returns A {Promise} containing an {Array} of {Command}s or {CodeAction}s that can be performed against the given
267 * documents range.
268 */
269 codeAction(params: lsp.CodeActionParams): Promise<Array<lsp.Command | lsp.CodeAction> | null>;
270 /**
271 * Public: Send a `codeAction/resolve` request.
272 *
273 * @param params The {CodeAction} whose properties (e.g. `edit`) are to be resolved.
274 * @returns A resolved {CodeAction} that can be applied immediately.
275 */
276 codeActionResolve(params: lsp.CodeAction): Promise<lsp.CodeAction>;
277 /**
278 * Public: Send a `textDocument/codeLens` request.
279 *
280 * @param params The {CodeLensParams} identifying the document for which code lens commands are desired.
281 * @returns A {Promise} containing an {Array} of {CodeLens}s that associate commands and data with specified ranges
282 * within the document.
283 */
284 codeLens(params: lsp.CodeLensParams): Promise<lsp.CodeLens[] | null>;
285 /**
286 * Public: Send a `codeLens/resolve` request.
287 *
288 * @param params The {CodeLens} identifying the code lens to be resolved with full detail.
289 * @returns A {Promise} containing the {CodeLens} fully resolved.
290 */
291 codeLensResolve(params: lsp.CodeLens): Promise<lsp.CodeLens>;
292 /**
293 * Public: Send a `textDocument/documentLink` request.
294 *
295 * @param params The {DocumentLinkParams} identifying the document for which links should be identified.
296 * @returns A {Promise} containing an {Array} of {DocumentLink}s relating uri's to specific ranges within the document.
297 */
298 documentLink(params: lsp.DocumentLinkParams): Promise<lsp.DocumentLink[] | null>;
299 /**
300 * Public: Send a `documentLink/resolve` request.
301 *
302 * @param params The {DocumentLink} identifying the document link to be resolved with full detail.
303 * @returns A {Promise} containing the {DocumentLink} fully resolved.
304 */
305 documentLinkResolve(params: lsp.DocumentLink): Promise<lsp.DocumentLink>;
306 /**
307 * Public: Send a `textDocument/formatting` request.
308 *
309 * @param params The {DocumentFormattingParams} identifying the document to be formatted as well as additional
310 * formatting preferences.
311 * @returns A {Promise} containing an {Array} of {TextEdit}s to be applied to the document to correctly reformat it.
312 */
313 documentFormatting(params: lsp.DocumentFormattingParams): Promise<lsp.TextEdit[] | null>;
314 /**
315 * Public: Send a `textDocument/rangeFormatting` request.
316 *
317 * @param params The {DocumentRangeFormattingParams} identifying the document and range to be formatted as well as
318 * additional formatting preferences.
319 * @returns A {Promise} containing an {Array} of {TextEdit}s to be applied to the document to correctly reformat it.
320 */
321 documentRangeFormatting(params: lsp.DocumentRangeFormattingParams): Promise<lsp.TextEdit[] | null>;
322 /**
323 * Public: Send a `textDocument/onTypeFormatting` request.
324 *
325 * @param params The {DocumentOnTypeFormattingParams} identifying the document to be formatted, the character that was
326 * typed and at what position as well as additional formatting preferences.
327 * @returns A {Promise} containing an {Array} of {TextEdit}s to be applied to the document to correctly reformat it.
328 */
329 documentOnTypeFormatting(params: lsp.DocumentOnTypeFormattingParams): Promise<lsp.TextEdit[] | null>;
330 /**
331 * Public: Send a `textDocument/rename` request.
332 *
333 * @param params The {RenameParams} identifying the document containing the symbol to be renamed, as well as the
334 * position and new name.
335 * @returns A {Promise} containing an {WorkspaceEdit} that contains a list of {TextEdit}s either on the changes
336 * property (keyed by uri) or the documentChanges property containing an {Array} of {TextDocumentEdit}s (preferred).
337 */
338 rename(params: lsp.RenameParams): Promise<lsp.WorkspaceEdit | null>;
339 /**
340 * Public: Send a `workspace/executeCommand` request.
341 *
342 * @param params The {ExecuteCommandParams} specifying the command and arguments the language server should execute
343 * (these commands are usually from {CodeLens} or {CodeAction} responses).
344 * @returns A {Promise} containing anything.
345 */
346 executeCommand(params: lsp.ExecuteCommandParams): Promise<any>;
347 /**
348 * Public: Send a `textDocument/prepareCallHierarchy` request.
349 *
350 * @param params The {CallHierarchyIncomingCallsParams} that containing {textDocument} and {position} associated with
351 * the calling.
352 * @param cancellationToken The {CancellationToken} that is used to cancel this request if necessary.
353 * @returns A {Promise} containing an {Array} of {CallHierarchyItem}s that corresponding to the request.
354 */
355 prepareCallHierarchy(params: lsp.CallHierarchyPrepareParams, _cancellationToken?: jsonrpc.CancellationToken): Promise<lsp.CallHierarchyItem[] | null>;
356 /**
357 * Public: Send a `callHierarchy/incomingCalls` request.
358 *
359 * @param params The {CallHierarchyIncomingCallsParams} that identifies {CallHierarchyItem} to get incoming calls.
360 * @param cancellationToken The {CancellationToken} that is used to cancel this request if necessary.
361 * @returns A {Promise} containing an {Array} of {CallHierarchyIncomingCall}s for the function that called by the
362 * function given to the parameter.
363 */
364 callHierarchyIncomingCalls(params: lsp.CallHierarchyIncomingCallsParams, _cancellationToken?: jsonrpc.CancellationToken): Promise<lsp.CallHierarchyIncomingCall[] | null>;
365 /**
366 * Public: Send a `callHierarchy/outgoingCalls` request.
367 *
368 * @param params The {CallHierarchyOutgoingCallsParams} that identifies {CallHierarchyItem} to get outgoing calls.
369 * @param cancellationToken The {CancellationToken} that is used to cancel this request if necessary.
370 * @returns A {Promise} containing an {Array} of {CallHierarchyIncomingCall}s for the function that calls the function
371 * given to the parameter.
372 */
373 callHierarchyOutgoingCalls(params: lsp.CallHierarchyOutgoingCallsParams, _cancellationToken?: jsonrpc.CancellationToken): Promise<lsp.CallHierarchyOutgoingCall[] | null>;
374 private _onRequest;
375 private _onNotification;
376 private _sendNotification;
377 private _sendRequest;
378}
379/** Contains additional information about the context in which a completion request is triggered. */
380export interface CompletionContext {
381 /** How the completion was triggered. */
382 triggerKind: lsp.CompletionTriggerKind;
383 /**
384 * The trigger character (a single character) that has trigger code complete. Is undefined if `triggerKind !==
385 * CompletionTriggerKind.TriggerCharacter`
386 */
387 triggerCharacter?: string;
388}
389/** Completion parameters */
390export interface CompletionParams extends lsp.TextDocumentPositionParams {
391 /**
392 * The completion context. This is only available it the client specifies to send this using
393 * `ClientCapabilities.textDocument.completion.contextSupport === true`
394 */
395 context?: CompletionContext;
396}