typescript-language-server 0.11.0 → 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.
Files changed (132) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +32 -6
  3. package/lib/calls.d.ts +3 -3
  4. package/lib/calls.d.ts.map +1 -1
  5. package/lib/calls.js +18 -46
  6. package/lib/calls.js.map +1 -1
  7. package/lib/cli.js +8 -32
  8. package/lib/cli.js.map +1 -1
  9. package/lib/commands.js +1 -4
  10. package/lib/commands.js.map +1 -1
  11. package/lib/completion.d.ts +7 -6
  12. package/lib/completion.d.ts.map +1 -1
  13. package/lib/completion.js +95 -115
  14. package/lib/completion.js.map +1 -1
  15. package/lib/diagnostic-queue.d.ts +5 -5
  16. package/lib/diagnostic-queue.d.ts.map +1 -1
  17. package/lib/diagnostic-queue.js +7 -14
  18. package/lib/diagnostic-queue.js.map +1 -1
  19. package/lib/document-symbol.d.ts +2 -2
  20. package/lib/document-symbol.d.ts.map +1 -1
  21. package/lib/document-symbol.js +16 -22
  22. package/lib/document-symbol.js.map +1 -1
  23. package/lib/document.d.ts +1 -1
  24. package/lib/document.d.ts.map +1 -1
  25. package/lib/document.js +6 -34
  26. package/lib/document.js.map +1 -1
  27. package/lib/features/fix-all.d.ts +4 -4
  28. package/lib/features/fix-all.d.ts.map +1 -1
  29. package/lib/features/fix-all.js +17 -44
  30. package/lib/features/fix-all.js.map +1 -1
  31. package/lib/file-lsp-server.spec.js +17 -18
  32. package/lib/file-lsp-server.spec.js.map +1 -1
  33. package/lib/hover.d.ts +2 -2
  34. package/lib/hover.d.ts.map +1 -1
  35. package/lib/hover.js +8 -12
  36. package/lib/hover.js.map +1 -1
  37. package/lib/logger.d.ts +12 -4
  38. package/lib/logger.d.ts.map +1 -1
  39. package/lib/logger.js +36 -43
  40. package/lib/logger.js.map +1 -1
  41. package/lib/lsp-client.d.ts +3 -3
  42. package/lib/lsp-client.d.ts.map +1 -1
  43. package/lib/lsp-client.js +4 -31
  44. package/lib/lsp-client.js.map +1 -1
  45. package/lib/lsp-connection.d.ts +1 -1
  46. package/lib/lsp-connection.d.ts.map +1 -1
  47. package/lib/lsp-connection.js +10 -37
  48. package/lib/lsp-connection.js.map +1 -1
  49. package/lib/lsp-protocol.calls.proposed.d.ts +1 -1
  50. package/lib/lsp-protocol.calls.proposed.d.ts.map +1 -1
  51. package/lib/lsp-protocol.calls.proposed.js +7 -32
  52. package/lib/lsp-protocol.calls.proposed.js.map +1 -1
  53. package/lib/lsp-protocol.inlayHints.proposed.d.ts +2 -2
  54. package/lib/lsp-protocol.inlayHints.proposed.d.ts.map +1 -1
  55. package/lib/lsp-protocol.inlayHints.proposed.js +2 -28
  56. package/lib/lsp-protocol.inlayHints.proposed.js.map +1 -1
  57. package/lib/lsp-server.d.ts +13 -9
  58. package/lib/lsp-server.d.ts.map +1 -1
  59. package/lib/lsp-server.js +234 -192
  60. package/lib/lsp-server.js.map +1 -1
  61. package/lib/lsp-server.spec.js +338 -232
  62. package/lib/lsp-server.spec.js.map +1 -1
  63. package/lib/organize-imports.d.ts +3 -3
  64. package/lib/organize-imports.d.ts.map +1 -1
  65. package/lib/organize-imports.js +5 -32
  66. package/lib/organize-imports.js.map +1 -1
  67. package/lib/organize-imports.spec.js +9 -34
  68. package/lib/organize-imports.spec.js.map +1 -1
  69. package/lib/protocol-translation.d.ts +3 -3
  70. package/lib/protocol-translation.d.ts.map +1 -1
  71. package/lib/protocol-translation.js +30 -72
  72. package/lib/protocol-translation.js.map +1 -1
  73. package/lib/quickfix.d.ts +3 -3
  74. package/lib/quickfix.d.ts.map +1 -1
  75. package/lib/quickfix.js +7 -35
  76. package/lib/quickfix.js.map +1 -1
  77. package/lib/refactor.d.ts +2 -2
  78. package/lib/refactor.d.ts.map +1 -1
  79. package/lib/refactor.js +7 -36
  80. package/lib/refactor.js.map +1 -1
  81. package/lib/semantic-tokens.d.ts +1 -1
  82. package/lib/semantic-tokens.d.ts.map +1 -1
  83. package/lib/semantic-tokens.js +1 -5
  84. package/lib/semantic-tokens.js.map +1 -1
  85. package/lib/test-utils.d.ts +8 -3
  86. package/lib/test-utils.d.ts.map +1 -1
  87. package/lib/test-utils.js +51 -60
  88. package/lib/test-utils.js.map +1 -1
  89. package/lib/ts-protocol.d.ts +7 -4
  90. package/lib/ts-protocol.d.ts.map +1 -1
  91. package/lib/ts-protocol.js +4 -31
  92. package/lib/ts-protocol.js.map +1 -1
  93. package/lib/tsp-client.d.ts +42 -43
  94. package/lib/tsp-client.d.ts.map +1 -1
  95. package/lib/tsp-client.js +23 -46
  96. package/lib/tsp-client.js.map +1 -1
  97. package/lib/tsp-client.spec.js +36 -56
  98. package/lib/tsp-client.spec.js.map +1 -1
  99. package/lib/tsp-command-types.js +3 -7
  100. package/lib/tsp-command-types.js.map +1 -1
  101. package/lib/utils/SnippetString.js +1 -4
  102. package/lib/utils/SnippetString.js.map +1 -1
  103. package/lib/utils/api.d.ts +1 -0
  104. package/lib/utils/api.d.ts.map +1 -1
  105. package/lib/utils/api.js +3 -28
  106. package/lib/utils/api.js.map +1 -1
  107. package/lib/utils/configuration.d.ts +2 -2
  108. package/lib/utils/configuration.d.ts.map +1 -1
  109. package/lib/utils/configuration.js +1 -2
  110. package/lib/utils/errorCodes.js +11 -14
  111. package/lib/utils/errorCodes.js.map +1 -1
  112. package/lib/utils/fixNames.js +13 -16
  113. package/lib/utils/fixNames.js.map +1 -1
  114. package/lib/utils/modules-resolver.js +7 -34
  115. package/lib/utils/modules-resolver.js.map +1 -1
  116. package/lib/utils/modules-resolver.spec.d.ts +1 -1
  117. package/lib/utils/modules-resolver.spec.d.ts.map +1 -1
  118. package/lib/utils/modules-resolver.spec.js +11 -34
  119. package/lib/utils/modules-resolver.spec.js.map +1 -1
  120. package/lib/utils/typeConverters.d.ts +1 -1
  121. package/lib/utils/typeConverters.d.ts.map +1 -1
  122. package/lib/utils/typeConverters.js +2 -5
  123. package/lib/utils/typeConverters.js.map +1 -1
  124. package/lib/utils/types.js +2 -29
  125. package/lib/utils/types.js.map +1 -1
  126. package/lib/utils/versionProvider.d.ts +3 -3
  127. package/lib/utils/versionProvider.d.ts.map +1 -1
  128. package/lib/utils/versionProvider.js +35 -41
  129. package/lib/utils/versionProvider.js.map +1 -1
  130. package/lib/utils.js +1 -5
  131. package/lib/utils.js.map +1 -1
  132. 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
- var __importDefault = (this && this.__importDefault) || function (mod) {
41
- return (mod && mod.__esModule) ? mod : { "default": mod };
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.documents = new document_1.LspDocuments();
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 = (0, p_debounce_1.default)(() => this.doRequestDiagnostics(), 200);
107
- this.logger = new logger_1.PrefixingLogger(options.logger, '[lspserver]');
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 versionProvider_1.TypeScriptVersionProvider(this.options, this.logger);
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.loadingIndicator = new ServerInitializingIndicator(this.options.lspClient);
147
- this.workspaceRoot = this.initializeParams.rootUri ? (0, protocol_translation_1.uriToPath)(this.initializeParams.rootUri) : this.initializeParams.rootPath || undefined;
148
- this.diagnosticQueue = new diagnostic_queue_1.DiagnosticEventQueue(diagnostics => this.options.lspClient.publishDiagnostics(diagnostics), this.documents, (_a = clientCapabilities.textDocument) === null || _a === void 0 ? void 0 : _a.publishDiagnostics, this.logger);
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, preferences } = {
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
- this.tspClient = new tsp_client_1.TspClient({
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
- this.logger.error(`tsserver process has exited (exit code: ${exitCode}, signal: ${signal}). Stopping the server.`);
184
- // Allow the log to be dispatched to the client.
185
- setTimeout(() => process.exit(1));
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.tspClient.shutdown();
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 fix_all_1.TypeScriptAutoFixProvider(this.tspClient);
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 && (0, protocol_translation_1.pathToUri)(logFile, undefined);
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: ((_c = (_b = clientCapabilities.textDocument) === null || _b === void 0 ? void 0 : _b.codeAction) === null || _c === void 0 ? void 0 : _c.codeActionLiteralSupport)
227
- ? { codeActionKinds: [...fix_all_1.TypeScriptAutoFixProvider.kinds.map(kind => kind.value), types_1.CodeActionKind.SourceOrganizeImportsTs.value] } : true,
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
- commands_1.Commands.APPLY_WORKSPACE_EDIT,
236
- commands_1.Commands.APPLY_CODE_ACTION,
237
- commands_1.Commands.APPLY_REFACTORING,
238
- commands_1.Commands.ORGANIZE_IMPORTS,
239
- commands_1.Commands.APPLY_RENAME_FILE
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 tempy_1.default.file({ name: 'tsserver.log' });
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 = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
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 = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
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 = (0, protocol_translation_1.uriToPath)(textDocument.uri);
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 = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
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 => (0, protocol_translation_1.toLocation)(fileSpan, this.documents)) : [];
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 = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
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
- (0, document_symbol_1.collectDocumentSymbols)(item, symbols);
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
- (0, document_symbol_1.collectSymbolInformation)(params.textDocument.uri, item, symbols);
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 = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
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([]);
@@ -557,15 +595,20 @@ class LspServer {
557
595
  throw new Error('The document should be opened for completion, file: ' + file);
558
596
  }
559
597
  try {
560
- const result = yield this.interuptDiagnostics(() => this.tspClient.request("completionInfo" /* CompletionInfo */, {
561
- file,
562
- line: params.position.line + 1,
563
- offset: params.position.character + 1
564
- }));
598
+ const result = yield this.interuptDiagnostics(() => {
599
+ var _a, _b;
600
+ return this.tspClient.request("completionInfo" /* CommandTypes.CompletionInfo */, {
601
+ file,
602
+ line: params.position.line + 1,
603
+ offset: params.position.character + 1,
604
+ triggerCharacter: getCompletionTriggerCharacter((_a = params.context) === null || _a === void 0 ? void 0 : _a.triggerCharacter),
605
+ triggerKind: (_b = params.context) === null || _b === void 0 ? void 0 : _b.triggerKind
606
+ });
607
+ });
565
608
  const { body } = result;
566
609
  const completions = (body ? body.entries : [])
567
610
  .filter(entry => entry.kind !== 'warning')
568
- .map(entry => (0, completion_1.asCompletionItem)(entry, file, params.position, document));
611
+ .map(entry => asCompletionItem(entry, file, params.position, document, this.features));
569
612
  return lsp.CompletionList.create(completions, body === null || body === void 0 ? void 0 : body.isIncomplete);
570
613
  }
571
614
  catch (error) {
@@ -582,20 +625,20 @@ class LspServer {
582
625
  completionResolve(item) {
583
626
  return __awaiter(this, void 0, void 0, function* () {
584
627
  this.logger.log('completion/resolve', item);
585
- yield this.tspClient.request("configure" /* Configure */, {
628
+ yield this.tspClient.request("configure" /* CommandTypes.Configure */, {
586
629
  formatOptions: this.getWorkspacePreferencesForDocument(item.data.file).format
587
630
  });
588
- 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));
589
632
  const details = body && body.length && body[0];
590
633
  if (!details) {
591
634
  return item;
592
635
  }
593
- return (0, completion_1.asResolvedCompletionItem)(item, details, this.tspClient, this.workspaceConfiguration.completions || {});
636
+ return asResolvedCompletionItem(item, details, this.tspClient, this.workspaceConfiguration.completions || {});
594
637
  });
595
638
  }
596
639
  hover(params) {
597
640
  return __awaiter(this, void 0, void 0, function* () {
598
- const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
641
+ const file = uriToPath(params.textDocument.uri);
599
642
  this.logger.log('hover', params, file);
600
643
  if (!file) {
601
644
  return { contents: [] };
@@ -604,13 +647,13 @@ class LspServer {
604
647
  if (!result || !result.body) {
605
648
  return { contents: [] };
606
649
  }
607
- const range = (0, protocol_translation_1.asRange)(result.body);
650
+ const range = asRange(result.body);
608
651
  const contents = [];
609
652
  if (result.body.displayString) {
610
653
  contents.push({ language: 'typescript', value: result.body.displayString });
611
654
  }
612
- const tags = (0, protocol_translation_1.asTagsDocumentation)(result.body.tags);
613
- const documentation = (0, protocol_translation_1.asPlainText)(result.body.documentation);
655
+ const tags = asTagsDocumentation(result.body.tags);
656
+ const documentation = asPlainText(result.body.documentation);
614
657
  contents.push(documentation + (tags ? '\n\n' + tags : ''));
615
658
  return {
616
659
  contents,
@@ -621,7 +664,7 @@ class LspServer {
621
664
  getQuickInfo(file, position) {
622
665
  return __awaiter(this, void 0, void 0, function* () {
623
666
  try {
624
- return yield this.tspClient.request("quickinfo" /* Quickinfo */, {
667
+ return yield this.tspClient.request("quickinfo" /* CommandTypes.Quickinfo */, {
625
668
  file,
626
669
  line: position.line + 1,
627
670
  offset: position.character + 1
@@ -634,12 +677,12 @@ class LspServer {
634
677
  }
635
678
  rename(params) {
636
679
  return __awaiter(this, void 0, void 0, function* () {
637
- const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
680
+ const file = uriToPath(params.textDocument.uri);
638
681
  this.logger.log('onRename', params, file);
639
682
  if (!file) {
640
683
  return undefined;
641
684
  }
642
- const result = yield this.tspClient.request("rename" /* Rename */, {
685
+ const result = yield this.tspClient.request("rename" /* CommandTypes.Rename */, {
643
686
  file,
644
687
  line: params.position.line + 1,
645
688
  offset: params.position.character + 1
@@ -652,13 +695,13 @@ class LspServer {
652
695
  };
653
696
  result.body.locs
654
697
  .forEach((spanGroup) => {
655
- const uri = (0, protocol_translation_1.pathToUri)(spanGroup.file, this.documents), textEdits = workspaceEdit.changes[uri] || (workspaceEdit.changes[uri] = []);
698
+ const uri = pathToUri(spanGroup.file, this.documents), textEdits = workspaceEdit.changes[uri] || (workspaceEdit.changes[uri] = []);
656
699
  spanGroup.locs.forEach((textSpan) => {
657
700
  textEdits.push({
658
701
  newText: `${textSpan.prefixText || ''}${params.newName}${textSpan.suffixText || ''}`,
659
702
  range: {
660
- start: (0, protocol_translation_1.toPosition)(textSpan.start),
661
- end: (0, protocol_translation_1.toPosition)(textSpan.end)
703
+ start: toPosition(textSpan.start),
704
+ end: toPosition(textSpan.end)
662
705
  }
663
706
  });
664
707
  });
@@ -668,12 +711,12 @@ class LspServer {
668
711
  }
669
712
  references(params) {
670
713
  return __awaiter(this, void 0, void 0, function* () {
671
- const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
714
+ const file = uriToPath(params.textDocument.uri);
672
715
  this.logger.log('onReferences', params, file);
673
716
  if (!file) {
674
717
  return [];
675
718
  }
676
- const result = yield this.tspClient.request("references" /* References */, {
719
+ const result = yield this.tspClient.request("references" /* CommandTypes.References */, {
677
720
  file,
678
721
  line: params.position.line + 1,
679
722
  offset: params.position.character + 1
@@ -683,22 +726,22 @@ class LspServer {
683
726
  }
684
727
  return result.body.refs
685
728
  .filter(fileSpan => params.context.includeDeclaration || !fileSpan.isDefinition)
686
- .map(fileSpan => (0, protocol_translation_1.toLocation)(fileSpan, this.documents));
729
+ .map(fileSpan => toLocation(fileSpan, this.documents));
687
730
  });
688
731
  }
689
732
  documentFormatting(params) {
690
733
  return __awaiter(this, void 0, void 0, function* () {
691
- const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
734
+ const file = uriToPath(params.textDocument.uri);
692
735
  this.logger.log('documentFormatting', params, file);
693
736
  if (!file) {
694
737
  return [];
695
738
  }
696
739
  const formatOptions = this.getFormattingOptions(file, params.options);
697
740
  // options are not yet supported in tsserver, but we can send a configure request first
698
- yield this.tspClient.request("configure" /* Configure */, {
741
+ yield this.tspClient.request("configure" /* CommandTypes.Configure */, {
699
742
  formatOptions
700
743
  });
701
- const response = yield this.tspClient.request("format" /* Format */, {
744
+ const response = yield this.tspClient.request("format" /* CommandTypes.Format */, {
702
745
  file,
703
746
  line: 1,
704
747
  offset: 1,
@@ -707,24 +750,24 @@ class LspServer {
707
750
  options: formatOptions
708
751
  });
709
752
  if (response.body) {
710
- return response.body.map(e => (0, protocol_translation_1.toTextEdit)(e));
753
+ return response.body.map(e => toTextEdit(e));
711
754
  }
712
755
  return [];
713
756
  });
714
757
  }
715
758
  documentRangeFormatting(params) {
716
759
  return __awaiter(this, void 0, void 0, function* () {
717
- const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
760
+ const file = uriToPath(params.textDocument.uri);
718
761
  this.logger.log('documentRangeFormatting', params, file);
719
762
  if (!file) {
720
763
  return [];
721
764
  }
722
765
  const formatOptions = this.getFormattingOptions(file, params.options);
723
766
  // options are not yet supported in tsserver, but we can send a configure request first
724
- yield this.tspClient.request("configure" /* Configure */, {
767
+ yield this.tspClient.request("configure" /* CommandTypes.Configure */, {
725
768
  formatOptions
726
769
  });
727
- const response = yield this.tspClient.request("format" /* Format */, {
770
+ const response = yield this.tspClient.request("format" /* CommandTypes.Format */, {
728
771
  file,
729
772
  line: params.range.start.line + 1,
730
773
  offset: params.range.start.character + 1,
@@ -733,7 +776,7 @@ class LspServer {
733
776
  options: formatOptions
734
777
  });
735
778
  if (response.body) {
736
- return response.body.map(e => (0, protocol_translation_1.toTextEdit)(e));
779
+ return response.body.map(e => toTextEdit(e));
737
780
  }
738
781
  return [];
739
782
  });
@@ -760,7 +803,7 @@ class LspServer {
760
803
  }
761
804
  signatureHelp(params) {
762
805
  return __awaiter(this, void 0, void 0, function* () {
763
- const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
806
+ const file = uriToPath(params.textDocument.uri);
764
807
  this.logger.log('signatureHelp', params, file);
765
808
  if (!file) {
766
809
  return undefined;
@@ -769,13 +812,13 @@ class LspServer {
769
812
  if (!response || !response.body) {
770
813
  return undefined;
771
814
  }
772
- return (0, hover_1.asSignatureHelp)(response.body);
815
+ return asSignatureHelp(response.body);
773
816
  });
774
817
  }
775
818
  getSignatureHelp(file, position) {
776
819
  return __awaiter(this, void 0, void 0, function* () {
777
820
  try {
778
- return yield this.tspClient.request("signatureHelp" /* SignatureHelp */, {
821
+ return yield this.tspClient.request("signatureHelp" /* CommandTypes.SignatureHelp */, {
779
822
  file,
780
823
  line: position.line + 1,
781
824
  offset: position.character + 1
@@ -789,23 +832,23 @@ class LspServer {
789
832
  codeAction(params) {
790
833
  var _a, _b;
791
834
  return __awaiter(this, void 0, void 0, function* () {
792
- const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
835
+ const file = uriToPath(params.textDocument.uri);
793
836
  this.logger.log('codeAction', params, file);
794
837
  if (!file) {
795
838
  return [];
796
839
  }
797
- const args = (0, protocol_translation_1.toFileRangeRequestArgs)(file, params.range);
840
+ const args = toFileRangeRequestArgs(file, params.range);
798
841
  const actions = [];
799
- const kinds = (_a = params.context.only) === null || _a === void 0 ? void 0 : _a.map(kind => new types_1.CodeActionKind(kind));
800
- if (!kinds || kinds.some(kind => kind.contains(types_1.CodeActionKind.QuickFix))) {
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))) {
801
844
  const errorCodes = params.context.diagnostics.map(diagnostic => Number(diagnostic.code));
802
- actions.push(...(0, quickfix_1.provideQuickFix)(yield this.getCodeFixes(Object.assign(Object.assign({}, args), { errorCodes })), this.documents));
845
+ actions.push(...provideQuickFix(yield this.getCodeFixes(Object.assign(Object.assign({}, args), { errorCodes })), this.documents));
803
846
  }
804
- if (!kinds || kinds.some(kind => kind.contains(types_1.CodeActionKind.Refactor))) {
805
- actions.push(...(0, refactor_1.provideRefactors)(yield this.getRefactors(args), args));
847
+ if (!kinds || kinds.some(kind => kind.contains(CodeActionKind.Refactor))) {
848
+ actions.push(...provideRefactors(yield this.getRefactors(args), args));
806
849
  }
807
850
  // organize import is provided by tsserver for any line, so we only get it if explicitly requested
808
- if (kinds === null || kinds === void 0 ? void 0 : kinds.some(kind => kind.contains(types_1.CodeActionKind.SourceOrganizeImportsTs))) {
851
+ if (kinds === null || kinds === void 0 ? void 0 : kinds.some(kind => kind.contains(CodeActionKind.SourceOrganizeImportsTs))) {
809
852
  // see this issue for more context about how this argument is used
810
853
  // https://github.com/microsoft/TypeScript/issues/43051
811
854
  const skipDestructiveCodeActions = params.context.diagnostics.some(
@@ -815,7 +858,7 @@ class LspServer {
815
858
  scope: { type: 'file', args },
816
859
  skipDestructiveCodeActions
817
860
  });
818
- actions.push(...(0, organize_imports_1.provideOrganizeImports)(response, this.documents));
861
+ actions.push(...provideOrganizeImports(response, this.documents));
819
862
  }
820
863
  // TODO: Since we rely on diagnostics pointing at errors in the correct places, we can't proceed if we are not
821
864
  // sure that diagnostics are up-to-date. Thus we check `pendingDebouncedRequest` to see if there are *any*
@@ -834,7 +877,7 @@ class LspServer {
834
877
  getCodeFixes(args) {
835
878
  return __awaiter(this, void 0, void 0, function* () {
836
879
  try {
837
- return yield this.tspClient.request("getCodeFixes" /* GetCodeFixes */, args);
880
+ return yield this.tspClient.request("getCodeFixes" /* CommandTypes.GetCodeFixes */, args);
838
881
  }
839
882
  catch (err) {
840
883
  return undefined;
@@ -844,7 +887,7 @@ class LspServer {
844
887
  getRefactors(args) {
845
888
  return __awaiter(this, void 0, void 0, function* () {
846
889
  try {
847
- return yield this.tspClient.request("getApplicableRefactors" /* GetApplicableRefactors */, args);
890
+ return yield this.tspClient.request("getApplicableRefactors" /* CommandTypes.GetApplicableRefactors */, args);
848
891
  }
849
892
  catch (err) {
850
893
  return undefined;
@@ -855,10 +898,10 @@ class LspServer {
855
898
  return __awaiter(this, void 0, void 0, function* () {
856
899
  try {
857
900
  // Pass format options to organize imports
858
- yield this.tspClient.request("configure" /* Configure */, {
901
+ yield this.tspClient.request("configure" /* CommandTypes.Configure */, {
859
902
  formatOptions: this.getWorkspacePreferencesForDocument(args.scope.args.file).format
860
903
  });
861
- return yield this.tspClient.request("organizeImports" /* OrganizeImports */, args);
904
+ return yield this.tspClient.request("organizeImports" /* CommandTypes.OrganizeImports */, args);
862
905
  }
863
906
  catch (err) {
864
907
  return undefined;
@@ -868,26 +911,26 @@ class LspServer {
868
911
  executeCommand(arg) {
869
912
  return __awaiter(this, void 0, void 0, function* () {
870
913
  this.logger.log('executeCommand', arg);
871
- if (arg.command === commands_1.Commands.APPLY_WORKSPACE_EDIT && arg.arguments) {
914
+ if (arg.command === Commands.APPLY_WORKSPACE_EDIT && arg.arguments) {
872
915
  const edit = arg.arguments[0];
873
916
  yield this.options.lspClient.applyWorkspaceEdit({
874
917
  edit
875
918
  });
876
919
  }
877
- else if (arg.command === commands_1.Commands.APPLY_CODE_ACTION && arg.arguments) {
920
+ else if (arg.command === Commands.APPLY_CODE_ACTION && arg.arguments) {
878
921
  const codeAction = arg.arguments[0];
879
922
  if (!(yield this.applyFileCodeEdits(codeAction.changes))) {
880
923
  return;
881
924
  }
882
925
  if (codeAction.commands && codeAction.commands.length) {
883
926
  for (const command of codeAction.commands) {
884
- yield this.tspClient.request("applyCodeActionCommand" /* ApplyCodeActionCommand */, { command });
927
+ yield this.tspClient.request("applyCodeActionCommand" /* CommandTypes.ApplyCodeActionCommand */, { command });
885
928
  }
886
929
  }
887
930
  }
888
- else if (arg.command === commands_1.Commands.APPLY_REFACTORING && arg.arguments) {
931
+ else if (arg.command === Commands.APPLY_REFACTORING && arg.arguments) {
889
932
  const args = arg.arguments[0];
890
- const { body } = yield this.tspClient.request("getEditsForRefactor" /* GetEditsForRefactor */, args);
933
+ const { body } = yield this.tspClient.request("getEditsForRefactor" /* CommandTypes.GetEditsForRefactor */, args);
891
934
  if (!body || !body.edits.length) {
892
935
  return;
893
936
  }
@@ -901,19 +944,19 @@ class LspServer {
901
944
  if (renameLocation) {
902
945
  yield this.options.lspClient.rename({
903
946
  textDocument: {
904
- uri: (0, protocol_translation_1.pathToUri)(args.file, this.documents)
947
+ uri: pathToUri(args.file, this.documents)
905
948
  },
906
- position: (0, protocol_translation_1.toPosition)(renameLocation)
949
+ position: toPosition(renameLocation)
907
950
  });
908
951
  }
909
952
  }
910
- else if (arg.command === commands_1.Commands.ORGANIZE_IMPORTS && arg.arguments) {
953
+ else if (arg.command === Commands.ORGANIZE_IMPORTS && arg.arguments) {
911
954
  const file = arg.arguments[0];
912
955
  const additionalArguments = arg.arguments[1] || {};
913
- yield this.tspClient.request("configure" /* Configure */, {
956
+ yield this.tspClient.request("configure" /* CommandTypes.Configure */, {
914
957
  formatOptions: this.getWorkspacePreferencesForDocument(file).format
915
958
  });
916
- const { body } = yield this.tspClient.request("organizeImports" /* OrganizeImports */, {
959
+ const { body } = yield this.tspClient.request("organizeImports" /* CommandTypes.OrganizeImports */, {
917
960
  scope: {
918
961
  type: 'file',
919
962
  args: { file }
@@ -922,17 +965,17 @@ class LspServer {
922
965
  });
923
966
  yield this.applyFileCodeEdits(body);
924
967
  }
925
- else if (arg.command === commands_1.Commands.APPLY_RENAME_FILE && arg.arguments) {
968
+ else if (arg.command === Commands.APPLY_RENAME_FILE && arg.arguments) {
926
969
  const { sourceUri, targetUri } = arg.arguments[0];
927
970
  this.applyRenameFile(sourceUri, targetUri);
928
971
  }
929
- else if (arg.command === commands_1.Commands.APPLY_COMPLETION_CODE_ACTION && arg.arguments) {
972
+ else if (arg.command === Commands.APPLY_COMPLETION_CODE_ACTION && arg.arguments) {
930
973
  const [_, codeActions] = arg.arguments;
931
974
  for (const codeAction of codeActions) {
932
975
  yield this.applyFileCodeEdits(codeAction.changes);
933
976
  if (codeAction.commands && codeAction.commands.length) {
934
977
  for (const command of codeAction.commands) {
935
- yield this.tspClient.request("applyCodeActionCommand" /* ApplyCodeActionCommand */, { command });
978
+ yield this.tspClient.request("applyCodeActionCommand" /* CommandTypes.ApplyCodeActionCommand */, { command });
936
979
  }
937
980
  }
938
981
  // Execute only the first code action.
@@ -951,7 +994,7 @@ class LspServer {
951
994
  }
952
995
  const changes = {};
953
996
  for (const edit of edits) {
954
- changes[(0, protocol_translation_1.pathToUri)(edit.fileName, this.documents)] = edit.textChanges.map(protocol_translation_1.toTextEdit);
997
+ changes[pathToUri(edit.fileName, this.documents)] = edit.textChanges.map(toTextEdit);
955
998
  }
956
999
  const { applied } = yield this.options.lspClient.applyWorkspaceEdit({
957
1000
  edit: { changes }
@@ -967,13 +1010,13 @@ class LspServer {
967
1010
  }
968
1011
  getEditsForFileRename(sourceUri, targetUri) {
969
1012
  return __awaiter(this, void 0, void 0, function* () {
970
- const newFilePath = (0, protocol_translation_1.uriToPath)(targetUri);
971
- const oldFilePath = (0, protocol_translation_1.uriToPath)(sourceUri);
1013
+ const newFilePath = uriToPath(targetUri);
1014
+ const oldFilePath = uriToPath(sourceUri);
972
1015
  if (!newFilePath || !oldFilePath) {
973
1016
  return [];
974
1017
  }
975
1018
  try {
976
- const { body } = yield this.tspClient.request("getEditsForFileRename" /* GetEditsForFileRename */, {
1019
+ const { body } = yield this.tspClient.request("getEditsForFileRename" /* CommandTypes.GetEditsForFileRename */, {
977
1020
  oldFilePath,
978
1021
  newFilePath
979
1022
  });
@@ -986,14 +1029,14 @@ class LspServer {
986
1029
  }
987
1030
  documentHighlight(arg) {
988
1031
  return __awaiter(this, void 0, void 0, function* () {
989
- const file = (0, protocol_translation_1.uriToPath)(arg.textDocument.uri);
1032
+ const file = uriToPath(arg.textDocument.uri);
990
1033
  this.logger.log('documentHighlight', arg, file);
991
1034
  if (!file) {
992
1035
  return [];
993
1036
  }
994
1037
  let response;
995
1038
  try {
996
- response = yield this.tspClient.request("documentHighlights" /* DocumentHighlights */, {
1039
+ response = yield this.tspClient.request("documentHighlights" /* CommandTypes.DocumentHighlights */, {
997
1040
  file,
998
1041
  line: arg.position.line + 1,
999
1042
  offset: arg.position.character + 1,
@@ -1010,8 +1053,8 @@ class LspServer {
1010
1053
  for (const item of response.body) {
1011
1054
  // tsp returns item.file with POSIX path delimiters, whereas file is platform specific.
1012
1055
  // Converting to a URI and back to a path ensures consistency.
1013
- if ((0, protocol_translation_1.normalizePath)(item.file) === file) {
1014
- const highlights = (0, protocol_translation_1.toDocumentHighlight)(item);
1056
+ if (normalizePath(item.file) === file) {
1057
+ const highlights = toDocumentHighlight(item);
1015
1058
  result.push(...highlights);
1016
1059
  }
1017
1060
  }
@@ -1023,7 +1066,7 @@ class LspServer {
1023
1066
  }
1024
1067
  workspaceSymbol(params) {
1025
1068
  return __awaiter(this, void 0, void 0, function* () {
1026
- const result = yield this.tspClient.request("navto" /* Navto */, {
1069
+ const result = yield this.tspClient.request("navto" /* CommandTypes.Navto */, {
1027
1070
  file: this.lastFileOrDummy(),
1028
1071
  searchValue: params.query
1029
1072
  });
@@ -1033,13 +1076,13 @@ class LspServer {
1033
1076
  return result.body.map(item => {
1034
1077
  return {
1035
1078
  location: {
1036
- uri: (0, protocol_translation_1.pathToUri)(item.file, this.documents),
1079
+ uri: pathToUri(item.file, this.documents),
1037
1080
  range: {
1038
- start: (0, protocol_translation_1.toPosition)(item.start),
1039
- end: (0, protocol_translation_1.toPosition)(item.end)
1081
+ start: toPosition(item.start),
1082
+ end: toPosition(item.end)
1040
1083
  }
1041
1084
  },
1042
- kind: (0, protocol_translation_1.toSymbolKind)(item.kind),
1085
+ kind: toSymbolKind(item.kind),
1043
1086
  name: item.name
1044
1087
  };
1045
1088
  });
@@ -1050,7 +1093,7 @@ class LspServer {
1050
1093
  */
1051
1094
  foldingRanges(params) {
1052
1095
  return __awaiter(this, void 0, void 0, function* () {
1053
- const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
1096
+ const file = uriToPath(params.textDocument.uri);
1054
1097
  this.logger.log('foldingRanges', params, file);
1055
1098
  if (!file) {
1056
1099
  return undefined;
@@ -1059,7 +1102,7 @@ class LspServer {
1059
1102
  if (!document) {
1060
1103
  throw new Error("The document should be opened for foldingRanges', file: " + file);
1061
1104
  }
1062
- const { body } = yield this.tspClient.request("getOutliningSpans" /* GetOutliningSpans */, { file });
1105
+ const { body } = yield this.tspClient.request("getOutliningSpans" /* CommandTypes.GetOutliningSpans */, { file });
1063
1106
  if (!body) {
1064
1107
  return undefined;
1065
1108
  }
@@ -1074,7 +1117,7 @@ class LspServer {
1074
1117
  });
1075
1118
  }
1076
1119
  asFoldingRange(span, document) {
1077
- const range = (0, protocol_translation_1.asRange)(span.textSpan);
1120
+ const range = asRange(span.textSpan);
1078
1121
  const kind = this.asFoldingRangeKind(span);
1079
1122
  // workaround for https://github.com/Microsoft/vscode/issues/49904
1080
1123
  if (span.kind === 'comment') {
@@ -1103,15 +1146,15 @@ class LspServer {
1103
1146
  }
1104
1147
  onTsEvent(event) {
1105
1148
  var _a;
1106
- if (event.event === "semanticDiag" /* SementicDiag */ ||
1107
- event.event === "syntaxDiag" /* SyntaxDiag */ ||
1108
- event.event === "suggestionDiag" /* SuggestionDiag */) {
1149
+ if (event.event === "semanticDiag" /* EventTypes.SementicDiag */ ||
1150
+ event.event === "syntaxDiag" /* EventTypes.SyntaxDiag */ ||
1151
+ event.event === "suggestionDiag" /* EventTypes.SuggestionDiag */) {
1109
1152
  (_a = this.diagnosticQueue) === null || _a === void 0 ? void 0 : _a.updateDiagnostics(event.event, event);
1110
1153
  }
1111
- else if (event.event === "projectLoadingStart" /* ProjectLoadingStart */) {
1154
+ else if (event.event === "projectLoadingStart" /* EventTypes.ProjectLoadingStart */) {
1112
1155
  this.loadingIndicator.startedLoadingProject(event.body.projectName);
1113
1156
  }
1114
- else if (event.event === "projectLoadingFinish" /* ProjectLoadingFinish */) {
1157
+ else if (event.event === "projectLoadingFinish" /* EventTypes.ProjectLoadingFinish */) {
1115
1158
  this.loadingIndicator.finishedLoadingProject(event.body.projectName);
1116
1159
  }
1117
1160
  else {
@@ -1123,17 +1166,17 @@ class LspServer {
1123
1166
  calls(params) {
1124
1167
  return __awaiter(this, void 0, void 0, function* () {
1125
1168
  let callsResult = { calls: [] };
1126
- const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
1169
+ const file = uriToPath(params.textDocument.uri);
1127
1170
  this.logger.log('calls', params, file);
1128
1171
  if (!file) {
1129
1172
  return callsResult;
1130
1173
  }
1131
1174
  if (params.direction === lspcalls.CallDirection.Outgoing) {
1132
1175
  const documentProvider = (file) => this.documents.get(file);
1133
- callsResult = yield (0, calls_1.computeCallees)(this.tspClient, params, documentProvider);
1176
+ callsResult = yield computeCallees(this.tspClient, params, documentProvider);
1134
1177
  }
1135
1178
  else {
1136
- callsResult = yield (0, calls_1.computeCallers)(this.tspClient, params);
1179
+ callsResult = yield computeCallers(this.tspClient, params);
1137
1180
  }
1138
1181
  return callsResult;
1139
1182
  });
@@ -1141,12 +1184,12 @@ class LspServer {
1141
1184
  inlayHints(params) {
1142
1185
  var _a, _b, _c, _d, _e, _f;
1143
1186
  return __awaiter(this, void 0, void 0, function* () {
1144
- const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
1187
+ const file = uriToPath(params.textDocument.uri);
1145
1188
  this.logger.log('inlayHints', params, file);
1146
1189
  if (!file) {
1147
1190
  return { inlayHints: [] };
1148
1191
  }
1149
- yield this.tspClient.request("configure" /* Configure */, {
1192
+ yield this.tspClient.request("configure" /* CommandTypes.Configure */, {
1150
1193
  preferences: this.getInlayHintsOptions(file)
1151
1194
  });
1152
1195
  const doc = this.documents.get(file);
@@ -1162,7 +1205,7 @@ class LspServer {
1162
1205
  character: 0
1163
1206
  });
1164
1207
  try {
1165
- const result = yield this.tspClient.request("provideInlayHints" /* ProvideInlayHints */, {
1208
+ const result = yield this.tspClient.request("provideInlayHints" /* CommandTypes.ProvideInlayHints */, {
1166
1209
  file,
1167
1210
  start: start,
1168
1211
  length: end - start
@@ -1170,7 +1213,7 @@ class LspServer {
1170
1213
  return {
1171
1214
  inlayHints: (_f = (_e = result.body) === null || _e === void 0 ? void 0 : _e.map((item) => ({
1172
1215
  text: item.text,
1173
- position: (0, protocol_translation_1.toPosition)(item.position),
1216
+ position: toPosition(item.position),
1174
1217
  whitespaceAfter: item.whitespaceAfter,
1175
1218
  whitespaceBefore: item.whitespaceBefore,
1176
1219
  kind: item.kind
@@ -1192,7 +1235,7 @@ class LspServer {
1192
1235
  }
1193
1236
  semanticTokensFull(params) {
1194
1237
  return __awaiter(this, void 0, void 0, function* () {
1195
- const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
1238
+ const file = uriToPath(params.textDocument.uri);
1196
1239
  this.logger.log('semanticTokensFull', params, file);
1197
1240
  if (!file) {
1198
1241
  return { data: [] };
@@ -1214,7 +1257,7 @@ class LspServer {
1214
1257
  }
1215
1258
  semanticTokensRange(params) {
1216
1259
  return __awaiter(this, void 0, void 0, function* () {
1217
- const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
1260
+ const file = uriToPath(params.textDocument.uri);
1218
1261
  this.logger.log('semanticTokensRange', params, file);
1219
1262
  if (!file) {
1220
1263
  return { data: [] };
@@ -1232,7 +1275,7 @@ class LspServer {
1232
1275
  var _a, _b;
1233
1276
  return __awaiter(this, void 0, void 0, function* () {
1234
1277
  try {
1235
- const result = yield this.tspClient.request("encodedSemanticClassifications-full" /* EncodedSemanticClassificationsFull */, {
1278
+ const result = yield this.tspClient.request("encodedSemanticClassifications-full" /* CommandTypes.EncodedSemanticClassificationsFull */, {
1236
1279
  file,
1237
1280
  start: startOffset,
1238
1281
  length: endOffset - startOffset,
@@ -1247,5 +1290,4 @@ class LspServer {
1247
1290
  });
1248
1291
  }
1249
1292
  }
1250
- exports.LspServer = LspServer;
1251
1293
  //# sourceMappingURL=lsp-server.js.map