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
@@ -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,18 +13,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
37
13
  step((generator = generator.apply(thisArg, _arguments || [])).next());
38
14
  });
39
15
  };
40
- Object.defineProperty(exports, "__esModule", { value: true });
41
- const chai = __importStar(require("chai"));
42
- const lsp = __importStar(require("vscode-languageserver/node"));
43
- const lspcalls = __importStar(require("./lsp-protocol.calls.proposed"));
44
- const test_utils_1 = require("./test-utils");
45
- const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
46
- const types_1 = require("./utils/types");
16
+ import * as chai from 'chai';
17
+ import fs from 'fs-extra';
18
+ import * as lsp from 'vscode-languageserver';
19
+ import * as lspcalls from './lsp-protocol.calls.proposed.js';
20
+ import { uri, createServer, position, lastPosition, filePath, getDefaultClientCapabilities, positionAfter, readContents, toPlatformEOL } from './test-utils.js';
21
+ import { TextDocument } from 'vscode-languageserver-textdocument';
22
+ import { Commands } from './commands.js';
23
+ import { CodeActionKind } from './utils/types.js';
47
24
  const assert = chai.assert;
48
25
  const diagnostics = new Map();
49
26
  let server;
50
27
  before(() => __awaiter(void 0, void 0, void 0, function* () {
51
- server = yield (0, test_utils_1.createServer)({
28
+ server = yield createServer({
52
29
  rootUri: null,
53
30
  publishDiagnostics: args => diagnostics.set(args.uri, args)
54
31
  });
@@ -64,14 +41,16 @@ beforeEach(() => {
64
41
  server.closeAll();
65
42
  // "closeAll" triggers final publishDiagnostics with an empty list so clear last.
66
43
  diagnostics.clear();
44
+ server.workspaceEdits = [];
67
45
  });
68
46
  after(() => {
69
47
  server.closeAll();
48
+ server.shutdown();
70
49
  });
71
50
  describe('completion', () => {
72
51
  it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
73
52
  const doc = {
74
- uri: (0, test_utils_1.uri)('bar.ts'),
53
+ uri: uri('bar.ts'),
75
54
  languageId: 'typescript',
76
55
  version: 1,
77
56
  text: `
@@ -83,7 +62,7 @@ describe('completion', () => {
83
62
  server.didOpenTextDocument({
84
63
  textDocument: doc
85
64
  });
86
- const pos = (0, test_utils_1.position)(doc, 'console');
65
+ const pos = position(doc, 'console');
87
66
  const proposals = yield server.completion({ textDocument: doc, position: pos });
88
67
  assert.isNotNull(proposals);
89
68
  assert.isAtLeast(proposals.items.length, 800);
@@ -93,10 +72,10 @@ describe('completion', () => {
93
72
  assert.isNotTrue(resolvedItem.deprecated, 'resolved item is not deprecated');
94
73
  assert.isDefined(resolvedItem.detail);
95
74
  server.didCloseTextDocument({ textDocument: doc });
96
- })).timeout(10000);
75
+ }));
97
76
  it('simple JS test', () => __awaiter(void 0, void 0, void 0, function* () {
98
77
  const doc = {
99
- uri: (0, test_utils_1.uri)('bar.js'),
78
+ uri: uri('bar.js'),
100
79
  languageId: 'javascript',
101
80
  version: 1,
102
81
  text: `
@@ -108,7 +87,7 @@ describe('completion', () => {
108
87
  server.didOpenTextDocument({
109
88
  textDocument: doc
110
89
  });
111
- const pos = (0, test_utils_1.position)(doc, 'console');
90
+ const pos = position(doc, 'console');
112
91
  const proposals = yield server.completion({ textDocument: doc, position: pos });
113
92
  assert.isNotNull(proposals);
114
93
  assert.isAtLeast(proposals.items.length, 800);
@@ -126,10 +105,10 @@ describe('completion', () => {
126
105
  }, false);
127
106
  assert.isFalse(containsInvalidCompletions);
128
107
  server.didCloseTextDocument({ textDocument: doc });
129
- })).timeout(10000);
108
+ }));
130
109
  it('deprecated by JSDoc', () => __awaiter(void 0, void 0, void 0, function* () {
131
110
  const doc = {
132
- uri: (0, test_utils_1.uri)('bar.ts'),
111
+ uri: uri('bar.ts'),
133
112
  languageId: 'typescript',
134
113
  version: 1,
135
114
  text: `
@@ -147,7 +126,7 @@ describe('completion', () => {
147
126
  server.didOpenTextDocument({
148
127
  textDocument: doc
149
128
  });
150
- const pos = (0, test_utils_1.position)(doc, 'foo(); // call me');
129
+ const pos = position(doc, 'foo(); // call me');
151
130
  const proposals = yield server.completion({ textDocument: doc, position: pos });
152
131
  assert.isNotNull(proposals);
153
132
  const item = proposals.items.find(i => i.label === 'foo');
@@ -157,10 +136,10 @@ describe('completion', () => {
157
136
  assert.isArray(resolvedItem.tags);
158
137
  assert.include(resolvedItem.tags, lsp.CompletionItemTag.Deprecated, 'resolved item is deprecated');
159
138
  server.didCloseTextDocument({ textDocument: doc });
160
- })).timeout(10000);
139
+ }));
161
140
  it('incorrect source location', () => __awaiter(void 0, void 0, void 0, function* () {
162
141
  const doc = {
163
- uri: (0, test_utils_1.uri)('bar.ts'),
142
+ uri: uri('bar.ts'),
164
143
  languageId: 'typescript',
165
144
  version: 1,
166
145
  text: `
@@ -172,28 +151,28 @@ describe('completion', () => {
172
151
  server.didOpenTextDocument({
173
152
  textDocument: doc
174
153
  });
175
- const pos = (0, test_utils_1.position)(doc, 'foo');
154
+ const pos = position(doc, 'foo');
176
155
  const proposals = yield server.completion({ textDocument: doc, position: pos });
177
156
  assert.isNull(proposals);
178
157
  server.didCloseTextDocument({ textDocument: doc });
179
- })).timeout(10000);
158
+ }));
180
159
  it('includes completions from global modules', () => __awaiter(void 0, void 0, void 0, function* () {
181
160
  const doc = {
182
- uri: (0, test_utils_1.uri)('bar.ts'),
161
+ uri: uri('bar.ts'),
183
162
  languageId: 'typescript',
184
163
  version: 1,
185
164
  text: 'pathex'
186
165
  };
187
166
  server.didOpenTextDocument({ textDocument: doc });
188
- const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.position)(doc, 'ex') });
167
+ const proposals = yield server.completion({ textDocument: doc, position: position(doc, 'ex') });
189
168
  assert.isNotNull(proposals);
190
169
  const pathExistsCompletion = proposals.items.find(completion => completion.label === 'pathExists');
191
170
  assert.isDefined(pathExistsCompletion);
192
171
  server.didCloseTextDocument({ textDocument: doc });
193
- })).timeout(10000);
172
+ }));
194
173
  it('includes completions with invalid identifier names', () => __awaiter(void 0, void 0, void 0, function* () {
195
174
  const doc = {
196
- uri: (0, test_utils_1.uri)('bar.ts'),
175
+ uri: uri('bar.ts'),
197
176
  languageId: 'typescript',
198
177
  version: 1,
199
178
  text: `
@@ -206,39 +185,39 @@ describe('completion', () => {
206
185
  `
207
186
  };
208
187
  server.didOpenTextDocument({ textDocument: doc });
209
- const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.positionAfter)(doc, '.i') });
188
+ const proposals = yield server.completion({ textDocument: doc, position: positionAfter(doc, '.i') });
210
189
  assert.isNotNull(proposals);
211
190
  const completion = proposals.items.find(completion => completion.label === 'invalid-identifier-name');
212
191
  assert.isDefined(completion);
213
192
  assert.isDefined(completion.textEdit);
214
193
  assert.equal(completion.textEdit.newText, '["invalid-identifier-name"]');
215
194
  server.didCloseTextDocument({ textDocument: doc });
216
- })).timeout(10000);
195
+ }));
217
196
  it('includes detail field with package name for auto-imports', () => __awaiter(void 0, void 0, void 0, function* () {
218
197
  const doc = {
219
- uri: (0, test_utils_1.uri)('bar.ts'),
198
+ uri: uri('bar.ts'),
220
199
  languageId: 'typescript',
221
200
  version: 1,
222
201
  text: 'readFile'
223
202
  };
224
203
  server.didOpenTextDocument({ textDocument: doc });
225
- const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.positionAfter)(doc, 'readFile') });
204
+ const proposals = yield server.completion({ textDocument: doc, position: positionAfter(doc, 'readFile') });
226
205
  assert.isNotNull(proposals);
227
206
  const completion = proposals.items.find(completion => completion.label === 'readFile');
228
207
  assert.isDefined(completion);
229
208
  assert.strictEqual(completion.detail, 'fs');
230
209
  assert.strictEqual(completion.insertTextFormat, /* snippet */ 2);
231
210
  server.didCloseTextDocument({ textDocument: doc });
232
- })).timeout(10000);
211
+ }));
233
212
  it('resolves text edit for auto-import completion', () => __awaiter(void 0, void 0, void 0, function* () {
234
213
  const doc = {
235
- uri: (0, test_utils_1.uri)('bar.ts'),
214
+ uri: uri('bar.ts'),
236
215
  languageId: 'typescript',
237
216
  version: 1,
238
217
  text: 'readFile'
239
218
  };
240
219
  server.didOpenTextDocument({ textDocument: doc });
241
- const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.positionAfter)(doc, 'readFile') });
220
+ const proposals = yield server.completion({ textDocument: doc, position: positionAfter(doc, 'readFile') });
242
221
  assert.isNotNull(proposals);
243
222
  const completion = proposals.items.find(completion => completion.label === 'readFile');
244
223
  assert.isDefined(completion);
@@ -259,7 +238,7 @@ describe('completion', () => {
259
238
  }
260
239
  ]);
261
240
  server.didCloseTextDocument({ textDocument: doc });
262
- })).timeout(10000);
241
+ }));
263
242
  it('resolves text edit for auto-import completion in right format', () => __awaiter(void 0, void 0, void 0, function* () {
264
243
  server.didChangeConfiguration({
265
244
  settings: {
@@ -272,13 +251,13 @@ describe('completion', () => {
272
251
  }
273
252
  });
274
253
  const doc = {
275
- uri: (0, test_utils_1.uri)('bar.ts'),
254
+ uri: uri('bar.ts'),
276
255
  languageId: 'typescript',
277
256
  version: 1,
278
257
  text: 'readFile'
279
258
  };
280
259
  server.didOpenTextDocument({ textDocument: doc });
281
- const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.positionAfter)(doc, 'readFile') });
260
+ const proposals = yield server.completion({ textDocument: doc, position: positionAfter(doc, 'readFile') });
282
261
  assert.isNotNull(proposals);
283
262
  const completion = proposals.items.find(completion => completion.label === 'readFile');
284
263
  assert.isDefined(completion);
@@ -312,10 +291,10 @@ describe('completion', () => {
312
291
  }
313
292
  }
314
293
  });
315
- })).timeout(10000);
294
+ }));
316
295
  it('resolves a snippet for method completion', () => __awaiter(void 0, void 0, void 0, function* () {
317
296
  const doc = {
318
- uri: (0, test_utils_1.uri)('bar.ts'),
297
+ uri: uri('bar.ts'),
319
298
  languageId: 'typescript',
320
299
  version: 1,
321
300
  text: `
@@ -324,7 +303,7 @@ describe('completion', () => {
324
303
  `
325
304
  };
326
305
  server.didOpenTextDocument({ textDocument: doc });
327
- const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.positionAfter)(doc, 'readFile') });
306
+ const proposals = yield server.completion({ textDocument: doc, position: positionAfter(doc, 'readFile') });
328
307
  assert.isNotNull(proposals);
329
308
  const completion = proposals.items.find(completion => completion.label === 'readFile');
330
309
  assert.strictEqual(completion.insertTextFormat, lsp.InsertTextFormat.Snippet);
@@ -334,12 +313,81 @@ describe('completion', () => {
334
313
  // eslint-disable-next-line no-template-curly-in-string
335
314
  assert.strictEqual(resolvedItem.insertText, 'readFile(${1:path}, ${2:options}, ${3:callback})$0');
336
315
  server.didCloseTextDocument({ textDocument: doc });
337
- })).timeout(10000);
316
+ }));
317
+ it('includes textEdit for string completion', () => __awaiter(void 0, void 0, void 0, function* () {
318
+ const doc = {
319
+ uri: uri('bar.ts'),
320
+ languageId: 'typescript',
321
+ version: 1,
322
+ text: `
323
+ function test(value: "fs/read" | "hello/world") {
324
+ return true;
325
+ }
326
+
327
+ test("fs/")
328
+ `
329
+ };
330
+ server.didOpenTextDocument({ textDocument: doc });
331
+ const proposals = yield server.completion({
332
+ textDocument: doc,
333
+ position: positionAfter(doc, 'test("fs/'),
334
+ context: {
335
+ triggerCharacter: '/',
336
+ triggerKind: 2
337
+ }
338
+ });
339
+ assert.isNotNull(proposals);
340
+ const completion = proposals.items.find(completion => completion.label === 'fs/read');
341
+ assert.strictEqual(completion.label, 'fs/read');
342
+ assert.deepStrictEqual(completion.textEdit, {
343
+ range: {
344
+ start: { line: 5, character: 20 },
345
+ end: { line: 5, character: 23 }
346
+ },
347
+ newText: 'fs/read'
348
+ });
349
+ }));
350
+ it('includes labelDetails with useLabelDetailsInCompletionEntries enabled', () => __awaiter(void 0, void 0, void 0, function* () {
351
+ const doc = {
352
+ uri: uri('foo.ts'),
353
+ languageId: 'typescript',
354
+ version: 1,
355
+ text: `
356
+ interface IFoo {
357
+ bar(x: number): void;
358
+ }
359
+ const obj: IFoo = {
360
+ /*a*/
361
+ }
362
+ `
363
+ };
364
+ server.didOpenTextDocument({ textDocument: doc });
365
+ const proposals = yield server.completion({
366
+ textDocument: doc,
367
+ position: positionAfter(doc, '/*a*/')
368
+ });
369
+ assert.isNotNull(proposals);
370
+ assert.lengthOf(proposals.items, 2);
371
+ assert.deepInclude(proposals.items[0], {
372
+ label: 'bar',
373
+ kind: 2,
374
+ insertTextFormat: 2
375
+ });
376
+ assert.deepInclude(proposals.items[1], {
377
+ label: 'bar',
378
+ labelDetails: {
379
+ detail: '(x)'
380
+ },
381
+ kind: 2,
382
+ insertTextFormat: 2,
383
+ insertText: toPlatformEOL('bar(x) {\n $0\n},')
384
+ });
385
+ }));
338
386
  });
339
387
  describe('diagnostics', () => {
340
388
  it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
341
389
  const doc = {
342
- uri: (0, test_utils_1.uri)('diagnosticsBar.ts'),
390
+ uri: uri('diagnosticsBar.ts'),
343
391
  languageId: 'typescript',
344
392
  version: 1,
345
393
  text: `
@@ -358,10 +406,10 @@ describe('diagnostics', () => {
358
406
  const fileDiagnostics = resultsForFile.diagnostics;
359
407
  assert.equal(fileDiagnostics.length, 1);
360
408
  assert.equal("Cannot find name 'missing'.", fileDiagnostics[0].message);
361
- })).timeout(10000);
409
+ }));
362
410
  it('supports diagnostic tags', () => __awaiter(void 0, void 0, void 0, function* () {
363
411
  const doc = {
364
- uri: (0, test_utils_1.uri)('diagnosticsBar.ts'),
412
+ uri: uri('diagnosticsBar.ts'),
365
413
  languageId: 'typescript',
366
414
  version: 1,
367
415
  text: `
@@ -387,10 +435,10 @@ describe('diagnostics', () => {
387
435
  const deprecatedDiagnostic = fileDiagnostics.find(d => d.code === 6387);
388
436
  assert.isDefined(deprecatedDiagnostic);
389
437
  assert.deepEqual(deprecatedDiagnostic.tags, [lsp.DiagnosticTag.Deprecated]);
390
- })).timeout(10000);
438
+ }));
391
439
  it('multiple files test', () => __awaiter(void 0, void 0, void 0, function* () {
392
440
  const doc = {
393
- uri: (0, test_utils_1.uri)('multipleFileDiagnosticsBar.ts'),
441
+ uri: uri('multipleFileDiagnosticsBar.ts'),
394
442
  languageId: 'typescript',
395
443
  version: 1,
396
444
  text: `
@@ -400,7 +448,7 @@ describe('diagnostics', () => {
400
448
  `
401
449
  };
402
450
  const doc2 = {
403
- uri: (0, test_utils_1.uri)('multipleFileDiagnosticsFoo.ts'),
451
+ uri: uri('multipleFileDiagnosticsFoo.ts'),
404
452
  languageId: 'typescript',
405
453
  version: 1,
406
454
  text: `
@@ -424,7 +472,7 @@ describe('diagnostics', () => {
424
472
  assert.isDefined(diagnosticsForDoc2);
425
473
  assert.equal(diagnosticsForDoc.diagnostics.length, 1, JSON.stringify(diagnostics));
426
474
  assert.equal(diagnosticsForDoc2.diagnostics.length, 1, JSON.stringify(diagnostics));
427
- })).timeout(10000);
475
+ }));
428
476
  it('code 6133 (ununsed variable) is ignored', () => __awaiter(void 0, void 0, void 0, function* () {
429
477
  server.didChangeConfiguration({
430
478
  settings: {
@@ -434,7 +482,7 @@ describe('diagnostics', () => {
434
482
  }
435
483
  });
436
484
  const doc = {
437
- uri: (0, test_utils_1.uri)('diagnosticsBar2.ts'),
485
+ uri: uri('diagnosticsBar2.ts'),
438
486
  languageId: 'typescript',
439
487
  version: 1,
440
488
  text: `
@@ -453,12 +501,12 @@ describe('diagnostics', () => {
453
501
  assert.isDefined(diagnosticsForThisFile);
454
502
  const fileDiagnostics = diagnosticsForThisFile.diagnostics;
455
503
  assert.equal(fileDiagnostics.length, 0, JSON.stringify(fileDiagnostics));
456
- })).timeout(10000);
504
+ }));
457
505
  });
458
506
  describe('document symbol', () => {
459
507
  it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
460
508
  const doc = {
461
- uri: (0, test_utils_1.uri)('bar.ts'),
509
+ uri: uri('bar.ts'),
462
510
  languageId: 'typescript',
463
511
  version: 1,
464
512
  text: `
@@ -481,10 +529,10 @@ Foo
481
529
  foo
482
530
  myFunction
483
531
  `, symbolsAsString(symbols) + '\n');
484
- })).timeout(10000);
532
+ }));
485
533
  it('merges interfaces correctly', () => __awaiter(void 0, void 0, void 0, function* () {
486
534
  const doc = {
487
- uri: (0, test_utils_1.uri)('bar.ts'),
535
+ uri: uri('bar.ts'),
488
536
  languageId: 'typescript',
489
537
  version: 1,
490
538
  text: `
@@ -511,10 +559,10 @@ Box
511
559
  Box
512
560
  scale
513
561
  `, symbolsAsString(symbols) + '\n');
514
- })).timeout(10000);
562
+ }));
515
563
  it('duplication test', () => __awaiter(void 0, void 0, void 0, function* () {
516
564
  const doc = {
517
- uri: (0, test_utils_1.uri)('bar.ts'),
565
+ uri: uri('bar.ts'),
518
566
  languageId: 'typescript',
519
567
  version: 1,
520
568
  text: `
@@ -550,7 +598,7 @@ Foo
550
598
  assert.deepEqual(symbols[0].range, { start: { line: 1, character: 8 }, end: { line: 5, character: 9 } });
551
599
  assert.deepEqual(symbols[1].selectionRange, symbols[1].range);
552
600
  assert.deepEqual(symbols[1].range, { start: { line: 6, character: 8 }, end: { line: 10, character: 9 } });
553
- })).timeout(10000);
601
+ }));
554
602
  });
555
603
  function symbolsAsString(symbols, indentation = '') {
556
604
  return symbols.map(symbol => {
@@ -571,7 +619,7 @@ function symbolsAsString(symbols, indentation = '') {
571
619
  describe('editing', () => {
572
620
  it('open and change', () => __awaiter(void 0, void 0, void 0, function* () {
573
621
  const doc = {
574
- uri: (0, test_utils_1.uri)('openAndChangeBar.ts'),
622
+ uri: uri('openAndChangeBar.ts'),
575
623
  languageId: 'typescript',
576
624
  version: 1,
577
625
  text: `
@@ -601,45 +649,44 @@ describe('editing', () => {
601
649
  const fileDiagnostics = resultsForFile.diagnostics;
602
650
  assert.isTrue(fileDiagnostics.length >= 1, fileDiagnostics.map(d => d.message).join(','));
603
651
  assert.equal("Cannot find name 'missing'.", fileDiagnostics[0].message);
604
- })).timeout(10000);
652
+ }));
605
653
  });
606
654
  describe('references', () => {
607
655
  it('respects "includeDeclaration" in the request', () => __awaiter(void 0, void 0, void 0, function* () {
608
656
  const doc = {
609
- uri: (0, test_utils_1.uri)('foo.ts'),
657
+ uri: uri('foo.ts'),
610
658
  languageId: 'typescript',
611
659
  version: 1,
612
660
  text: `
613
- export let foo = 1;
614
- foo++;
615
- foo = 1;
661
+ function foo() {};
662
+ foo();
616
663
  `
617
664
  };
618
665
  server.didOpenTextDocument({
619
666
  textDocument: doc
620
667
  });
621
668
  // Without declaration/definition.
669
+ const position = lastPosition(doc, 'function foo()');
622
670
  let references = yield server.references({
623
671
  context: { includeDeclaration: false },
624
672
  textDocument: doc,
625
- position: (0, test_utils_1.lastPosition)(doc, 'foo')
673
+ position
626
674
  });
627
- assert.strictEqual(references.length, 2);
675
+ assert.strictEqual(references.length, 1);
628
676
  assert.strictEqual(references[0].range.start.line, 2);
629
- assert.strictEqual(references[1].range.start.line, 3);
630
677
  // With declaration/definition.
631
678
  references = yield server.references({
632
679
  context: { includeDeclaration: true },
633
680
  textDocument: doc,
634
- position: (0, test_utils_1.lastPosition)(doc, 'foo')
681
+ position
635
682
  });
636
- assert.strictEqual(references.length, 3);
637
- })).timeout(10000);
683
+ assert.strictEqual(references.length, 2);
684
+ }));
638
685
  });
639
686
  describe('workspace configuration', () => {
640
687
  it('receives workspace configuration notification', () => __awaiter(void 0, void 0, void 0, function* () {
641
688
  const doc = {
642
- uri: (0, test_utils_1.uri)('bar.ts'),
689
+ uri: uri('bar.ts'),
643
690
  languageId: 'typescript',
644
691
  version: 1,
645
692
  text: `
@@ -665,13 +712,13 @@ describe('workspace configuration', () => {
665
712
  }
666
713
  }
667
714
  });
668
- const file = (0, test_utils_1.filePath)('bar.ts');
715
+ const file = filePath('bar.ts');
669
716
  const settings = server.getWorkspacePreferencesForDocument(file);
670
717
  assert.deepEqual(settings, { format: { insertSpaceAfterCommaDelimiter: true } });
671
718
  }));
672
719
  });
673
720
  describe('formatting', () => {
674
- const uriString = (0, test_utils_1.uri)('bar.ts');
721
+ const uriString = uri('bar.ts');
675
722
  const languageId = 'typescript';
676
723
  const version = 1;
677
724
  it('full document formatting', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -687,9 +734,9 @@ describe('formatting', () => {
687
734
  insertSpaces: true
688
735
  }
689
736
  });
690
- const result = vscode_languageserver_textdocument_1.TextDocument.applyEdits(vscode_languageserver_textdocument_1.TextDocument.create(uriString, languageId, version, text), edits);
737
+ const result = TextDocument.applyEdits(TextDocument.create(uriString, languageId, version, text), edits);
691
738
  assert.equal('export function foo(): void { }', result);
692
- })).timeout(10000);
739
+ }));
693
740
  it('indent settings (3 spaces)', () => __awaiter(void 0, void 0, void 0, function* () {
694
741
  const text = 'function foo() {\n// some code\n}';
695
742
  const textDocument = {
@@ -703,9 +750,9 @@ describe('formatting', () => {
703
750
  insertSpaces: true
704
751
  }
705
752
  });
706
- const result = vscode_languageserver_textdocument_1.TextDocument.applyEdits(vscode_languageserver_textdocument_1.TextDocument.create(uriString, languageId, version, text), edits);
753
+ const result = TextDocument.applyEdits(TextDocument.create(uriString, languageId, version, text), edits);
707
754
  assert.equal('function foo() {\n // some code\n}', result);
708
- })).timeout(10000);
755
+ }));
709
756
  it('indent settings (tabs)', () => __awaiter(void 0, void 0, void 0, function* () {
710
757
  const text = 'function foo() {\n// some code\n}';
711
758
  const textDocument = {
@@ -719,9 +766,9 @@ describe('formatting', () => {
719
766
  insertSpaces: false
720
767
  }
721
768
  });
722
- const result = vscode_languageserver_textdocument_1.TextDocument.applyEdits(vscode_languageserver_textdocument_1.TextDocument.create(uriString, languageId, version, text), edits);
769
+ const result = TextDocument.applyEdits(TextDocument.create(uriString, languageId, version, text), edits);
723
770
  assert.equal('function foo() {\n\t// some code\n}', result);
724
- })).timeout(10000);
771
+ }));
725
772
  it('formatting setting set through workspace configuration', () => __awaiter(void 0, void 0, void 0, function* () {
726
773
  const text = 'function foo() {\n// some code\n}';
727
774
  const textDocument = {
@@ -745,9 +792,9 @@ describe('formatting', () => {
745
792
  insertSpaces: false
746
793
  }
747
794
  });
748
- const result = vscode_languageserver_textdocument_1.TextDocument.applyEdits(vscode_languageserver_textdocument_1.TextDocument.create(uriString, languageId, version, text), edits);
795
+ const result = TextDocument.applyEdits(TextDocument.create(uriString, languageId, version, text), edits);
749
796
  assert.equal('function foo()\n{\n\t// some code\n}', result);
750
- })).timeout(10000);
797
+ }));
751
798
  it('selected range', () => __awaiter(void 0, void 0, void 0, function* () {
752
799
  const text = 'function foo() {\nconst first = 1;\nconst second = 2;\nconst val = foo( "something" );\n//const fourth = 4;\n}';
753
800
  const textDocument = {
@@ -771,14 +818,14 @@ describe('formatting', () => {
771
818
  insertSpaces: true
772
819
  }
773
820
  });
774
- const result = vscode_languageserver_textdocument_1.TextDocument.applyEdits(vscode_languageserver_textdocument_1.TextDocument.create(uriString, languageId, version, text), edits);
821
+ const result = TextDocument.applyEdits(TextDocument.create(uriString, languageId, version, text), edits);
775
822
  assert.equal('function foo() {\nconst first = 1;\n const second = 2;\n const val = foo("something");\n//const fourth = 4;\n}', result);
776
- })).timeout(10000);
823
+ }));
777
824
  });
778
825
  describe('signatureHelp', () => {
779
826
  it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
780
827
  const doc = {
781
- uri: (0, test_utils_1.uri)('bar.ts'),
828
+ uri: uri('bar.ts'),
782
829
  languageId: 'typescript',
783
830
  version: 1,
784
831
  text: `
@@ -791,19 +838,19 @@ describe('signatureHelp', () => {
791
838
  });
792
839
  let result = (yield server.signatureHelp({
793
840
  textDocument: doc,
794
- position: (0, test_utils_1.position)(doc, 'param1')
841
+ position: position(doc, 'param1')
795
842
  }));
796
843
  assert.equal('bar: string', result.signatures[result.activeSignature].parameters[result.activeParameter].label);
797
844
  result = (yield server.signatureHelp({
798
845
  textDocument: doc,
799
- position: (0, test_utils_1.position)(doc, 'param2')
846
+ position: position(doc, 'param2')
800
847
  }));
801
848
  assert.equal('baz?: boolean', result.signatures[result.activeSignature].parameters[result.activeParameter].label);
802
- })).timeout(10000);
849
+ }));
803
850
  });
804
851
  describe('code actions', () => {
805
852
  const doc = {
806
- uri: (0, test_utils_1.uri)('bar.ts'),
853
+ uri: uri('bar.ts'),
807
854
  languageId: 'typescript',
808
855
  version: 1,
809
856
  text: `import { something } from "something";
@@ -845,7 +892,7 @@ describe('code actions', () => {
845
892
  documentChanges: [
846
893
  {
847
894
  textDocument: {
848
- uri: (0, test_utils_1.uri)('bar.ts'),
895
+ uri: uri('bar.ts'),
849
896
  version: 1
850
897
  },
851
898
  edits: [
@@ -879,7 +926,7 @@ describe('code actions', () => {
879
926
  command: '_typescript.applyRefactoring',
880
927
  arguments: [
881
928
  {
882
- file: (0, test_utils_1.filePath)('bar.ts'),
929
+ file: filePath('bar.ts'),
883
930
  startLine: 2,
884
931
  startOffset: 26,
885
932
  endLine: 2,
@@ -891,7 +938,7 @@ describe('code actions', () => {
891
938
  },
892
939
  kind: 'refactor'
893
940
  });
894
- })).timeout(10000);
941
+ }));
895
942
  it('can filter quickfix code actions filtered by only', () => __awaiter(void 0, void 0, void 0, function* () {
896
943
  server.didOpenTextDocument({
897
944
  textDocument: doc
@@ -922,7 +969,7 @@ describe('code actions', () => {
922
969
  action: 'Convert parameters to destructured object',
923
970
  endLine: 2,
924
971
  endOffset: 50,
925
- file: (0, test_utils_1.filePath)('bar.ts'),
972
+ file: filePath('bar.ts'),
926
973
  refactor: 'Convert parameters to destructured object',
927
974
  startLine: 2,
928
975
  startOffset: 26
@@ -935,7 +982,7 @@ describe('code actions', () => {
935
982
  title: 'Convert parameters to destructured object'
936
983
  }
937
984
  ]);
938
- })).timeout(10000);
985
+ }));
939
986
  it('does not provide organize imports when there are errors', () => __awaiter(void 0, void 0, void 0, function* () {
940
987
  server.didOpenTextDocument({
941
988
  textDocument: doc
@@ -957,14 +1004,14 @@ describe('code actions', () => {
957
1004
  code: 6133,
958
1005
  message: 'unused arg'
959
1006
  }],
960
- only: [types_1.CodeActionKind.SourceOrganizeImportsTs.value]
1007
+ only: [CodeActionKind.SourceOrganizeImportsTs.value]
961
1008
  }
962
1009
  }));
963
1010
  assert.deepEqual(result, []);
964
- })).timeout(10000);
1011
+ }));
965
1012
  it('provides "add missing imports" when explicitly requested in only', () => __awaiter(void 0, void 0, void 0, function* () {
966
1013
  const doc = {
967
- uri: (0, test_utils_1.uri)('bar.ts'),
1014
+ uri: uri('bar.ts'),
968
1015
  languageId: 'typescript',
969
1016
  version: 1,
970
1017
  text: 'existsSync(\'t\');'
@@ -982,12 +1029,12 @@ describe('code actions', () => {
982
1029
  },
983
1030
  context: {
984
1031
  diagnostics: [],
985
- only: [types_1.CodeActionKind.SourceAddMissingImportsTs.value]
1032
+ only: [CodeActionKind.SourceAddMissingImportsTs.value]
986
1033
  }
987
1034
  }));
988
1035
  assert.deepEqual(result, [
989
1036
  {
990
- kind: types_1.CodeActionKind.SourceAddMissingImportsTs.value,
1037
+ kind: CodeActionKind.SourceAddMissingImportsTs.value,
991
1038
  title: 'Add all missing imports',
992
1039
  edit: {
993
1040
  documentChanges: [
@@ -1009,7 +1056,7 @@ describe('code actions', () => {
1009
1056
  }
1010
1057
  ],
1011
1058
  textDocument: {
1012
- uri: (0, test_utils_1.uri)('bar.ts'),
1059
+ uri: uri('bar.ts'),
1013
1060
  version: 1
1014
1061
  }
1015
1062
  }
@@ -1017,10 +1064,10 @@ describe('code actions', () => {
1017
1064
  }
1018
1065
  }
1019
1066
  ]);
1020
- })).timeout(10000);
1067
+ }));
1021
1068
  it('provides "fix all" when explicitly requested in only', () => __awaiter(void 0, void 0, void 0, function* () {
1022
1069
  const doc = {
1023
- uri: (0, test_utils_1.uri)('bar.ts'),
1070
+ uri: uri('bar.ts'),
1024
1071
  languageId: 'typescript',
1025
1072
  version: 1,
1026
1073
  text: `function foo() {
@@ -1041,12 +1088,12 @@ describe('code actions', () => {
1041
1088
  },
1042
1089
  context: {
1043
1090
  diagnostics: [],
1044
- only: [types_1.CodeActionKind.SourceFixAllTs.value]
1091
+ only: [CodeActionKind.SourceFixAllTs.value]
1045
1092
  }
1046
1093
  }));
1047
1094
  assert.deepEqual(result, [
1048
1095
  {
1049
- kind: types_1.CodeActionKind.SourceFixAllTs.value,
1096
+ kind: CodeActionKind.SourceFixAllTs.value,
1050
1097
  title: 'Fix all',
1051
1098
  edit: {
1052
1099
  documentChanges: [
@@ -1067,7 +1114,7 @@ describe('code actions', () => {
1067
1114
  }
1068
1115
  ],
1069
1116
  textDocument: {
1070
- uri: (0, test_utils_1.uri)('bar.ts'),
1117
+ uri: uri('bar.ts'),
1071
1118
  version: 1
1072
1119
  }
1073
1120
  }
@@ -1075,10 +1122,10 @@ describe('code actions', () => {
1075
1122
  }
1076
1123
  }
1077
1124
  ]);
1078
- })).timeout(10000);
1125
+ }));
1079
1126
  it('provides organize imports when explicitly requested in only', () => __awaiter(void 0, void 0, void 0, function* () {
1080
1127
  const doc = {
1081
- uri: (0, test_utils_1.uri)('bar.ts'),
1128
+ uri: uri('bar.ts'),
1082
1129
  languageId: 'typescript',
1083
1130
  version: 1,
1084
1131
  text: `import { existsSync } from 'fs';
@@ -1103,12 +1150,12 @@ existsSync('t');`
1103
1150
  code: 6133,
1104
1151
  message: 'unused arg'
1105
1152
  }],
1106
- only: [types_1.CodeActionKind.SourceOrganizeImportsTs.value]
1153
+ only: [CodeActionKind.SourceOrganizeImportsTs.value]
1107
1154
  }
1108
1155
  }));
1109
1156
  assert.deepEqual(result, [
1110
1157
  {
1111
- kind: types_1.CodeActionKind.SourceOrganizeImportsTs.value,
1158
+ kind: CodeActionKind.SourceOrganizeImportsTs.value,
1112
1159
  title: 'Organize imports',
1113
1160
  edit: {
1114
1161
  documentChanges: [
@@ -1142,7 +1189,7 @@ existsSync('t');`
1142
1189
  }
1143
1190
  ],
1144
1191
  textDocument: {
1145
- uri: (0, test_utils_1.uri)('bar.ts'),
1192
+ uri: uri('bar.ts'),
1146
1193
  version: 1
1147
1194
  }
1148
1195
  }
@@ -1150,10 +1197,10 @@ existsSync('t');`
1150
1197
  }
1151
1198
  }
1152
1199
  ]);
1153
- })).timeout(10000);
1200
+ }));
1154
1201
  it('provides "remove unused" when explicitly requested in only', () => __awaiter(void 0, void 0, void 0, function* () {
1155
1202
  const doc = {
1156
- uri: (0, test_utils_1.uri)('bar.ts'),
1203
+ uri: uri('bar.ts'),
1157
1204
  languageId: 'typescript',
1158
1205
  version: 1,
1159
1206
  text: 'import { existsSync } from \'fs\';'
@@ -1166,17 +1213,17 @@ existsSync('t');`
1166
1213
  const result = (yield server.codeAction({
1167
1214
  textDocument: doc,
1168
1215
  range: {
1169
- start: (0, test_utils_1.position)(doc, 'existsSync'),
1170
- end: (0, test_utils_1.positionAfter)(doc, 'existsSync')
1216
+ start: position(doc, 'existsSync'),
1217
+ end: positionAfter(doc, 'existsSync')
1171
1218
  },
1172
1219
  context: {
1173
1220
  diagnostics: [],
1174
- only: [types_1.CodeActionKind.SourceRemoveUnusedTs.value]
1221
+ only: [CodeActionKind.SourceRemoveUnusedTs.value]
1175
1222
  }
1176
1223
  }));
1177
1224
  assert.deepEqual(result, [
1178
1225
  {
1179
- kind: types_1.CodeActionKind.SourceRemoveUnusedTs.value,
1226
+ kind: CodeActionKind.SourceRemoveUnusedTs.value,
1180
1227
  title: 'Remove all unused code',
1181
1228
  edit: {
1182
1229
  documentChanges: [
@@ -1197,7 +1244,7 @@ existsSync('t');`
1197
1244
  }
1198
1245
  ],
1199
1246
  textDocument: {
1200
- uri: (0, test_utils_1.uri)('bar.ts'),
1247
+ uri: uri('bar.ts'),
1201
1248
  version: 1
1202
1249
  }
1203
1250
  }
@@ -1205,10 +1252,10 @@ existsSync('t');`
1205
1252
  }
1206
1253
  }
1207
1254
  ]);
1208
- })).timeout(10000);
1255
+ }));
1209
1256
  it('only provides the "source.fixAll" kind if requested in only', () => __awaiter(void 0, void 0, void 0, function* () {
1210
1257
  const doc = {
1211
- uri: (0, test_utils_1.uri)('bar.ts'),
1258
+ uri: uri('bar.ts'),
1212
1259
  languageId: 'typescript',
1213
1260
  version: 1,
1214
1261
  text: `
@@ -1228,17 +1275,17 @@ existsSync('t');`
1228
1275
  textDocument: doc,
1229
1276
  range: {
1230
1277
  start: { line: 0, character: 0 },
1231
- end: (0, test_utils_1.lastPosition)(doc, '}')
1278
+ end: lastPosition(doc, '}')
1232
1279
  },
1233
1280
  context: {
1234
1281
  diagnostics: [],
1235
- only: [types_1.CodeActionKind.SourceFixAllTs.value]
1282
+ only: [CodeActionKind.SourceFixAllTs.value]
1236
1283
  }
1237
1284
  }));
1238
1285
  assert.strictEqual(result.length, 1, JSON.stringify(result, null, 2));
1239
1286
  assert.deepEqual(result, [
1240
1287
  {
1241
- kind: types_1.CodeActionKind.SourceFixAllTs.value,
1288
+ kind: CodeActionKind.SourceFixAllTs.value,
1242
1289
  title: 'Fix all',
1243
1290
  edit: {
1244
1291
  documentChanges: [
@@ -1259,7 +1306,7 @@ existsSync('t');`
1259
1306
  }
1260
1307
  ],
1261
1308
  textDocument: {
1262
- uri: (0, test_utils_1.uri)('bar.ts'),
1309
+ uri: uri('bar.ts'),
1263
1310
  version: 1
1264
1311
  }
1265
1312
  }
@@ -1267,12 +1314,84 @@ existsSync('t');`
1267
1314
  }
1268
1315
  }
1269
1316
  ]);
1270
- })).timeout(10000);
1317
+ }));
1318
+ });
1319
+ describe('executeCommand', () => {
1320
+ it('apply refactoring (move to new file)', () => __awaiter(void 0, void 0, void 0, function* () {
1321
+ const fooUri = uri('foo.ts');
1322
+ const doc = {
1323
+ uri: fooUri,
1324
+ languageId: 'typescript',
1325
+ version: 1,
1326
+ text: 'export function fn(): void {}\nexport function newFn(): void {}'
1327
+ };
1328
+ server.didOpenTextDocument({
1329
+ textDocument: doc
1330
+ });
1331
+ const codeActions = (yield server.codeAction({
1332
+ textDocument: doc,
1333
+ range: {
1334
+ start: position(doc, 'newFn'),
1335
+ end: position(doc, 'newFn')
1336
+ },
1337
+ context: {
1338
+ diagnostics: []
1339
+ }
1340
+ }));
1341
+ // Find refactoring code action.
1342
+ const applyRefactoringAction = codeActions.find(action => { var _a; return ((_a = action.command) === null || _a === void 0 ? void 0 : _a.command) === Commands.APPLY_REFACTORING; });
1343
+ assert.isDefined(applyRefactoringAction);
1344
+ // Execute refactoring action.
1345
+ yield server.executeCommand({
1346
+ command: applyRefactoringAction.command.command,
1347
+ arguments: applyRefactoringAction.command.arguments
1348
+ });
1349
+ assert.equal(1, server.workspaceEdits.length);
1350
+ const { changes } = server.workspaceEdits[0].edit;
1351
+ assert.isDefined(changes);
1352
+ assert.equal(2, Object.keys(changes).length);
1353
+ const change1 = changes[fooUri];
1354
+ assert.isDefined(change1);
1355
+ const change2 = changes[uri('newFn.ts')];
1356
+ assert.isDefined(change2);
1357
+ // Clean up file that is created on applying edit.
1358
+ fs.unlinkSync(filePath('newFn.ts'));
1359
+ assert.deepEqual(change1, [
1360
+ {
1361
+ range: {
1362
+ start: {
1363
+ line: 1,
1364
+ character: 0
1365
+ },
1366
+ end: {
1367
+ line: 1,
1368
+ character: 32
1369
+ }
1370
+ },
1371
+ newText: ''
1372
+ }
1373
+ ]);
1374
+ assert.deepEqual(change2, [
1375
+ {
1376
+ range: {
1377
+ start: {
1378
+ line: 0,
1379
+ character: 0
1380
+ },
1381
+ end: {
1382
+ line: 0,
1383
+ character: 0
1384
+ }
1385
+ },
1386
+ newText: 'export function newFn(): void { }\n'
1387
+ }
1388
+ ]);
1389
+ }));
1271
1390
  });
1272
1391
  describe('documentHighlight', () => {
1273
1392
  it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
1274
1393
  const barDoc = {
1275
- uri: (0, test_utils_1.uri)('bar.d.ts'),
1394
+ uri: uri('bar.d.ts'),
1276
1395
  languageId: 'typescript',
1277
1396
  version: 1,
1278
1397
  text: `
@@ -1285,7 +1404,7 @@ describe('documentHighlight', () => {
1285
1404
  textDocument: barDoc
1286
1405
  });
1287
1406
  const fooDoc = {
1288
- uri: (0, test_utils_1.uri)('bar.ts'),
1407
+ uri: uri('bar.ts'),
1289
1408
  languageId: 'typescript',
1290
1409
  version: 1,
1291
1410
  text: `
@@ -1299,10 +1418,10 @@ describe('documentHighlight', () => {
1299
1418
  });
1300
1419
  const result = yield server.documentHighlight({
1301
1420
  textDocument: fooDoc,
1302
- position: (0, test_utils_1.lastPosition)(fooDoc, 'Bar')
1421
+ position: lastPosition(fooDoc, 'Bar')
1303
1422
  });
1304
1423
  assert.equal(2, result.length, JSON.stringify(result, undefined, 2));
1305
- })).timeout(10000);
1424
+ }));
1306
1425
  });
1307
1426
  describe('calls', () => {
1308
1427
  function resultToString(callsResult, direction) {
@@ -1322,7 +1441,7 @@ describe('calls', () => {
1322
1441
  return out.join('\n');
1323
1442
  }
1324
1443
  const doDoc = {
1325
- uri: (0, test_utils_1.uri)('do.ts'),
1444
+ uri: uri('do.ts'),
1326
1445
  languageId: 'typescript',
1327
1446
  version: 1,
1328
1447
  text: `
@@ -1340,7 +1459,7 @@ export function three() {
1340
1459
  `
1341
1460
  };
1342
1461
  const fooDoc = {
1343
- uri: (0, test_utils_1.uri)('foo.ts'),
1462
+ uri: uri('foo.ts'),
1344
1463
  languageId: 'typescript',
1345
1464
  version: 1,
1346
1465
  text: `import { doStuff } from './do';
@@ -1357,18 +1476,14 @@ export function factory() {
1357
1476
  `
1358
1477
  };
1359
1478
  function openDocuments() {
1360
- server.didOpenTextDocument({
1361
- textDocument: doDoc
1362
- });
1363
- server.didOpenTextDocument({
1364
- textDocument: fooDoc
1365
- });
1479
+ server.didOpenTextDocument({ textDocument: doDoc });
1480
+ server.didOpenTextDocument({ textDocument: fooDoc });
1366
1481
  }
1367
1482
  it('callers: first step', () => __awaiter(void 0, void 0, void 0, function* () {
1368
1483
  openDocuments();
1369
1484
  const callsResult = yield server.calls({
1370
1485
  textDocument: fooDoc,
1371
- position: lsp.Position.create(3, 9)
1486
+ position: position(fooDoc, 'doStuff();')
1372
1487
  });
1373
1488
  assert.equal(resultToString(callsResult, lspcalls.CallDirection.Incoming), `
1374
1489
  ↘ doStuff (do.ts#1)
@@ -1376,61 +1491,72 @@ export function factory() {
1376
1491
  ↘ doSomething (foo.ts#2) - foo.ts#3
1377
1492
  ↘ x (foo.ts#4) - foo.ts#4
1378
1493
  `.trim());
1379
- })).timeout(10000);
1494
+ }));
1380
1495
  it('callers: second step', () => __awaiter(void 0, void 0, void 0, function* () {
1381
1496
  openDocuments();
1382
1497
  const callsResult = yield server.calls({
1383
1498
  textDocument: fooDoc,
1384
- position: lsp.Position.create(2, 5)
1499
+ position: position(fooDoc, 'doSomething() {')
1385
1500
  });
1386
1501
  assert.equal(resultToString(callsResult, lspcalls.CallDirection.Incoming), `
1387
1502
  ↘ doSomething (foo.ts#2)
1388
1503
  ↘ factory (foo.ts#8) - foo.ts#9
1389
1504
  `.trim());
1390
- })).timeout(10000);
1391
- it('callees: first step', () => __awaiter(void 0, void 0, void 0, function* () {
1505
+ }));
1506
+ it.skip('callees: first step', () => __awaiter(void 0, void 0, void 0, function* () {
1392
1507
  openDocuments();
1393
1508
  const direction = lspcalls.CallDirection.Outgoing;
1394
1509
  const callsResult = yield server.calls({
1395
1510
  direction,
1396
1511
  textDocument: fooDoc,
1397
- position: lsp.Position.create(3, 9)
1512
+ position: position(fooDoc, 'doStuff()')
1398
1513
  });
1399
1514
  assert.equal(resultToString(callsResult, direction), `
1400
1515
  ↖ doStuff (do.ts#1)
1401
1516
  ↖ two (do.ts#4) - do.ts#2
1402
1517
  `.trim());
1403
- })).timeout(10000);
1404
- it('callees: second step', () => __awaiter(void 0, void 0, void 0, function* () {
1518
+ }));
1519
+ it.skip('callees: second step', () => __awaiter(void 0, void 0, void 0, function* () {
1405
1520
  openDocuments();
1406
1521
  const direction = lspcalls.CallDirection.Outgoing;
1407
1522
  const callsResult = yield server.calls({
1408
1523
  direction,
1409
1524
  textDocument: doDoc,
1410
- position: lsp.Position.create(4, 17)
1525
+ position: position(doDoc, 'function two()')
1411
1526
  });
1412
1527
  assert.equal(resultToString(callsResult, direction), `
1413
1528
  ↖ two (do.ts#4)
1414
1529
  ↖ three (do.ts#9) - do.ts#5
1415
1530
  ↖ ttt (do.ts#6) - do.ts#7
1416
1531
  `.trim());
1417
- })).timeout(10000);
1532
+ }));
1418
1533
  });
1419
1534
  describe('diagnostics (no client support)', () => {
1535
+ let localServer;
1420
1536
  before(() => __awaiter(void 0, void 0, void 0, function* () {
1421
1537
  var _a;
1422
1538
  // Remove the "textDocument.publishDiagnostics" client capability.
1423
- const clientCapabilitiesOverride = (0, test_utils_1.getDefaultClientCapabilities)();
1539
+ const clientCapabilitiesOverride = getDefaultClientCapabilities();
1424
1540
  (_a = clientCapabilitiesOverride.textDocument) === null || _a === void 0 ? true : delete _a.publishDiagnostics;
1425
- server = yield (0, test_utils_1.createServer)({
1541
+ localServer = yield createServer({
1426
1542
  rootUri: null,
1427
1543
  publishDiagnostics: args => diagnostics.set(args.uri, args),
1428
1544
  clientCapabilitiesOverride
1429
1545
  });
1430
1546
  }));
1547
+ beforeEach(() => {
1548
+ localServer.closeAll();
1549
+ // "closeAll" triggers final publishDiagnostics with an empty list so clear last.
1550
+ diagnostics.clear();
1551
+ localServer.workspaceEdits = [];
1552
+ });
1553
+ after(() => {
1554
+ localServer.closeAll();
1555
+ localServer.shutdown();
1556
+ });
1431
1557
  it('diagnostics are published', () => __awaiter(void 0, void 0, void 0, function* () {
1432
1558
  const doc = {
1433
- uri: (0, test_utils_1.uri)('diagnosticsBar.ts'),
1559
+ uri: uri('diagnosticsBar.ts'),
1434
1560
  languageId: 'typescript',
1435
1561
  version: 1,
1436
1562
  text: `
@@ -1439,78 +1565,77 @@ describe('diagnostics (no client support)', () => {
1439
1565
  }
1440
1566
  `
1441
1567
  };
1442
- server.didOpenTextDocument({
1568
+ localServer.didOpenTextDocument({
1443
1569
  textDocument: doc
1444
1570
  });
1445
- yield server.requestDiagnostics();
1571
+ yield localServer.requestDiagnostics();
1446
1572
  yield new Promise(resolve => setTimeout(resolve, 200));
1447
1573
  const resultsForFile = diagnostics.get(doc.uri);
1448
1574
  assert.isDefined(resultsForFile);
1449
1575
  assert.strictEqual(resultsForFile === null || resultsForFile === void 0 ? void 0 : resultsForFile.diagnostics.length, 1);
1450
- })).timeout(10000);
1576
+ }));
1451
1577
  });
1452
1578
  describe('jsx/tsx project', () => {
1579
+ let localServer;
1453
1580
  before(() => __awaiter(void 0, void 0, void 0, function* () {
1454
- server = yield (0, test_utils_1.createServer)({
1455
- rootUri: (0, test_utils_1.uri)('jsx'),
1581
+ localServer = yield createServer({
1582
+ rootUri: uri('jsx'),
1456
1583
  publishDiagnostics: args => diagnostics.set(args.uri, args)
1457
1584
  });
1458
1585
  }));
1586
+ beforeEach(() => {
1587
+ localServer.closeAll();
1588
+ // "closeAll" triggers final publishDiagnostics with an empty list so clear last.
1589
+ diagnostics.clear();
1590
+ localServer.workspaceEdits = [];
1591
+ });
1592
+ after(() => {
1593
+ localServer.closeAll();
1594
+ localServer.shutdown();
1595
+ });
1459
1596
  it('includes snippet completion for element prop', () => __awaiter(void 0, void 0, void 0, function* () {
1460
1597
  const doc = {
1461
- uri: (0, test_utils_1.uri)('jsx', 'app.tsx'),
1598
+ uri: uri('jsx', 'app.tsx'),
1462
1599
  languageId: 'typescriptreact',
1463
1600
  version: 1,
1464
- text: (0, test_utils_1.readContents)((0, test_utils_1.filePath)('jsx', 'app.tsx'))
1601
+ text: readContents(filePath('jsx', 'app.tsx'))
1465
1602
  };
1466
- server.didOpenTextDocument({
1603
+ localServer.didOpenTextDocument({
1467
1604
  textDocument: doc
1468
1605
  });
1469
- const completion = yield server.completion({ textDocument: doc, position: (0, test_utils_1.position)(doc, 'title') });
1606
+ const completion = yield localServer.completion({ textDocument: doc, position: position(doc, 'title') });
1470
1607
  assert.isNotNull(completion);
1471
1608
  const item = completion.items.find(i => i.label === 'title');
1472
1609
  assert.isDefined(item);
1473
1610
  assert.strictEqual(item === null || item === void 0 ? void 0 : item.insertTextFormat, 2);
1474
- })).timeout(10000);
1611
+ }));
1475
1612
  });
1476
1613
  describe('inlayHints', () => {
1477
- it('inlayHints', () => __awaiter(void 0, void 0, void 0, function* () {
1478
- const doc = {
1479
- uri: (0, test_utils_1.uri)('module.ts'),
1480
- languageId: 'typescript',
1481
- version: 1,
1482
- text: `
1483
- export function foo() {
1484
- return 3
1485
- }
1486
- `
1487
- };
1488
- yield server.initialize({
1489
- initializationOptions: {
1490
- preferences: {
1491
- includeInlayFunctionLikeReturnTypeHints: true
1614
+ before(() => __awaiter(void 0, void 0, void 0, function* () {
1615
+ server.didChangeConfiguration({
1616
+ settings: {
1617
+ typescript: {
1618
+ inlayHints: {
1619
+ includeInlayFunctionLikeReturnTypeHints: true
1620
+ }
1492
1621
  }
1493
- },
1494
- processId: null,
1495
- capabilities: (0, test_utils_1.getDefaultClientCapabilities)(),
1496
- workspaceFolders: [],
1497
- rootUri: ''
1498
- });
1499
- server.didOpenTextDocument({
1500
- textDocument: doc
1622
+ }
1501
1623
  });
1502
- const { inlayHints } = yield server.inlayHints({
1503
- textDocument: doc
1624
+ }));
1625
+ after(() => {
1626
+ server.didChangeConfiguration({
1627
+ settings: {
1628
+ typescript: {
1629
+ inlayHints: {
1630
+ includeInlayFunctionLikeReturnTypeHints: false
1631
+ }
1632
+ }
1633
+ }
1504
1634
  });
1505
- assert.isDefined(inlayHints);
1506
- assert.strictEqual(inlayHints.length, 1);
1507
- assert.strictEqual(inlayHints[0].text, ': number');
1508
- assert.strictEqual(inlayHints[0].kind, 'Type');
1509
- assert.deepStrictEqual(inlayHints[0].position, { line: 1, character: 29 });
1510
- })).timeout(10000);
1511
- it('inlayHints options set through workspace configuration ', () => __awaiter(void 0, void 0, void 0, function* () {
1635
+ });
1636
+ it('inlayHints', () => __awaiter(void 0, void 0, void 0, function* () {
1512
1637
  const doc = {
1513
- uri: (0, test_utils_1.uri)('module.ts'),
1638
+ uri: uri('module.ts'),
1514
1639
  languageId: 'typescript',
1515
1640
  version: 1,
1516
1641
  text: `
@@ -1519,32 +1644,13 @@ describe('inlayHints', () => {
1519
1644
  }
1520
1645
  `
1521
1646
  };
1522
- yield server.initialize({
1523
- processId: null,
1524
- capabilities: (0, test_utils_1.getDefaultClientCapabilities)(),
1525
- workspaceFolders: [],
1526
- rootUri: ''
1527
- });
1528
- server.didChangeConfiguration({
1529
- settings: {
1530
- typescript: {
1531
- inlayHints: {
1532
- includeInlayFunctionLikeReturnTypeHints: true
1533
- }
1534
- }
1535
- }
1536
- });
1537
- server.didOpenTextDocument({
1538
- textDocument: doc
1539
- });
1540
- const { inlayHints } = yield server.inlayHints({
1541
- textDocument: doc
1542
- });
1647
+ server.didOpenTextDocument({ textDocument: doc });
1648
+ const { inlayHints } = yield server.inlayHints({ textDocument: doc });
1543
1649
  assert.isDefined(inlayHints);
1544
1650
  assert.strictEqual(inlayHints.length, 1);
1545
1651
  assert.strictEqual(inlayHints[0].text, ': number');
1546
1652
  assert.strictEqual(inlayHints[0].kind, 'Type');
1547
1653
  assert.deepStrictEqual(inlayHints[0].position, { line: 1, character: 29 });
1548
- })).timeout(10000);
1654
+ }));
1549
1655
  });
1550
1656
  //# sourceMappingURL=lsp-server.spec.js.map