-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlsp-connection.ts
68 lines (61 loc) · 3.59 KB
/
lsp-connection.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
/*
* Copyright (C) 2017, 2018 TypeFox and others.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
import lsp from 'vscode-languageserver/node.js';
import { LspClientLogger } from './utils/logger.js';
import { LspServer } from './lsp-server.js';
import { LspClientImpl } from './lsp-client.js';
import type { TsServerLogLevel } from './utils/configuration.js';
export interface LspConnectionOptions {
cmdLineTsserverPath: string;
cmdLineTsserverLogVerbosity: TsServerLogLevel;
showMessageLevel: lsp.MessageType;
}
export function createLspConnection(options: LspConnectionOptions): lsp.Connection {
const connection = lsp.createConnection(lsp.ProposedFeatures.all);
const lspClient = new LspClientImpl(connection);
const logger = new LspClientLogger(lspClient, options.showMessageLevel);
const server: LspServer = new LspServer({
logger,
lspClient,
tsserverPath: options.cmdLineTsserverPath,
tsserverLogVerbosity: options.cmdLineTsserverLogVerbosity,
});
connection.onInitialize(server.initialize.bind(server));
connection.onInitialized(server.initialized.bind(server));
connection.onDidChangeConfiguration(server.didChangeConfiguration.bind(server));
connection.onDidOpenTextDocument(server.didOpenTextDocument.bind(server));
connection.onDidSaveTextDocument(server.didSaveTextDocument.bind(server));
connection.onDidCloseTextDocument(server.didCloseTextDocument.bind(server));
connection.onDidChangeTextDocument(server.didChangeTextDocument.bind(server));
connection.onCodeAction(server.codeAction.bind(server));
connection.onCompletion(server.completion.bind(server));
connection.onCompletionResolve(server.completionResolve.bind(server));
connection.onDefinition(server.definition.bind(server));
connection.onImplementation(server.implementation.bind(server));
connection.onTypeDefinition(server.typeDefinition.bind(server));
connection.onDocumentFormatting(server.documentFormatting.bind(server));
connection.onDocumentRangeFormatting(server.documentRangeFormatting.bind(server));
connection.onDocumentHighlight(server.documentHighlight.bind(server));
connection.onDocumentSymbol(server.documentSymbol.bind(server));
connection.onExecuteCommand(server.executeCommand.bind(server));
connection.onHover(server.hover.bind(server));
connection.onReferences(server.references.bind(server));
connection.onRenameRequest(server.rename.bind(server));
connection.onPrepareRename(server.prepareRename.bind(server));
connection.onSelectionRanges(server.selectionRanges.bind(server));
connection.onSignatureHelp(server.signatureHelp.bind(server));
connection.onWorkspaceSymbol(server.workspaceSymbol.bind(server));
connection.onFoldingRanges(server.foldingRanges.bind(server));
connection.languages.callHierarchy.onPrepare(server.prepareCallHierarchy.bind(server));
connection.languages.callHierarchy.onIncomingCalls(server.callHierarchyIncomingCalls.bind(server));
connection.languages.callHierarchy.onOutgoingCalls(server.callHierarchyOutgoingCalls.bind(server));
connection.languages.inlayHint.on(server.inlayHints.bind(server));
connection.languages.semanticTokens.on(server.semanticTokensFull.bind(server));
connection.languages.semanticTokens.onRange(server.semanticTokensRange.bind(server));
connection.workspace.onWillRenameFiles(server.willRenameFiles.bind(server));
return connection;
}