typescript-language-server 0.11.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +32 -6
- package/lib/calls.d.ts +3 -3
- package/lib/calls.d.ts.map +1 -1
- package/lib/calls.js +18 -46
- package/lib/calls.js.map +1 -1
- package/lib/cli.js +8 -32
- package/lib/cli.js.map +1 -1
- package/lib/commands.js +1 -4
- package/lib/commands.js.map +1 -1
- package/lib/completion.d.ts +6 -6
- package/lib/completion.d.ts.map +1 -1
- package/lib/completion.js +76 -116
- package/lib/completion.js.map +1 -1
- package/lib/diagnostic-queue.d.ts +5 -5
- package/lib/diagnostic-queue.d.ts.map +1 -1
- package/lib/diagnostic-queue.js +7 -14
- package/lib/diagnostic-queue.js.map +1 -1
- package/lib/document-symbol.d.ts +2 -2
- package/lib/document-symbol.d.ts.map +1 -1
- package/lib/document-symbol.js +16 -22
- package/lib/document-symbol.js.map +1 -1
- package/lib/document.d.ts +1 -1
- package/lib/document.d.ts.map +1 -1
- package/lib/document.js +6 -34
- package/lib/document.js.map +1 -1
- package/lib/features/fix-all.d.ts +4 -4
- package/lib/features/fix-all.d.ts.map +1 -1
- package/lib/features/fix-all.js +17 -44
- package/lib/features/fix-all.js.map +1 -1
- package/lib/file-lsp-server.spec.js +17 -18
- package/lib/file-lsp-server.spec.js.map +1 -1
- package/lib/hover.d.ts +2 -2
- package/lib/hover.d.ts.map +1 -1
- package/lib/hover.js +8 -12
- package/lib/hover.js.map +1 -1
- package/lib/logger.d.ts +12 -4
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +36 -43
- package/lib/logger.js.map +1 -1
- package/lib/lsp-client.d.ts +3 -3
- package/lib/lsp-client.d.ts.map +1 -1
- package/lib/lsp-client.js +4 -31
- package/lib/lsp-client.js.map +1 -1
- package/lib/lsp-connection.d.ts +1 -1
- package/lib/lsp-connection.d.ts.map +1 -1
- package/lib/lsp-connection.js +10 -37
- package/lib/lsp-connection.js.map +1 -1
- package/lib/lsp-protocol.calls.proposed.d.ts +1 -1
- package/lib/lsp-protocol.calls.proposed.d.ts.map +1 -1
- package/lib/lsp-protocol.calls.proposed.js +7 -32
- package/lib/lsp-protocol.calls.proposed.js.map +1 -1
- package/lib/lsp-protocol.inlayHints.proposed.d.ts +2 -2
- package/lib/lsp-protocol.inlayHints.proposed.d.ts.map +1 -1
- package/lib/lsp-protocol.inlayHints.proposed.js +2 -28
- package/lib/lsp-protocol.inlayHints.proposed.js.map +1 -1
- package/lib/lsp-server.d.ts +13 -9
- package/lib/lsp-server.d.ts.map +1 -1
- package/lib/lsp-server.js +226 -189
- package/lib/lsp-server.js.map +1 -1
- package/lib/lsp-server.spec.js +243 -245
- package/lib/lsp-server.spec.js.map +1 -1
- package/lib/organize-imports.d.ts +3 -3
- package/lib/organize-imports.d.ts.map +1 -1
- package/lib/organize-imports.js +5 -32
- package/lib/organize-imports.js.map +1 -1
- package/lib/organize-imports.spec.js +9 -34
- package/lib/organize-imports.spec.js.map +1 -1
- package/lib/protocol-translation.d.ts +3 -3
- package/lib/protocol-translation.d.ts.map +1 -1
- package/lib/protocol-translation.js +26 -70
- package/lib/protocol-translation.js.map +1 -1
- package/lib/quickfix.d.ts +3 -3
- package/lib/quickfix.d.ts.map +1 -1
- package/lib/quickfix.js +7 -35
- package/lib/quickfix.js.map +1 -1
- package/lib/refactor.d.ts +2 -2
- package/lib/refactor.d.ts.map +1 -1
- package/lib/refactor.js +7 -36
- package/lib/refactor.js.map +1 -1
- package/lib/semantic-tokens.d.ts +1 -1
- package/lib/semantic-tokens.d.ts.map +1 -1
- package/lib/semantic-tokens.js +1 -5
- package/lib/semantic-tokens.js.map +1 -1
- package/lib/test-utils.d.ts +4 -2
- package/lib/test-utils.d.ts.map +1 -1
- package/lib/test-utils.js +39 -60
- package/lib/test-utils.js.map +1 -1
- package/lib/ts-protocol.d.ts +7 -4
- package/lib/ts-protocol.d.ts.map +1 -1
- package/lib/ts-protocol.js +4 -31
- package/lib/ts-protocol.js.map +1 -1
- package/lib/tsp-client.d.ts +42 -43
- package/lib/tsp-client.d.ts.map +1 -1
- package/lib/tsp-client.js +23 -46
- package/lib/tsp-client.js.map +1 -1
- package/lib/tsp-client.spec.js +36 -56
- package/lib/tsp-client.spec.js.map +1 -1
- package/lib/tsp-command-types.js +3 -7
- package/lib/tsp-command-types.js.map +1 -1
- package/lib/utils/SnippetString.js +1 -4
- package/lib/utils/SnippetString.js.map +1 -1
- package/lib/utils/api.d.ts +1 -0
- package/lib/utils/api.d.ts.map +1 -1
- package/lib/utils/api.js +3 -28
- package/lib/utils/api.js.map +1 -1
- package/lib/utils/configuration.d.ts +2 -2
- package/lib/utils/configuration.d.ts.map +1 -1
- package/lib/utils/configuration.js +1 -2
- package/lib/utils/errorCodes.js +11 -14
- package/lib/utils/errorCodes.js.map +1 -1
- package/lib/utils/fixNames.js +13 -16
- package/lib/utils/fixNames.js.map +1 -1
- package/lib/utils/modules-resolver.js +7 -34
- package/lib/utils/modules-resolver.js.map +1 -1
- package/lib/utils/modules-resolver.spec.d.ts +1 -1
- package/lib/utils/modules-resolver.spec.d.ts.map +1 -1
- package/lib/utils/modules-resolver.spec.js +11 -34
- package/lib/utils/modules-resolver.spec.js.map +1 -1
- package/lib/utils/typeConverters.d.ts +1 -1
- package/lib/utils/typeConverters.d.ts.map +1 -1
- package/lib/utils/typeConverters.js +2 -5
- package/lib/utils/typeConverters.js.map +1 -1
- package/lib/utils/types.js +2 -29
- package/lib/utils/types.js.map +1 -1
- package/lib/utils/versionProvider.d.ts +3 -3
- package/lib/utils/versionProvider.d.ts.map +1 -1
- package/lib/utils/versionProvider.js +35 -41
- package/lib/utils/versionProvider.js.map +1 -1
- package/lib/utils.js +1 -5
- package/lib/utils.js.map +1 -1
- package/package.json +35 -33
package/lib/lsp-server.js
CHANGED
|
@@ -1,33 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
* Copyright (C) 2017, 2018 TypeFox and others.
|
|
4
3
|
*
|
|
5
4
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
|
|
6
5
|
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
7
6
|
*/
|
|
8
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
}) : (function(o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
}));
|
|
19
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
-
}) : function(o, v) {
|
|
22
|
-
o["default"] = v;
|
|
23
|
-
});
|
|
24
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
-
if (mod && mod.__esModule) return mod;
|
|
26
|
-
var result = {};
|
|
27
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
-
__setModuleDefault(result, mod);
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
7
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
32
8
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
33
9
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -37,34 +13,61 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
37
13
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
38
14
|
});
|
|
39
15
|
};
|
|
40
|
-
|
|
41
|
-
|
|
16
|
+
import * as path from 'node:path';
|
|
17
|
+
import fs from 'fs-extra';
|
|
18
|
+
import debounce from 'p-debounce';
|
|
19
|
+
import { temporaryFile } from 'tempy';
|
|
20
|
+
import * as lsp from 'vscode-languageserver';
|
|
21
|
+
import * as lspcalls from './lsp-protocol.calls.proposed.js';
|
|
22
|
+
import * as lspsemanticTokens from './semantic-tokens.js';
|
|
23
|
+
import API from './utils/api.js';
|
|
24
|
+
import { PrefixingLogger } from './logger.js';
|
|
25
|
+
import { TspClient } from './tsp-client.js';
|
|
26
|
+
import { DiagnosticEventQueue } from './diagnostic-queue.js';
|
|
27
|
+
import { toDocumentHighlight, asRange, asTagsDocumentation, uriToPath, toSymbolKind, toLocation, toPosition, pathToUri, toTextEdit, toFileRangeRequestArgs, asPlainText, normalizePath } from './protocol-translation.js';
|
|
28
|
+
import { LspDocuments } from './document.js';
|
|
29
|
+
import { asCompletionItem, asResolvedCompletionItem, getCompletionTriggerCharacter } from './completion.js';
|
|
30
|
+
import { asSignatureHelp } from './hover.js';
|
|
31
|
+
import { Commands } from './commands.js';
|
|
32
|
+
import { provideQuickFix } from './quickfix.js';
|
|
33
|
+
import { provideRefactors } from './refactor.js';
|
|
34
|
+
import { provideOrganizeImports } from './organize-imports.js';
|
|
35
|
+
import { collectDocumentSymbols, collectSymbolInformation } from './document-symbol.js';
|
|
36
|
+
import { computeCallers, computeCallees } from './calls.js';
|
|
37
|
+
import { TypeScriptVersionProvider } from './utils/versionProvider.js';
|
|
38
|
+
import { TypeScriptAutoFixProvider } from './features/fix-all.js';
|
|
39
|
+
import { CodeActionKind } from './utils/types.js';
|
|
40
|
+
const DEFAULT_TSSERVER_PREFERENCES = {
|
|
41
|
+
allowIncompleteCompletions: true,
|
|
42
|
+
allowRenameOfImportPath: true,
|
|
43
|
+
allowTextChangesInNewFiles: true,
|
|
44
|
+
disableSuggestions: false,
|
|
45
|
+
displayPartsForJSDoc: true,
|
|
46
|
+
generateReturnInDocTemplate: true,
|
|
47
|
+
importModuleSpecifierEnding: 'auto',
|
|
48
|
+
importModuleSpecifierPreference: 'shortest',
|
|
49
|
+
includeAutomaticOptionalChainCompletions: true,
|
|
50
|
+
includeCompletionsForImportStatements: true,
|
|
51
|
+
includeCompletionsForModuleExports: true,
|
|
52
|
+
includeCompletionsWithClassMemberSnippets: true,
|
|
53
|
+
includeCompletionsWithInsertText: true,
|
|
54
|
+
includeCompletionsWithObjectLiteralMethodSnippets: true,
|
|
55
|
+
includeCompletionsWithSnippetText: true,
|
|
56
|
+
includeInlayEnumMemberValueHints: false,
|
|
57
|
+
includeInlayFunctionLikeReturnTypeHints: false,
|
|
58
|
+
includeInlayFunctionParameterTypeHints: false,
|
|
59
|
+
includeInlayParameterNameHints: 'none',
|
|
60
|
+
includeInlayParameterNameHintsWhenArgumentMatchesName: false,
|
|
61
|
+
includeInlayPropertyDeclarationTypeHints: false,
|
|
62
|
+
includeInlayVariableTypeHints: false,
|
|
63
|
+
includePackageJsonAutoImports: 'auto',
|
|
64
|
+
jsxAttributeCompletionStyle: 'auto',
|
|
65
|
+
lazyConfiguredProjectsFromExternalProject: false,
|
|
66
|
+
providePrefixAndSuffixTextForRename: true,
|
|
67
|
+
provideRefactorNotApplicableReason: false,
|
|
68
|
+
quotePreference: 'auto',
|
|
69
|
+
useLabelDetailsInCompletionEntries: true
|
|
42
70
|
};
|
|
43
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
-
exports.LspServer = void 0;
|
|
45
|
-
const path = __importStar(require("path"));
|
|
46
|
-
const tempy_1 = __importDefault(require("tempy"));
|
|
47
|
-
const lsp = __importStar(require("vscode-languageserver/node"));
|
|
48
|
-
const lspcalls = __importStar(require("./lsp-protocol.calls.proposed"));
|
|
49
|
-
const lspsemanticTokens = __importStar(require("./semantic-tokens"));
|
|
50
|
-
const fs = __importStar(require("fs-extra"));
|
|
51
|
-
const p_debounce_1 = __importDefault(require("p-debounce"));
|
|
52
|
-
const logger_1 = require("./logger");
|
|
53
|
-
const tsp_client_1 = require("./tsp-client");
|
|
54
|
-
const diagnostic_queue_1 = require("./diagnostic-queue");
|
|
55
|
-
const protocol_translation_1 = require("./protocol-translation");
|
|
56
|
-
const document_1 = require("./document");
|
|
57
|
-
const completion_1 = require("./completion");
|
|
58
|
-
const hover_1 = require("./hover");
|
|
59
|
-
const commands_1 = require("./commands");
|
|
60
|
-
const quickfix_1 = require("./quickfix");
|
|
61
|
-
const refactor_1 = require("./refactor");
|
|
62
|
-
const organize_imports_1 = require("./organize-imports");
|
|
63
|
-
const document_symbol_1 = require("./document-symbol");
|
|
64
|
-
const calls_1 = require("./calls");
|
|
65
|
-
const versionProvider_1 = require("./utils/versionProvider");
|
|
66
|
-
const fix_all_1 = require("./features/fix-all");
|
|
67
|
-
const types_1 = require("./utils/types");
|
|
68
71
|
class ServerInitializingIndicator {
|
|
69
72
|
constructor(lspClient) {
|
|
70
73
|
this.lspClient = lspClient;
|
|
@@ -96,15 +99,16 @@ class ServerInitializingIndicator {
|
|
|
96
99
|
}
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
|
-
class LspServer {
|
|
102
|
+
export class LspServer {
|
|
100
103
|
constructor(options) {
|
|
101
104
|
this.options = options;
|
|
102
|
-
this.
|
|
105
|
+
this.features = {};
|
|
106
|
+
this.documents = new LspDocuments();
|
|
103
107
|
// True if diagnostic request is currently debouncing or the request is in progress. False only if there are
|
|
104
108
|
// no pending requests.
|
|
105
109
|
this.pendingDebouncedRequest = false;
|
|
106
|
-
this.doRequestDiagnosticsDebounced = (
|
|
107
|
-
this.logger = new
|
|
110
|
+
this.doRequestDiagnosticsDebounced = debounce(() => this.doRequestDiagnostics(), 200);
|
|
111
|
+
this.logger = new PrefixingLogger(options.logger, '[lspserver]');
|
|
108
112
|
this.workspaceConfiguration = {};
|
|
109
113
|
}
|
|
110
114
|
closeAll() {
|
|
@@ -112,8 +116,30 @@ class LspServer {
|
|
|
112
116
|
this.closeDocument(file);
|
|
113
117
|
}
|
|
114
118
|
}
|
|
119
|
+
shutdown() {
|
|
120
|
+
if (this._tspClient) {
|
|
121
|
+
this._tspClient.shutdown();
|
|
122
|
+
this._tspClient = null;
|
|
123
|
+
}
|
|
124
|
+
if (this._loadingIndicator) {
|
|
125
|
+
this._loadingIndicator.reset();
|
|
126
|
+
this._loadingIndicator = null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
get tspClient() {
|
|
130
|
+
if (!this._tspClient) {
|
|
131
|
+
throw new Error('TS client not created. Did you forget to send the "initialize" request?');
|
|
132
|
+
}
|
|
133
|
+
return this._tspClient;
|
|
134
|
+
}
|
|
135
|
+
get loadingIndicator() {
|
|
136
|
+
if (!this._loadingIndicator) {
|
|
137
|
+
throw new Error('Loading indicator not created. Did you forget to send the "initialize" request?');
|
|
138
|
+
}
|
|
139
|
+
return this._loadingIndicator;
|
|
140
|
+
}
|
|
115
141
|
findTypescriptVersion() {
|
|
116
|
-
const typescriptVersionProvider = new
|
|
142
|
+
const typescriptVersionProvider = new TypeScriptVersionProvider(this.options, this.logger);
|
|
117
143
|
// User-provided tsserver path.
|
|
118
144
|
const userSettingVersion = typescriptVersionProvider.getUserSettingVersion();
|
|
119
145
|
if (userSettingVersion) {
|
|
@@ -137,21 +163,23 @@ class LspServer {
|
|
|
137
163
|
return null;
|
|
138
164
|
}
|
|
139
165
|
initialize(params) {
|
|
140
|
-
var _a, _b, _c;
|
|
166
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
141
167
|
return __awaiter(this, void 0, void 0, function* () {
|
|
142
168
|
this.logger.log('initialize', params);
|
|
169
|
+
if (this._tspClient) {
|
|
170
|
+
throw new Error('The "initialize" request has already called before.');
|
|
171
|
+
}
|
|
143
172
|
this.initializeParams = params;
|
|
144
173
|
const clientCapabilities = this.initializeParams.capabilities;
|
|
145
174
|
this.options.lspClient.setClientCapabilites(clientCapabilities);
|
|
146
|
-
this.
|
|
147
|
-
this.workspaceRoot = this.initializeParams.rootUri ?
|
|
148
|
-
this.diagnosticQueue = new
|
|
175
|
+
this._loadingIndicator = new ServerInitializingIndicator(this.options.lspClient);
|
|
176
|
+
this.workspaceRoot = this.initializeParams.rootUri ? uriToPath(this.initializeParams.rootUri) : this.initializeParams.rootPath || undefined;
|
|
177
|
+
this.diagnosticQueue = new DiagnosticEventQueue(diagnostics => this.options.lspClient.publishDiagnostics(diagnostics), this.documents, (_a = clientCapabilities.textDocument) === null || _a === void 0 ? void 0 : _a.publishDiagnostics, this.logger);
|
|
149
178
|
const userInitializationOptions = this.initializeParams.initializationOptions || {};
|
|
150
179
|
const { disableAutomaticTypingAcquisition, hostInfo, maxTsServerMemory, npmLocation, locale } = userInitializationOptions;
|
|
151
|
-
const { logVerbosity, plugins
|
|
180
|
+
const { logVerbosity, plugins } = {
|
|
152
181
|
logVerbosity: userInitializationOptions.logVerbosity || this.options.tsserverLogVerbosity,
|
|
153
|
-
plugins: userInitializationOptions.plugins || []
|
|
154
|
-
preferences: Object.assign({ allowIncompleteCompletions: true, allowRenameOfImportPath: true, allowTextChangesInNewFiles: true, displayPartsForJSDoc: true, generateReturnInDocTemplate: true, includeAutomaticOptionalChainCompletions: true, includeCompletionsForImportStatements: true, includeCompletionsForModuleExports: true, includeCompletionsWithClassMemberSnippets: true, includeCompletionsWithInsertText: true, includeCompletionsWithSnippetText: true, jsxAttributeCompletionStyle: 'auto', providePrefixAndSuffixTextForRename: true }, userInitializationOptions.preferences)
|
|
182
|
+
plugins: userInitializationOptions.plugins || []
|
|
155
183
|
};
|
|
156
184
|
const logFile = this.getLogFile(logVerbosity);
|
|
157
185
|
const globalPlugins = [];
|
|
@@ -167,7 +195,14 @@ class LspServer {
|
|
|
167
195
|
else {
|
|
168
196
|
throw Error('Could not find a valid tsserver executable in the workspace or in the $PATH. Please ensure that the "typescript" dependency is installed in either location. Exiting.');
|
|
169
197
|
}
|
|
170
|
-
|
|
198
|
+
const userPreferences = Object.assign(Object.assign({}, DEFAULT_TSSERVER_PREFERENCES), userInitializationOptions.preferences);
|
|
199
|
+
if (userPreferences.useLabelDetailsInCompletionEntries
|
|
200
|
+
&& ((_d = (_c = (_b = clientCapabilities.textDocument) === null || _b === void 0 ? void 0 : _b.completion) === null || _c === void 0 ? void 0 : _c.completionItem) === null || _d === void 0 ? void 0 : _d.labelDetailsSupport)
|
|
201
|
+
&& ((_e = typescriptVersion.version) === null || _e === void 0 ? void 0 : _e.gte(API.v470))) {
|
|
202
|
+
this.features.labelDetails = true;
|
|
203
|
+
}
|
|
204
|
+
const finalPreferences = Object.assign(Object.assign({}, userPreferences), { useLabelDetailsInCompletionEntries: this.features.labelDetails });
|
|
205
|
+
this._tspClient = new TspClient({
|
|
171
206
|
tsserverPath: typescriptVersion.tsServerPath,
|
|
172
207
|
logFile,
|
|
173
208
|
logVerbosity,
|
|
@@ -180,9 +215,10 @@ class LspServer {
|
|
|
180
215
|
logger: this.options.logger,
|
|
181
216
|
onEvent: this.onTsEvent.bind(this),
|
|
182
217
|
onExit: (exitCode, signal) => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
218
|
+
if (exitCode) {
|
|
219
|
+
this.logger.error(`tsserver process has exited (exit code: ${exitCode}, signal: ${signal}). Stopping the server.`);
|
|
220
|
+
}
|
|
221
|
+
this.shutdown();
|
|
186
222
|
}
|
|
187
223
|
});
|
|
188
224
|
const started = this.tspClient.start();
|
|
@@ -190,32 +226,29 @@ class LspServer {
|
|
|
190
226
|
throw new Error('tsserver process has failed to start.');
|
|
191
227
|
}
|
|
192
228
|
process.on('exit', () => {
|
|
193
|
-
this.
|
|
194
|
-
if (this.loadingIndicator) {
|
|
195
|
-
this.loadingIndicator.reset();
|
|
196
|
-
}
|
|
229
|
+
this.shutdown();
|
|
197
230
|
});
|
|
198
231
|
process.on('SIGINT', () => {
|
|
199
232
|
process.exit();
|
|
200
233
|
});
|
|
201
|
-
this.typeScriptAutoFixProvider = new
|
|
234
|
+
this.typeScriptAutoFixProvider = new TypeScriptAutoFixProvider(this.tspClient);
|
|
202
235
|
yield Promise.all([
|
|
203
|
-
this.tspClient.request("configure" /* Configure */, Object.assign(Object.assign({}, hostInfo ? { hostInfo } : {}), { formatOptions: {
|
|
236
|
+
this.tspClient.request("configure" /* CommandTypes.Configure */, Object.assign(Object.assign({}, hostInfo ? { hostInfo } : {}), { formatOptions: {
|
|
204
237
|
// We can use \n here since the editor should normalize later on to its line endings.
|
|
205
238
|
newLineCharacter: '\n'
|
|
206
|
-
}, preferences })),
|
|
207
|
-
this.tspClient.request("compilerOptionsForInferredProjects" /* CompilerOptionsForInferredProjects */, {
|
|
239
|
+
}, preferences: finalPreferences })),
|
|
240
|
+
this.tspClient.request("compilerOptionsForInferredProjects" /* CommandTypes.CompilerOptionsForInferredProjects */, {
|
|
208
241
|
options: {
|
|
209
|
-
module: "CommonJS" /* CommonJS */,
|
|
210
|
-
target: "ES2016" /* ES2016 */,
|
|
211
|
-
jsx: "Preserve" /* Preserve */,
|
|
242
|
+
module: "CommonJS" /* tsp.ModuleKind.CommonJS */,
|
|
243
|
+
target: "ES2016" /* tsp.ScriptTarget.ES2016 */,
|
|
244
|
+
jsx: "Preserve" /* tsp.JsxEmit.Preserve */,
|
|
212
245
|
allowJs: true,
|
|
213
246
|
allowSyntheticDefaultImports: true,
|
|
214
247
|
allowNonTsExtensions: true
|
|
215
248
|
}
|
|
216
249
|
})
|
|
217
250
|
]);
|
|
218
|
-
const logFileUri = logFile &&
|
|
251
|
+
const logFileUri = logFile && pathToUri(logFile, undefined);
|
|
219
252
|
this.initializeResult = {
|
|
220
253
|
capabilities: {
|
|
221
254
|
textDocumentSync: lsp.TextDocumentSyncKind.Incremental,
|
|
@@ -223,8 +256,13 @@ class LspServer {
|
|
|
223
256
|
triggerCharacters: ['.', '"', '\'', '/', '@', '<'],
|
|
224
257
|
resolveProvider: true
|
|
225
258
|
},
|
|
226
|
-
codeActionProvider: ((
|
|
227
|
-
? { codeActionKinds: [
|
|
259
|
+
codeActionProvider: ((_g = (_f = clientCapabilities.textDocument) === null || _f === void 0 ? void 0 : _f.codeAction) === null || _g === void 0 ? void 0 : _g.codeActionLiteralSupport)
|
|
260
|
+
? { codeActionKinds: [
|
|
261
|
+
...TypeScriptAutoFixProvider.kinds.map(kind => kind.value),
|
|
262
|
+
CodeActionKind.SourceOrganizeImportsTs.value,
|
|
263
|
+
CodeActionKind.QuickFix.value,
|
|
264
|
+
CodeActionKind.Refactor.value
|
|
265
|
+
] } : true,
|
|
228
266
|
definitionProvider: true,
|
|
229
267
|
documentFormattingProvider: true,
|
|
230
268
|
documentRangeFormattingProvider: true,
|
|
@@ -232,11 +270,11 @@ class LspServer {
|
|
|
232
270
|
documentSymbolProvider: true,
|
|
233
271
|
executeCommandProvider: {
|
|
234
272
|
commands: [
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
273
|
+
Commands.APPLY_WORKSPACE_EDIT,
|
|
274
|
+
Commands.APPLY_CODE_ACTION,
|
|
275
|
+
Commands.APPLY_REFACTORING,
|
|
276
|
+
Commands.ORGANIZE_IMPORTS,
|
|
277
|
+
Commands.APPLY_RENAME_FILE
|
|
240
278
|
]
|
|
241
279
|
},
|
|
242
280
|
hoverProvider: true,
|
|
@@ -297,7 +335,7 @@ class LspServer {
|
|
|
297
335
|
fs.ensureFileSync(logFile);
|
|
298
336
|
return logFile;
|
|
299
337
|
}
|
|
300
|
-
return
|
|
338
|
+
return temporaryFile({ name: 'tsserver.log' });
|
|
301
339
|
}
|
|
302
340
|
doGetLogFile() {
|
|
303
341
|
if (process.env.TSSERVER_LOG_FILE) {
|
|
@@ -348,7 +386,7 @@ class LspServer {
|
|
|
348
386
|
this.diagnosticsTokenSource = geterrTokenSource;
|
|
349
387
|
const { files } = this.documents;
|
|
350
388
|
try {
|
|
351
|
-
return yield this.tspClient.request("geterr" /* Geterr */, { delay: 0, files }, this.diagnosticsTokenSource.token);
|
|
389
|
+
return yield this.tspClient.request("geterr" /* CommandTypes.Geterr */, { delay: 0, files }, this.diagnosticsTokenSource.token);
|
|
352
390
|
}
|
|
353
391
|
finally {
|
|
354
392
|
if (this.diagnosticsTokenSource === geterrTokenSource) {
|
|
@@ -364,13 +402,13 @@ class LspServer {
|
|
|
364
402
|
}
|
|
365
403
|
}
|
|
366
404
|
didOpenTextDocument(params) {
|
|
367
|
-
const file =
|
|
405
|
+
const file = uriToPath(params.textDocument.uri);
|
|
368
406
|
this.logger.log('onDidOpenTextDocument', params, file);
|
|
369
407
|
if (!file) {
|
|
370
408
|
return;
|
|
371
409
|
}
|
|
372
410
|
if (this.documents.open(file, params.textDocument)) {
|
|
373
|
-
this.tspClient.notify("open" /* Open */, {
|
|
411
|
+
this.tspClient.notify("open" /* CommandTypes.Open */, {
|
|
374
412
|
file,
|
|
375
413
|
fileContent: params.textDocument.text,
|
|
376
414
|
scriptKindName: this.getScriptKindName(params.textDocument.languageId),
|
|
@@ -400,7 +438,7 @@ class LspServer {
|
|
|
400
438
|
return undefined;
|
|
401
439
|
}
|
|
402
440
|
didCloseTextDocument(params) {
|
|
403
|
-
const file =
|
|
441
|
+
const file = uriToPath(params.textDocument.uri);
|
|
404
442
|
this.logger.log('onDidCloseTextDocument', params, file);
|
|
405
443
|
if (!file) {
|
|
406
444
|
return;
|
|
@@ -412,7 +450,7 @@ class LspServer {
|
|
|
412
450
|
if (!document) {
|
|
413
451
|
return;
|
|
414
452
|
}
|
|
415
|
-
this.tspClient.notify("close" /* Close */, { file });
|
|
453
|
+
this.tspClient.notify("close" /* CommandTypes.Close */, { file });
|
|
416
454
|
// We won't be updating diagnostics anymore for that file, so clear them
|
|
417
455
|
// so we don't leave stale ones.
|
|
418
456
|
this.options.lspClient.publishDiagnostics({
|
|
@@ -422,7 +460,7 @@ class LspServer {
|
|
|
422
460
|
}
|
|
423
461
|
didChangeTextDocument(params) {
|
|
424
462
|
const { textDocument } = params;
|
|
425
|
-
const file =
|
|
463
|
+
const file = uriToPath(textDocument.uri);
|
|
426
464
|
this.logger.log('onDidChangeTextDocument', params, file);
|
|
427
465
|
if (!file) {
|
|
428
466
|
return;
|
|
@@ -453,7 +491,7 @@ class LspServer {
|
|
|
453
491
|
endLine = endPos.line + 1;
|
|
454
492
|
endOffset = endPos.character + 1;
|
|
455
493
|
}
|
|
456
|
-
this.tspClient.notify("change" /* Change */, {
|
|
494
|
+
this.tspClient.notify("change" /* CommandTypes.Change */, {
|
|
457
495
|
file,
|
|
458
496
|
line,
|
|
459
497
|
offset,
|
|
@@ -495,7 +533,7 @@ class LspServer {
|
|
|
495
533
|
}
|
|
496
534
|
getDefinition({ type, params }) {
|
|
497
535
|
return __awaiter(this, void 0, void 0, function* () {
|
|
498
|
-
const file =
|
|
536
|
+
const file = uriToPath(params.textDocument.uri);
|
|
499
537
|
this.logger.log(type, params, file);
|
|
500
538
|
if (!file) {
|
|
501
539
|
return [];
|
|
@@ -505,17 +543,17 @@ class LspServer {
|
|
|
505
543
|
line: params.position.line + 1,
|
|
506
544
|
offset: params.position.character + 1
|
|
507
545
|
});
|
|
508
|
-
return result.body ? result.body.map(fileSpan =>
|
|
546
|
+
return result.body ? result.body.map(fileSpan => toLocation(fileSpan, this.documents)) : [];
|
|
509
547
|
});
|
|
510
548
|
}
|
|
511
549
|
documentSymbol(params) {
|
|
512
550
|
return __awaiter(this, void 0, void 0, function* () {
|
|
513
|
-
const file =
|
|
551
|
+
const file = uriToPath(params.textDocument.uri);
|
|
514
552
|
this.logger.log('symbol', params, file);
|
|
515
553
|
if (!file) {
|
|
516
554
|
return [];
|
|
517
555
|
}
|
|
518
|
-
const response = yield this.tspClient.request("navtree" /* NavTree */, {
|
|
556
|
+
const response = yield this.tspClient.request("navtree" /* CommandTypes.NavTree */, {
|
|
519
557
|
file
|
|
520
558
|
});
|
|
521
559
|
const tree = response.body;
|
|
@@ -525,13 +563,13 @@ class LspServer {
|
|
|
525
563
|
if (this.supportHierarchicalDocumentSymbol) {
|
|
526
564
|
const symbols = [];
|
|
527
565
|
for (const item of tree.childItems) {
|
|
528
|
-
|
|
566
|
+
collectDocumentSymbols(item, symbols);
|
|
529
567
|
}
|
|
530
568
|
return symbols;
|
|
531
569
|
}
|
|
532
570
|
const symbols = [];
|
|
533
571
|
for (const item of tree.childItems) {
|
|
534
|
-
|
|
572
|
+
collectSymbolInformation(params.textDocument.uri, item, symbols);
|
|
535
573
|
}
|
|
536
574
|
return symbols;
|
|
537
575
|
});
|
|
@@ -547,7 +585,7 @@ class LspServer {
|
|
|
547
585
|
*/
|
|
548
586
|
completion(params) {
|
|
549
587
|
return __awaiter(this, void 0, void 0, function* () {
|
|
550
|
-
const file =
|
|
588
|
+
const file = uriToPath(params.textDocument.uri);
|
|
551
589
|
this.logger.log('completion', params, file);
|
|
552
590
|
if (!file) {
|
|
553
591
|
return lsp.CompletionList.create([]);
|
|
@@ -559,18 +597,18 @@ class LspServer {
|
|
|
559
597
|
try {
|
|
560
598
|
const result = yield this.interuptDiagnostics(() => {
|
|
561
599
|
var _a, _b;
|
|
562
|
-
return this.tspClient.request("completionInfo" /* CompletionInfo */, {
|
|
600
|
+
return this.tspClient.request("completionInfo" /* CommandTypes.CompletionInfo */, {
|
|
563
601
|
file,
|
|
564
602
|
line: params.position.line + 1,
|
|
565
603
|
offset: params.position.character + 1,
|
|
566
|
-
triggerCharacter:
|
|
604
|
+
triggerCharacter: getCompletionTriggerCharacter((_a = params.context) === null || _a === void 0 ? void 0 : _a.triggerCharacter),
|
|
567
605
|
triggerKind: (_b = params.context) === null || _b === void 0 ? void 0 : _b.triggerKind
|
|
568
606
|
});
|
|
569
607
|
});
|
|
570
608
|
const { body } = result;
|
|
571
609
|
const completions = (body ? body.entries : [])
|
|
572
610
|
.filter(entry => entry.kind !== 'warning')
|
|
573
|
-
.map(entry =>
|
|
611
|
+
.map(entry => asCompletionItem(entry, file, params.position, document, this.features));
|
|
574
612
|
return lsp.CompletionList.create(completions, body === null || body === void 0 ? void 0 : body.isIncomplete);
|
|
575
613
|
}
|
|
576
614
|
catch (error) {
|
|
@@ -587,20 +625,20 @@ class LspServer {
|
|
|
587
625
|
completionResolve(item) {
|
|
588
626
|
return __awaiter(this, void 0, void 0, function* () {
|
|
589
627
|
this.logger.log('completion/resolve', item);
|
|
590
|
-
yield this.tspClient.request("configure" /* Configure */, {
|
|
628
|
+
yield this.tspClient.request("configure" /* CommandTypes.Configure */, {
|
|
591
629
|
formatOptions: this.getWorkspacePreferencesForDocument(item.data.file).format
|
|
592
630
|
});
|
|
593
|
-
const { body } = yield this.interuptDiagnostics(() => this.tspClient.request("completionEntryDetails" /* CompletionDetails */, item.data));
|
|
631
|
+
const { body } = yield this.interuptDiagnostics(() => this.tspClient.request("completionEntryDetails" /* CommandTypes.CompletionDetails */, item.data));
|
|
594
632
|
const details = body && body.length && body[0];
|
|
595
633
|
if (!details) {
|
|
596
634
|
return item;
|
|
597
635
|
}
|
|
598
|
-
return
|
|
636
|
+
return asResolvedCompletionItem(item, details, this.tspClient, this.workspaceConfiguration.completions || {});
|
|
599
637
|
});
|
|
600
638
|
}
|
|
601
639
|
hover(params) {
|
|
602
640
|
return __awaiter(this, void 0, void 0, function* () {
|
|
603
|
-
const file =
|
|
641
|
+
const file = uriToPath(params.textDocument.uri);
|
|
604
642
|
this.logger.log('hover', params, file);
|
|
605
643
|
if (!file) {
|
|
606
644
|
return { contents: [] };
|
|
@@ -609,13 +647,13 @@ class LspServer {
|
|
|
609
647
|
if (!result || !result.body) {
|
|
610
648
|
return { contents: [] };
|
|
611
649
|
}
|
|
612
|
-
const range =
|
|
650
|
+
const range = asRange(result.body);
|
|
613
651
|
const contents = [];
|
|
614
652
|
if (result.body.displayString) {
|
|
615
653
|
contents.push({ language: 'typescript', value: result.body.displayString });
|
|
616
654
|
}
|
|
617
|
-
const tags =
|
|
618
|
-
const documentation =
|
|
655
|
+
const tags = asTagsDocumentation(result.body.tags);
|
|
656
|
+
const documentation = asPlainText(result.body.documentation);
|
|
619
657
|
contents.push(documentation + (tags ? '\n\n' + tags : ''));
|
|
620
658
|
return {
|
|
621
659
|
contents,
|
|
@@ -626,7 +664,7 @@ class LspServer {
|
|
|
626
664
|
getQuickInfo(file, position) {
|
|
627
665
|
return __awaiter(this, void 0, void 0, function* () {
|
|
628
666
|
try {
|
|
629
|
-
return yield this.tspClient.request("quickinfo" /* Quickinfo */, {
|
|
667
|
+
return yield this.tspClient.request("quickinfo" /* CommandTypes.Quickinfo */, {
|
|
630
668
|
file,
|
|
631
669
|
line: position.line + 1,
|
|
632
670
|
offset: position.character + 1
|
|
@@ -639,12 +677,12 @@ class LspServer {
|
|
|
639
677
|
}
|
|
640
678
|
rename(params) {
|
|
641
679
|
return __awaiter(this, void 0, void 0, function* () {
|
|
642
|
-
const file =
|
|
680
|
+
const file = uriToPath(params.textDocument.uri);
|
|
643
681
|
this.logger.log('onRename', params, file);
|
|
644
682
|
if (!file) {
|
|
645
683
|
return undefined;
|
|
646
684
|
}
|
|
647
|
-
const result = yield this.tspClient.request("rename" /* Rename */, {
|
|
685
|
+
const result = yield this.tspClient.request("rename" /* CommandTypes.Rename */, {
|
|
648
686
|
file,
|
|
649
687
|
line: params.position.line + 1,
|
|
650
688
|
offset: params.position.character + 1
|
|
@@ -657,13 +695,13 @@ class LspServer {
|
|
|
657
695
|
};
|
|
658
696
|
result.body.locs
|
|
659
697
|
.forEach((spanGroup) => {
|
|
660
|
-
const uri =
|
|
698
|
+
const uri = pathToUri(spanGroup.file, this.documents), textEdits = workspaceEdit.changes[uri] || (workspaceEdit.changes[uri] = []);
|
|
661
699
|
spanGroup.locs.forEach((textSpan) => {
|
|
662
700
|
textEdits.push({
|
|
663
701
|
newText: `${textSpan.prefixText || ''}${params.newName}${textSpan.suffixText || ''}`,
|
|
664
702
|
range: {
|
|
665
|
-
start:
|
|
666
|
-
end:
|
|
703
|
+
start: toPosition(textSpan.start),
|
|
704
|
+
end: toPosition(textSpan.end)
|
|
667
705
|
}
|
|
668
706
|
});
|
|
669
707
|
});
|
|
@@ -673,12 +711,12 @@ class LspServer {
|
|
|
673
711
|
}
|
|
674
712
|
references(params) {
|
|
675
713
|
return __awaiter(this, void 0, void 0, function* () {
|
|
676
|
-
const file =
|
|
714
|
+
const file = uriToPath(params.textDocument.uri);
|
|
677
715
|
this.logger.log('onReferences', params, file);
|
|
678
716
|
if (!file) {
|
|
679
717
|
return [];
|
|
680
718
|
}
|
|
681
|
-
const result = yield this.tspClient.request("references" /* References */, {
|
|
719
|
+
const result = yield this.tspClient.request("references" /* CommandTypes.References */, {
|
|
682
720
|
file,
|
|
683
721
|
line: params.position.line + 1,
|
|
684
722
|
offset: params.position.character + 1
|
|
@@ -688,22 +726,22 @@ class LspServer {
|
|
|
688
726
|
}
|
|
689
727
|
return result.body.refs
|
|
690
728
|
.filter(fileSpan => params.context.includeDeclaration || !fileSpan.isDefinition)
|
|
691
|
-
.map(fileSpan =>
|
|
729
|
+
.map(fileSpan => toLocation(fileSpan, this.documents));
|
|
692
730
|
});
|
|
693
731
|
}
|
|
694
732
|
documentFormatting(params) {
|
|
695
733
|
return __awaiter(this, void 0, void 0, function* () {
|
|
696
|
-
const file =
|
|
734
|
+
const file = uriToPath(params.textDocument.uri);
|
|
697
735
|
this.logger.log('documentFormatting', params, file);
|
|
698
736
|
if (!file) {
|
|
699
737
|
return [];
|
|
700
738
|
}
|
|
701
739
|
const formatOptions = this.getFormattingOptions(file, params.options);
|
|
702
740
|
// options are not yet supported in tsserver, but we can send a configure request first
|
|
703
|
-
yield this.tspClient.request("configure" /* Configure */, {
|
|
741
|
+
yield this.tspClient.request("configure" /* CommandTypes.Configure */, {
|
|
704
742
|
formatOptions
|
|
705
743
|
});
|
|
706
|
-
const response = yield this.tspClient.request("format" /* Format */, {
|
|
744
|
+
const response = yield this.tspClient.request("format" /* CommandTypes.Format */, {
|
|
707
745
|
file,
|
|
708
746
|
line: 1,
|
|
709
747
|
offset: 1,
|
|
@@ -712,24 +750,24 @@ class LspServer {
|
|
|
712
750
|
options: formatOptions
|
|
713
751
|
});
|
|
714
752
|
if (response.body) {
|
|
715
|
-
return response.body.map(e =>
|
|
753
|
+
return response.body.map(e => toTextEdit(e));
|
|
716
754
|
}
|
|
717
755
|
return [];
|
|
718
756
|
});
|
|
719
757
|
}
|
|
720
758
|
documentRangeFormatting(params) {
|
|
721
759
|
return __awaiter(this, void 0, void 0, function* () {
|
|
722
|
-
const file =
|
|
760
|
+
const file = uriToPath(params.textDocument.uri);
|
|
723
761
|
this.logger.log('documentRangeFormatting', params, file);
|
|
724
762
|
if (!file) {
|
|
725
763
|
return [];
|
|
726
764
|
}
|
|
727
765
|
const formatOptions = this.getFormattingOptions(file, params.options);
|
|
728
766
|
// options are not yet supported in tsserver, but we can send a configure request first
|
|
729
|
-
yield this.tspClient.request("configure" /* Configure */, {
|
|
767
|
+
yield this.tspClient.request("configure" /* CommandTypes.Configure */, {
|
|
730
768
|
formatOptions
|
|
731
769
|
});
|
|
732
|
-
const response = yield this.tspClient.request("format" /* Format */, {
|
|
770
|
+
const response = yield this.tspClient.request("format" /* CommandTypes.Format */, {
|
|
733
771
|
file,
|
|
734
772
|
line: params.range.start.line + 1,
|
|
735
773
|
offset: params.range.start.character + 1,
|
|
@@ -738,7 +776,7 @@ class LspServer {
|
|
|
738
776
|
options: formatOptions
|
|
739
777
|
});
|
|
740
778
|
if (response.body) {
|
|
741
|
-
return response.body.map(e =>
|
|
779
|
+
return response.body.map(e => toTextEdit(e));
|
|
742
780
|
}
|
|
743
781
|
return [];
|
|
744
782
|
});
|
|
@@ -765,7 +803,7 @@ class LspServer {
|
|
|
765
803
|
}
|
|
766
804
|
signatureHelp(params) {
|
|
767
805
|
return __awaiter(this, void 0, void 0, function* () {
|
|
768
|
-
const file =
|
|
806
|
+
const file = uriToPath(params.textDocument.uri);
|
|
769
807
|
this.logger.log('signatureHelp', params, file);
|
|
770
808
|
if (!file) {
|
|
771
809
|
return undefined;
|
|
@@ -774,13 +812,13 @@ class LspServer {
|
|
|
774
812
|
if (!response || !response.body) {
|
|
775
813
|
return undefined;
|
|
776
814
|
}
|
|
777
|
-
return
|
|
815
|
+
return asSignatureHelp(response.body);
|
|
778
816
|
});
|
|
779
817
|
}
|
|
780
818
|
getSignatureHelp(file, position) {
|
|
781
819
|
return __awaiter(this, void 0, void 0, function* () {
|
|
782
820
|
try {
|
|
783
|
-
return yield this.tspClient.request("signatureHelp" /* SignatureHelp */, {
|
|
821
|
+
return yield this.tspClient.request("signatureHelp" /* CommandTypes.SignatureHelp */, {
|
|
784
822
|
file,
|
|
785
823
|
line: position.line + 1,
|
|
786
824
|
offset: position.character + 1
|
|
@@ -794,23 +832,23 @@ class LspServer {
|
|
|
794
832
|
codeAction(params) {
|
|
795
833
|
var _a, _b;
|
|
796
834
|
return __awaiter(this, void 0, void 0, function* () {
|
|
797
|
-
const file =
|
|
835
|
+
const file = uriToPath(params.textDocument.uri);
|
|
798
836
|
this.logger.log('codeAction', params, file);
|
|
799
837
|
if (!file) {
|
|
800
838
|
return [];
|
|
801
839
|
}
|
|
802
|
-
const args =
|
|
840
|
+
const args = toFileRangeRequestArgs(file, params.range);
|
|
803
841
|
const actions = [];
|
|
804
|
-
const kinds = (_a = params.context.only) === null || _a === void 0 ? void 0 : _a.map(kind => new
|
|
805
|
-
if (!kinds || kinds.some(kind => kind.contains(
|
|
842
|
+
const kinds = (_a = params.context.only) === null || _a === void 0 ? void 0 : _a.map(kind => new CodeActionKind(kind));
|
|
843
|
+
if (!kinds || kinds.some(kind => kind.contains(CodeActionKind.QuickFix))) {
|
|
806
844
|
const errorCodes = params.context.diagnostics.map(diagnostic => Number(diagnostic.code));
|
|
807
|
-
actions.push(...
|
|
845
|
+
actions.push(...provideQuickFix(yield this.getCodeFixes(Object.assign(Object.assign({}, args), { errorCodes })), this.documents));
|
|
808
846
|
}
|
|
809
|
-
if (!kinds || kinds.some(kind => kind.contains(
|
|
810
|
-
actions.push(...
|
|
847
|
+
if (!kinds || kinds.some(kind => kind.contains(CodeActionKind.Refactor))) {
|
|
848
|
+
actions.push(...provideRefactors(yield this.getRefactors(args), args));
|
|
811
849
|
}
|
|
812
850
|
// organize import is provided by tsserver for any line, so we only get it if explicitly requested
|
|
813
|
-
if (kinds === null || kinds === void 0 ? void 0 : kinds.some(kind => kind.contains(
|
|
851
|
+
if (kinds === null || kinds === void 0 ? void 0 : kinds.some(kind => kind.contains(CodeActionKind.SourceOrganizeImportsTs))) {
|
|
814
852
|
// see this issue for more context about how this argument is used
|
|
815
853
|
// https://github.com/microsoft/TypeScript/issues/43051
|
|
816
854
|
const skipDestructiveCodeActions = params.context.diagnostics.some(
|
|
@@ -820,7 +858,7 @@ class LspServer {
|
|
|
820
858
|
scope: { type: 'file', args },
|
|
821
859
|
skipDestructiveCodeActions
|
|
822
860
|
});
|
|
823
|
-
actions.push(...
|
|
861
|
+
actions.push(...provideOrganizeImports(response, this.documents));
|
|
824
862
|
}
|
|
825
863
|
// TODO: Since we rely on diagnostics pointing at errors in the correct places, we can't proceed if we are not
|
|
826
864
|
// sure that diagnostics are up-to-date. Thus we check `pendingDebouncedRequest` to see if there are *any*
|
|
@@ -839,7 +877,7 @@ class LspServer {
|
|
|
839
877
|
getCodeFixes(args) {
|
|
840
878
|
return __awaiter(this, void 0, void 0, function* () {
|
|
841
879
|
try {
|
|
842
|
-
return yield this.tspClient.request("getCodeFixes" /* GetCodeFixes */, args);
|
|
880
|
+
return yield this.tspClient.request("getCodeFixes" /* CommandTypes.GetCodeFixes */, args);
|
|
843
881
|
}
|
|
844
882
|
catch (err) {
|
|
845
883
|
return undefined;
|
|
@@ -849,7 +887,7 @@ class LspServer {
|
|
|
849
887
|
getRefactors(args) {
|
|
850
888
|
return __awaiter(this, void 0, void 0, function* () {
|
|
851
889
|
try {
|
|
852
|
-
return yield this.tspClient.request("getApplicableRefactors" /* GetApplicableRefactors */, args);
|
|
890
|
+
return yield this.tspClient.request("getApplicableRefactors" /* CommandTypes.GetApplicableRefactors */, args);
|
|
853
891
|
}
|
|
854
892
|
catch (err) {
|
|
855
893
|
return undefined;
|
|
@@ -860,10 +898,10 @@ class LspServer {
|
|
|
860
898
|
return __awaiter(this, void 0, void 0, function* () {
|
|
861
899
|
try {
|
|
862
900
|
// Pass format options to organize imports
|
|
863
|
-
yield this.tspClient.request("configure" /* Configure */, {
|
|
901
|
+
yield this.tspClient.request("configure" /* CommandTypes.Configure */, {
|
|
864
902
|
formatOptions: this.getWorkspacePreferencesForDocument(args.scope.args.file).format
|
|
865
903
|
});
|
|
866
|
-
return yield this.tspClient.request("organizeImports" /* OrganizeImports */, args);
|
|
904
|
+
return yield this.tspClient.request("organizeImports" /* CommandTypes.OrganizeImports */, args);
|
|
867
905
|
}
|
|
868
906
|
catch (err) {
|
|
869
907
|
return undefined;
|
|
@@ -873,26 +911,26 @@ class LspServer {
|
|
|
873
911
|
executeCommand(arg) {
|
|
874
912
|
return __awaiter(this, void 0, void 0, function* () {
|
|
875
913
|
this.logger.log('executeCommand', arg);
|
|
876
|
-
if (arg.command ===
|
|
914
|
+
if (arg.command === Commands.APPLY_WORKSPACE_EDIT && arg.arguments) {
|
|
877
915
|
const edit = arg.arguments[0];
|
|
878
916
|
yield this.options.lspClient.applyWorkspaceEdit({
|
|
879
917
|
edit
|
|
880
918
|
});
|
|
881
919
|
}
|
|
882
|
-
else if (arg.command ===
|
|
920
|
+
else if (arg.command === Commands.APPLY_CODE_ACTION && arg.arguments) {
|
|
883
921
|
const codeAction = arg.arguments[0];
|
|
884
922
|
if (!(yield this.applyFileCodeEdits(codeAction.changes))) {
|
|
885
923
|
return;
|
|
886
924
|
}
|
|
887
925
|
if (codeAction.commands && codeAction.commands.length) {
|
|
888
926
|
for (const command of codeAction.commands) {
|
|
889
|
-
yield this.tspClient.request("applyCodeActionCommand" /* ApplyCodeActionCommand */, { command });
|
|
927
|
+
yield this.tspClient.request("applyCodeActionCommand" /* CommandTypes.ApplyCodeActionCommand */, { command });
|
|
890
928
|
}
|
|
891
929
|
}
|
|
892
930
|
}
|
|
893
|
-
else if (arg.command ===
|
|
931
|
+
else if (arg.command === Commands.APPLY_REFACTORING && arg.arguments) {
|
|
894
932
|
const args = arg.arguments[0];
|
|
895
|
-
const { body } = yield this.tspClient.request("getEditsForRefactor" /* GetEditsForRefactor */, args);
|
|
933
|
+
const { body } = yield this.tspClient.request("getEditsForRefactor" /* CommandTypes.GetEditsForRefactor */, args);
|
|
896
934
|
if (!body || !body.edits.length) {
|
|
897
935
|
return;
|
|
898
936
|
}
|
|
@@ -906,19 +944,19 @@ class LspServer {
|
|
|
906
944
|
if (renameLocation) {
|
|
907
945
|
yield this.options.lspClient.rename({
|
|
908
946
|
textDocument: {
|
|
909
|
-
uri:
|
|
947
|
+
uri: pathToUri(args.file, this.documents)
|
|
910
948
|
},
|
|
911
|
-
position:
|
|
949
|
+
position: toPosition(renameLocation)
|
|
912
950
|
});
|
|
913
951
|
}
|
|
914
952
|
}
|
|
915
|
-
else if (arg.command ===
|
|
953
|
+
else if (arg.command === Commands.ORGANIZE_IMPORTS && arg.arguments) {
|
|
916
954
|
const file = arg.arguments[0];
|
|
917
955
|
const additionalArguments = arg.arguments[1] || {};
|
|
918
|
-
yield this.tspClient.request("configure" /* Configure */, {
|
|
956
|
+
yield this.tspClient.request("configure" /* CommandTypes.Configure */, {
|
|
919
957
|
formatOptions: this.getWorkspacePreferencesForDocument(file).format
|
|
920
958
|
});
|
|
921
|
-
const { body } = yield this.tspClient.request("organizeImports" /* OrganizeImports */, {
|
|
959
|
+
const { body } = yield this.tspClient.request("organizeImports" /* CommandTypes.OrganizeImports */, {
|
|
922
960
|
scope: {
|
|
923
961
|
type: 'file',
|
|
924
962
|
args: { file }
|
|
@@ -927,17 +965,17 @@ class LspServer {
|
|
|
927
965
|
});
|
|
928
966
|
yield this.applyFileCodeEdits(body);
|
|
929
967
|
}
|
|
930
|
-
else if (arg.command ===
|
|
968
|
+
else if (arg.command === Commands.APPLY_RENAME_FILE && arg.arguments) {
|
|
931
969
|
const { sourceUri, targetUri } = arg.arguments[0];
|
|
932
970
|
this.applyRenameFile(sourceUri, targetUri);
|
|
933
971
|
}
|
|
934
|
-
else if (arg.command ===
|
|
972
|
+
else if (arg.command === Commands.APPLY_COMPLETION_CODE_ACTION && arg.arguments) {
|
|
935
973
|
const [_, codeActions] = arg.arguments;
|
|
936
974
|
for (const codeAction of codeActions) {
|
|
937
975
|
yield this.applyFileCodeEdits(codeAction.changes);
|
|
938
976
|
if (codeAction.commands && codeAction.commands.length) {
|
|
939
977
|
for (const command of codeAction.commands) {
|
|
940
|
-
yield this.tspClient.request("applyCodeActionCommand" /* ApplyCodeActionCommand */, { command });
|
|
978
|
+
yield this.tspClient.request("applyCodeActionCommand" /* CommandTypes.ApplyCodeActionCommand */, { command });
|
|
941
979
|
}
|
|
942
980
|
}
|
|
943
981
|
// Execute only the first code action.
|
|
@@ -956,7 +994,7 @@ class LspServer {
|
|
|
956
994
|
}
|
|
957
995
|
const changes = {};
|
|
958
996
|
for (const edit of edits) {
|
|
959
|
-
changes[
|
|
997
|
+
changes[pathToUri(edit.fileName, this.documents)] = edit.textChanges.map(toTextEdit);
|
|
960
998
|
}
|
|
961
999
|
const { applied } = yield this.options.lspClient.applyWorkspaceEdit({
|
|
962
1000
|
edit: { changes }
|
|
@@ -972,13 +1010,13 @@ class LspServer {
|
|
|
972
1010
|
}
|
|
973
1011
|
getEditsForFileRename(sourceUri, targetUri) {
|
|
974
1012
|
return __awaiter(this, void 0, void 0, function* () {
|
|
975
|
-
const newFilePath =
|
|
976
|
-
const oldFilePath =
|
|
1013
|
+
const newFilePath = uriToPath(targetUri);
|
|
1014
|
+
const oldFilePath = uriToPath(sourceUri);
|
|
977
1015
|
if (!newFilePath || !oldFilePath) {
|
|
978
1016
|
return [];
|
|
979
1017
|
}
|
|
980
1018
|
try {
|
|
981
|
-
const { body } = yield this.tspClient.request("getEditsForFileRename" /* GetEditsForFileRename */, {
|
|
1019
|
+
const { body } = yield this.tspClient.request("getEditsForFileRename" /* CommandTypes.GetEditsForFileRename */, {
|
|
982
1020
|
oldFilePath,
|
|
983
1021
|
newFilePath
|
|
984
1022
|
});
|
|
@@ -991,14 +1029,14 @@ class LspServer {
|
|
|
991
1029
|
}
|
|
992
1030
|
documentHighlight(arg) {
|
|
993
1031
|
return __awaiter(this, void 0, void 0, function* () {
|
|
994
|
-
const file =
|
|
1032
|
+
const file = uriToPath(arg.textDocument.uri);
|
|
995
1033
|
this.logger.log('documentHighlight', arg, file);
|
|
996
1034
|
if (!file) {
|
|
997
1035
|
return [];
|
|
998
1036
|
}
|
|
999
1037
|
let response;
|
|
1000
1038
|
try {
|
|
1001
|
-
response = yield this.tspClient.request("documentHighlights" /* DocumentHighlights */, {
|
|
1039
|
+
response = yield this.tspClient.request("documentHighlights" /* CommandTypes.DocumentHighlights */, {
|
|
1002
1040
|
file,
|
|
1003
1041
|
line: arg.position.line + 1,
|
|
1004
1042
|
offset: arg.position.character + 1,
|
|
@@ -1015,8 +1053,8 @@ class LspServer {
|
|
|
1015
1053
|
for (const item of response.body) {
|
|
1016
1054
|
// tsp returns item.file with POSIX path delimiters, whereas file is platform specific.
|
|
1017
1055
|
// Converting to a URI and back to a path ensures consistency.
|
|
1018
|
-
if (
|
|
1019
|
-
const highlights =
|
|
1056
|
+
if (normalizePath(item.file) === file) {
|
|
1057
|
+
const highlights = toDocumentHighlight(item);
|
|
1020
1058
|
result.push(...highlights);
|
|
1021
1059
|
}
|
|
1022
1060
|
}
|
|
@@ -1028,7 +1066,7 @@ class LspServer {
|
|
|
1028
1066
|
}
|
|
1029
1067
|
workspaceSymbol(params) {
|
|
1030
1068
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1031
|
-
const result = yield this.tspClient.request("navto" /* Navto */, {
|
|
1069
|
+
const result = yield this.tspClient.request("navto" /* CommandTypes.Navto */, {
|
|
1032
1070
|
file: this.lastFileOrDummy(),
|
|
1033
1071
|
searchValue: params.query
|
|
1034
1072
|
});
|
|
@@ -1038,13 +1076,13 @@ class LspServer {
|
|
|
1038
1076
|
return result.body.map(item => {
|
|
1039
1077
|
return {
|
|
1040
1078
|
location: {
|
|
1041
|
-
uri:
|
|
1079
|
+
uri: pathToUri(item.file, this.documents),
|
|
1042
1080
|
range: {
|
|
1043
|
-
start:
|
|
1044
|
-
end:
|
|
1081
|
+
start: toPosition(item.start),
|
|
1082
|
+
end: toPosition(item.end)
|
|
1045
1083
|
}
|
|
1046
1084
|
},
|
|
1047
|
-
kind:
|
|
1085
|
+
kind: toSymbolKind(item.kind),
|
|
1048
1086
|
name: item.name
|
|
1049
1087
|
};
|
|
1050
1088
|
});
|
|
@@ -1055,7 +1093,7 @@ class LspServer {
|
|
|
1055
1093
|
*/
|
|
1056
1094
|
foldingRanges(params) {
|
|
1057
1095
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1058
|
-
const file =
|
|
1096
|
+
const file = uriToPath(params.textDocument.uri);
|
|
1059
1097
|
this.logger.log('foldingRanges', params, file);
|
|
1060
1098
|
if (!file) {
|
|
1061
1099
|
return undefined;
|
|
@@ -1064,7 +1102,7 @@ class LspServer {
|
|
|
1064
1102
|
if (!document) {
|
|
1065
1103
|
throw new Error("The document should be opened for foldingRanges', file: " + file);
|
|
1066
1104
|
}
|
|
1067
|
-
const { body } = yield this.tspClient.request("getOutliningSpans" /* GetOutliningSpans */, { file });
|
|
1105
|
+
const { body } = yield this.tspClient.request("getOutliningSpans" /* CommandTypes.GetOutliningSpans */, { file });
|
|
1068
1106
|
if (!body) {
|
|
1069
1107
|
return undefined;
|
|
1070
1108
|
}
|
|
@@ -1079,7 +1117,7 @@ class LspServer {
|
|
|
1079
1117
|
});
|
|
1080
1118
|
}
|
|
1081
1119
|
asFoldingRange(span, document) {
|
|
1082
|
-
const range =
|
|
1120
|
+
const range = asRange(span.textSpan);
|
|
1083
1121
|
const kind = this.asFoldingRangeKind(span);
|
|
1084
1122
|
// workaround for https://github.com/Microsoft/vscode/issues/49904
|
|
1085
1123
|
if (span.kind === 'comment') {
|
|
@@ -1108,15 +1146,15 @@ class LspServer {
|
|
|
1108
1146
|
}
|
|
1109
1147
|
onTsEvent(event) {
|
|
1110
1148
|
var _a;
|
|
1111
|
-
if (event.event === "semanticDiag" /* SementicDiag */ ||
|
|
1112
|
-
event.event === "syntaxDiag" /* SyntaxDiag */ ||
|
|
1113
|
-
event.event === "suggestionDiag" /* SuggestionDiag */) {
|
|
1149
|
+
if (event.event === "semanticDiag" /* EventTypes.SementicDiag */ ||
|
|
1150
|
+
event.event === "syntaxDiag" /* EventTypes.SyntaxDiag */ ||
|
|
1151
|
+
event.event === "suggestionDiag" /* EventTypes.SuggestionDiag */) {
|
|
1114
1152
|
(_a = this.diagnosticQueue) === null || _a === void 0 ? void 0 : _a.updateDiagnostics(event.event, event);
|
|
1115
1153
|
}
|
|
1116
|
-
else if (event.event === "projectLoadingStart" /* ProjectLoadingStart */) {
|
|
1154
|
+
else if (event.event === "projectLoadingStart" /* EventTypes.ProjectLoadingStart */) {
|
|
1117
1155
|
this.loadingIndicator.startedLoadingProject(event.body.projectName);
|
|
1118
1156
|
}
|
|
1119
|
-
else if (event.event === "projectLoadingFinish" /* ProjectLoadingFinish */) {
|
|
1157
|
+
else if (event.event === "projectLoadingFinish" /* EventTypes.ProjectLoadingFinish */) {
|
|
1120
1158
|
this.loadingIndicator.finishedLoadingProject(event.body.projectName);
|
|
1121
1159
|
}
|
|
1122
1160
|
else {
|
|
@@ -1128,17 +1166,17 @@ class LspServer {
|
|
|
1128
1166
|
calls(params) {
|
|
1129
1167
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1130
1168
|
let callsResult = { calls: [] };
|
|
1131
|
-
const file =
|
|
1169
|
+
const file = uriToPath(params.textDocument.uri);
|
|
1132
1170
|
this.logger.log('calls', params, file);
|
|
1133
1171
|
if (!file) {
|
|
1134
1172
|
return callsResult;
|
|
1135
1173
|
}
|
|
1136
1174
|
if (params.direction === lspcalls.CallDirection.Outgoing) {
|
|
1137
1175
|
const documentProvider = (file) => this.documents.get(file);
|
|
1138
|
-
callsResult = yield
|
|
1176
|
+
callsResult = yield computeCallees(this.tspClient, params, documentProvider);
|
|
1139
1177
|
}
|
|
1140
1178
|
else {
|
|
1141
|
-
callsResult = yield
|
|
1179
|
+
callsResult = yield computeCallers(this.tspClient, params);
|
|
1142
1180
|
}
|
|
1143
1181
|
return callsResult;
|
|
1144
1182
|
});
|
|
@@ -1146,12 +1184,12 @@ class LspServer {
|
|
|
1146
1184
|
inlayHints(params) {
|
|
1147
1185
|
var _a, _b, _c, _d, _e, _f;
|
|
1148
1186
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1149
|
-
const file =
|
|
1187
|
+
const file = uriToPath(params.textDocument.uri);
|
|
1150
1188
|
this.logger.log('inlayHints', params, file);
|
|
1151
1189
|
if (!file) {
|
|
1152
1190
|
return { inlayHints: [] };
|
|
1153
1191
|
}
|
|
1154
|
-
yield this.tspClient.request("configure" /* Configure */, {
|
|
1192
|
+
yield this.tspClient.request("configure" /* CommandTypes.Configure */, {
|
|
1155
1193
|
preferences: this.getInlayHintsOptions(file)
|
|
1156
1194
|
});
|
|
1157
1195
|
const doc = this.documents.get(file);
|
|
@@ -1167,7 +1205,7 @@ class LspServer {
|
|
|
1167
1205
|
character: 0
|
|
1168
1206
|
});
|
|
1169
1207
|
try {
|
|
1170
|
-
const result = yield this.tspClient.request("provideInlayHints" /* ProvideInlayHints */, {
|
|
1208
|
+
const result = yield this.tspClient.request("provideInlayHints" /* CommandTypes.ProvideInlayHints */, {
|
|
1171
1209
|
file,
|
|
1172
1210
|
start: start,
|
|
1173
1211
|
length: end - start
|
|
@@ -1175,7 +1213,7 @@ class LspServer {
|
|
|
1175
1213
|
return {
|
|
1176
1214
|
inlayHints: (_f = (_e = result.body) === null || _e === void 0 ? void 0 : _e.map((item) => ({
|
|
1177
1215
|
text: item.text,
|
|
1178
|
-
position:
|
|
1216
|
+
position: toPosition(item.position),
|
|
1179
1217
|
whitespaceAfter: item.whitespaceAfter,
|
|
1180
1218
|
whitespaceBefore: item.whitespaceBefore,
|
|
1181
1219
|
kind: item.kind
|
|
@@ -1197,7 +1235,7 @@ class LspServer {
|
|
|
1197
1235
|
}
|
|
1198
1236
|
semanticTokensFull(params) {
|
|
1199
1237
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1200
|
-
const file =
|
|
1238
|
+
const file = uriToPath(params.textDocument.uri);
|
|
1201
1239
|
this.logger.log('semanticTokensFull', params, file);
|
|
1202
1240
|
if (!file) {
|
|
1203
1241
|
return { data: [] };
|
|
@@ -1219,7 +1257,7 @@ class LspServer {
|
|
|
1219
1257
|
}
|
|
1220
1258
|
semanticTokensRange(params) {
|
|
1221
1259
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1222
|
-
const file =
|
|
1260
|
+
const file = uriToPath(params.textDocument.uri);
|
|
1223
1261
|
this.logger.log('semanticTokensRange', params, file);
|
|
1224
1262
|
if (!file) {
|
|
1225
1263
|
return { data: [] };
|
|
@@ -1237,7 +1275,7 @@ class LspServer {
|
|
|
1237
1275
|
var _a, _b;
|
|
1238
1276
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1239
1277
|
try {
|
|
1240
|
-
const result = yield this.tspClient.request("encodedSemanticClassifications-full" /* EncodedSemanticClassificationsFull */, {
|
|
1278
|
+
const result = yield this.tspClient.request("encodedSemanticClassifications-full" /* CommandTypes.EncodedSemanticClassificationsFull */, {
|
|
1241
1279
|
file,
|
|
1242
1280
|
start: startOffset,
|
|
1243
1281
|
length: endOffset - startOffset,
|
|
@@ -1252,5 +1290,4 @@ class LspServer {
|
|
|
1252
1290
|
});
|
|
1253
1291
|
}
|
|
1254
1292
|
}
|
|
1255
|
-
exports.LspServer = LspServer;
|
|
1256
1293
|
//# sourceMappingURL=lsp-server.js.map
|