typescript-language-server 0.11.2 → 1.0.0

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