typescript-language-server 0.11.2 → 1.1.1

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 (149) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +160 -27
  3. package/lib/calls.d.ts +3 -3
  4. package/lib/calls.d.ts.map +1 -1
  5. package/lib/calls.js +143 -195
  6. package/lib/calls.js.map +1 -1
  7. package/lib/cli.js +9 -33
  8. package/lib/cli.js.map +1 -1
  9. package/lib/commands.d.ts +1 -0
  10. package/lib/commands.d.ts.map +1 -1
  11. package/lib/commands.js +4 -5
  12. package/lib/commands.js.map +1 -1
  13. package/lib/completion.d.ts +8 -11
  14. package/lib/completion.d.ts.map +1 -1
  15. package/lib/completion.js +121 -163
  16. package/lib/completion.js.map +1 -1
  17. package/lib/configuration-manager.d.ts +47 -0
  18. package/lib/configuration-manager.d.ts.map +1 -0
  19. package/lib/configuration-manager.js +105 -0
  20. package/lib/configuration-manager.js.map +1 -0
  21. package/lib/diagnostic-queue.d.ts +10 -9
  22. package/lib/diagnostic-queue.d.ts.map +1 -1
  23. package/lib/diagnostic-queue.js +13 -21
  24. package/lib/diagnostic-queue.js.map +1 -1
  25. package/lib/document-symbol.d.ts +2 -2
  26. package/lib/document-symbol.d.ts.map +1 -1
  27. package/lib/document-symbol.js +20 -25
  28. package/lib/document-symbol.js.map +1 -1
  29. package/lib/document.d.ts +1 -1
  30. package/lib/document.d.ts.map +1 -1
  31. package/lib/document.js +6 -34
  32. package/lib/document.js.map +1 -1
  33. package/lib/features/fix-all.d.ts +4 -4
  34. package/lib/features/fix-all.d.ts.map +1 -1
  35. package/lib/features/fix-all.js +104 -147
  36. package/lib/features/fix-all.js.map +1 -1
  37. package/lib/features/inlay-hints.d.ts +11 -0
  38. package/lib/features/inlay-hints.d.ts.map +1 -0
  39. package/lib/features/inlay-hints.js +70 -0
  40. package/lib/features/inlay-hints.js.map +1 -0
  41. package/lib/features/source-definition.d.ts +11 -0
  42. package/lib/features/source-definition.d.ts.map +1 -0
  43. package/lib/features/source-definition.js +50 -0
  44. package/lib/features/source-definition.js.map +1 -0
  45. package/lib/file-lsp-server.spec.js +26 -36
  46. package/lib/file-lsp-server.spec.js.map +1 -1
  47. package/lib/hover.d.ts +4 -3
  48. package/lib/hover.d.ts.map +1 -1
  49. package/lib/hover.js +53 -17
  50. package/lib/hover.js.map +1 -1
  51. package/lib/logger.d.ts +12 -4
  52. package/lib/logger.d.ts.map +1 -1
  53. package/lib/logger.js +37 -44
  54. package/lib/logger.js.map +1 -1
  55. package/lib/lsp-client.d.ts +13 -17
  56. package/lib/lsp-client.d.ts.map +1 -1
  57. package/lib/lsp-client.js +32 -91
  58. package/lib/lsp-client.js.map +1 -1
  59. package/lib/lsp-connection.d.ts +1 -1
  60. package/lib/lsp-connection.d.ts.map +1 -1
  61. package/lib/lsp-connection.js +13 -39
  62. package/lib/lsp-connection.js.map +1 -1
  63. package/lib/lsp-protocol.calls.proposed.d.ts +1 -1
  64. package/lib/lsp-protocol.calls.proposed.d.ts.map +1 -1
  65. package/lib/lsp-protocol.calls.proposed.js +7 -32
  66. package/lib/lsp-protocol.calls.proposed.js.map +1 -1
  67. package/lib/lsp-protocol.inlayHints.proposed.d.ts +2 -11
  68. package/lib/lsp-protocol.inlayHints.proposed.d.ts.map +1 -1
  69. package/lib/lsp-protocol.inlayHints.proposed.js +2 -28
  70. package/lib/lsp-protocol.inlayHints.proposed.js.map +1 -1
  71. package/lib/lsp-server.d.ts +27 -28
  72. package/lib/lsp-server.d.ts.map +1 -1
  73. package/lib/lsp-server.js +868 -926
  74. package/lib/lsp-server.js.map +1 -1
  75. package/lib/lsp-server.spec.js +908 -633
  76. package/lib/lsp-server.spec.js.map +1 -1
  77. package/lib/organize-imports.d.ts +3 -3
  78. package/lib/organize-imports.d.ts.map +1 -1
  79. package/lib/organize-imports.js +5 -32
  80. package/lib/organize-imports.js.map +1 -1
  81. package/lib/organize-imports.spec.js +17 -42
  82. package/lib/organize-imports.spec.js.map +1 -1
  83. package/lib/protocol-translation.d.ts +5 -10
  84. package/lib/protocol-translation.d.ts.map +1 -1
  85. package/lib/protocol-translation.js +39 -170
  86. package/lib/protocol-translation.js.map +1 -1
  87. package/lib/quickfix.d.ts +3 -3
  88. package/lib/quickfix.d.ts.map +1 -1
  89. package/lib/quickfix.js +7 -35
  90. package/lib/quickfix.js.map +1 -1
  91. package/lib/refactor.d.ts +2 -2
  92. package/lib/refactor.d.ts.map +1 -1
  93. package/lib/refactor.js +11 -36
  94. package/lib/refactor.js.map +1 -1
  95. package/lib/semantic-tokens.d.ts +1 -1
  96. package/lib/semantic-tokens.d.ts.map +1 -1
  97. package/lib/semantic-tokens.js +1 -5
  98. package/lib/semantic-tokens.js.map +1 -1
  99. package/lib/test-utils.d.ts +8 -5
  100. package/lib/test-utils.d.ts.map +1 -1
  101. package/lib/test-utils.js +132 -127
  102. package/lib/test-utils.js.map +1 -1
  103. package/lib/ts-protocol.d.ts +8 -20
  104. package/lib/ts-protocol.d.ts.map +1 -1
  105. package/lib/ts-protocol.js +4 -31
  106. package/lib/ts-protocol.js.map +1 -1
  107. package/lib/tsp-client.d.ts +46 -43
  108. package/lib/tsp-client.d.ts.map +1 -1
  109. package/lib/tsp-client.js +31 -52
  110. package/lib/tsp-client.js.map +1 -1
  111. package/lib/tsp-client.spec.js +48 -75
  112. package/lib/tsp-client.spec.js.map +1 -1
  113. package/lib/tsp-command-types.d.ts +1 -0
  114. package/lib/tsp-command-types.d.ts.map +1 -1
  115. package/lib/tsp-command-types.js +4 -8
  116. package/lib/tsp-command-types.js.map +1 -1
  117. package/lib/utils/SnippetString.js +1 -4
  118. package/lib/utils/SnippetString.js.map +1 -1
  119. package/lib/utils/api.d.ts +1 -0
  120. package/lib/utils/api.d.ts.map +1 -1
  121. package/lib/utils/api.js +3 -28
  122. package/lib/utils/api.js.map +1 -1
  123. package/lib/utils/configuration.d.ts +2 -2
  124. package/lib/utils/configuration.d.ts.map +1 -1
  125. package/lib/utils/configuration.js +1 -2
  126. package/lib/utils/errorCodes.js +11 -14
  127. package/lib/utils/errorCodes.js.map +1 -1
  128. package/lib/utils/fixNames.js +13 -16
  129. package/lib/utils/fixNames.js.map +1 -1
  130. package/lib/utils/modules-resolver.js +7 -34
  131. package/lib/utils/modules-resolver.js.map +1 -1
  132. package/lib/utils/modules-resolver.spec.d.ts +1 -1
  133. package/lib/utils/modules-resolver.spec.d.ts.map +1 -1
  134. package/lib/utils/modules-resolver.spec.js +11 -34
  135. package/lib/utils/modules-resolver.spec.js.map +1 -1
  136. package/lib/utils/typeConverters.d.ts +20 -2
  137. package/lib/utils/typeConverters.d.ts.map +1 -1
  138. package/lib/utils/typeConverters.js +105 -9
  139. package/lib/utils/typeConverters.js.map +1 -1
  140. package/lib/utils/types.js +2 -29
  141. package/lib/utils/types.js.map +1 -1
  142. package/lib/utils/versionProvider.d.ts +3 -3
  143. package/lib/utils/versionProvider.d.ts.map +1 -1
  144. package/lib/utils/versionProvider.js +52 -60
  145. package/lib/utils/versionProvider.js.map +1 -1
  146. package/lib/utils.d.ts.map +1 -1
  147. package/lib/utils.js +3 -5
  148. package/lib/utils.js.map +1 -1
  149. package/package.json +38 -33
@@ -1,67 +1,33 @@
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
32
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
33
- return new (P || (P = Promise))(function (resolve, reject) {
34
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
35
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
36
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
37
- step((generator = generator.apply(thisArg, _arguments || [])).next());
38
- });
39
- };
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");
7
+ import * as chai from 'chai';
8
+ import fs from 'fs-extra';
9
+ import * as lsp from 'vscode-languageserver';
10
+ import * as lspcalls from './lsp-protocol.calls.proposed.js';
11
+ import { uri, createServer, position, lastPosition, filePath, positionAfter, readContents, toPlatformEOL } from './test-utils.js';
12
+ import { TextDocument } from 'vscode-languageserver-textdocument';
13
+ import { Commands } from './commands.js';
14
+ import { CodeActionKind } from './utils/types.js';
49
15
  const assert = chai.assert;
50
16
  const diagnostics = new Map();
51
17
  let server;
52
- before(() => __awaiter(void 0, void 0, void 0, function* () {
53
- server = yield (0, test_utils_1.createServer)({
54
- rootUri: null,
55
- publishDiagnostics: args => diagnostics.set(args.uri, args)
18
+ before(async () => {
19
+ server = await createServer({
20
+ rootUri: uri(),
21
+ publishDiagnostics: args => diagnostics.set(args.uri, args),
56
22
  });
57
23
  server.didChangeConfiguration({
58
24
  settings: {
59
25
  completions: {
60
- completeFunctionCalls: true
61
- }
62
- }
26
+ completeFunctionCalls: true,
27
+ },
28
+ },
63
29
  });
64
- }));
30
+ });
65
31
  beforeEach(() => {
66
32
  server.closeAll();
67
33
  // "closeAll" triggers final publishDiagnostics with an empty list so clear last.
@@ -70,54 +36,55 @@ beforeEach(() => {
70
36
  });
71
37
  after(() => {
72
38
  server.closeAll();
39
+ server.shutdown();
73
40
  });
74
41
  describe('completion', () => {
75
- it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
42
+ it('simple test', async () => {
76
43
  const doc = {
77
- uri: (0, test_utils_1.uri)('bar.ts'),
44
+ uri: uri('bar.ts'),
78
45
  languageId: 'typescript',
79
46
  version: 1,
80
47
  text: `
81
48
  export function foo(): void {
82
49
  console.log('test')
83
50
  }
84
- `
51
+ `,
85
52
  };
86
53
  server.didOpenTextDocument({
87
- textDocument: doc
54
+ textDocument: doc,
88
55
  });
89
- const pos = (0, test_utils_1.position)(doc, 'console');
90
- const proposals = yield server.completion({ textDocument: doc, position: pos });
56
+ const pos = position(doc, 'console');
57
+ const proposals = await server.completion({ textDocument: doc, position: pos });
91
58
  assert.isNotNull(proposals);
92
59
  assert.isAtLeast(proposals.items.length, 800);
93
60
  const item = proposals.items.find(i => i.label === 'addEventListener');
94
61
  assert.isDefined(item);
95
- const resolvedItem = yield server.completionResolve(item);
62
+ const resolvedItem = await server.completionResolve(item);
96
63
  assert.isNotTrue(resolvedItem.deprecated, 'resolved item is not deprecated');
97
64
  assert.isDefined(resolvedItem.detail);
98
65
  server.didCloseTextDocument({ textDocument: doc });
99
- })).timeout(10000);
100
- it('simple JS test', () => __awaiter(void 0, void 0, void 0, function* () {
66
+ });
67
+ it('simple JS test', async () => {
101
68
  const doc = {
102
- uri: (0, test_utils_1.uri)('bar.js'),
69
+ uri: uri('bar.js'),
103
70
  languageId: 'javascript',
104
71
  version: 1,
105
72
  text: `
106
73
  export function foo() {
107
74
  console.log('test')
108
75
  }
109
- `
76
+ `,
110
77
  };
111
78
  server.didOpenTextDocument({
112
- textDocument: doc
79
+ textDocument: doc,
113
80
  });
114
- const pos = (0, test_utils_1.position)(doc, 'console');
115
- const proposals = yield server.completion({ textDocument: doc, position: pos });
81
+ const pos = position(doc, 'console');
82
+ const proposals = await server.completion({ textDocument: doc, position: pos });
116
83
  assert.isNotNull(proposals);
117
84
  assert.isAtLeast(proposals.items.length, 800);
118
85
  const item = proposals.items.find(i => i.label === 'addEventListener');
119
86
  assert.isDefined(item);
120
- const resolvedItem = yield server.completionResolve(item);
87
+ const resolvedItem = await server.completionResolve(item);
121
88
  assert.isDefined(resolvedItem.detail);
122
89
  const containsInvalidCompletions = proposals.items.reduce((accumulator, current) => {
123
90
  if (accumulator) {
@@ -129,10 +96,10 @@ describe('completion', () => {
129
96
  }, false);
130
97
  assert.isFalse(containsInvalidCompletions);
131
98
  server.didCloseTextDocument({ textDocument: doc });
132
- })).timeout(10000);
133
- it('deprecated by JSDoc', () => __awaiter(void 0, void 0, void 0, function* () {
99
+ });
100
+ it('deprecated by JSDoc', async () => {
134
101
  const doc = {
135
- uri: (0, test_utils_1.uri)('bar.ts'),
102
+ uri: uri('bar.ts'),
136
103
  languageId: 'typescript',
137
104
  version: 1,
138
105
  text: `
@@ -145,58 +112,58 @@ describe('completion', () => {
145
112
  }
146
113
 
147
114
  foo(); // call me
148
- `
115
+ `,
149
116
  };
150
117
  server.didOpenTextDocument({
151
- textDocument: doc
118
+ textDocument: doc,
152
119
  });
153
- const pos = (0, test_utils_1.position)(doc, 'foo(); // call me');
154
- const proposals = yield server.completion({ textDocument: doc, position: pos });
120
+ const pos = position(doc, 'foo(); // call me');
121
+ const proposals = await server.completion({ textDocument: doc, position: pos });
155
122
  assert.isNotNull(proposals);
156
123
  const item = proposals.items.find(i => i.label === 'foo');
157
124
  assert.isDefined(item);
158
- const resolvedItem = yield server.completionResolve(item);
125
+ const resolvedItem = await server.completionResolve(item);
159
126
  assert.isDefined(resolvedItem.detail);
160
127
  assert.isArray(resolvedItem.tags);
161
128
  assert.include(resolvedItem.tags, lsp.CompletionItemTag.Deprecated, 'resolved item is deprecated');
162
129
  server.didCloseTextDocument({ textDocument: doc });
163
- })).timeout(10000);
164
- it('incorrect source location', () => __awaiter(void 0, void 0, void 0, function* () {
130
+ });
131
+ it('incorrect source location', async () => {
165
132
  const doc = {
166
- uri: (0, test_utils_1.uri)('bar.ts'),
133
+ uri: uri('bar.ts'),
167
134
  languageId: 'typescript',
168
135
  version: 1,
169
136
  text: `
170
137
  export function foo(): void {
171
138
  console.log('test')
172
139
  }
173
- `
140
+ `,
174
141
  };
175
142
  server.didOpenTextDocument({
176
- textDocument: doc
143
+ textDocument: doc,
177
144
  });
178
- const pos = (0, test_utils_1.position)(doc, 'foo');
179
- const proposals = yield server.completion({ textDocument: doc, position: pos });
145
+ const pos = position(doc, 'foo');
146
+ const proposals = await server.completion({ textDocument: doc, position: pos });
180
147
  assert.isNull(proposals);
181
148
  server.didCloseTextDocument({ textDocument: doc });
182
- })).timeout(10000);
183
- it('includes completions from global modules', () => __awaiter(void 0, void 0, void 0, function* () {
149
+ });
150
+ it('includes completions from global modules', async () => {
184
151
  const doc = {
185
- uri: (0, test_utils_1.uri)('bar.ts'),
152
+ uri: uri('bar.ts'),
186
153
  languageId: 'typescript',
187
154
  version: 1,
188
- text: 'pathex'
155
+ text: 'pathex',
189
156
  };
190
157
  server.didOpenTextDocument({ textDocument: doc });
191
- const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.position)(doc, 'ex') });
158
+ const proposals = await server.completion({ textDocument: doc, position: position(doc, 'ex') });
192
159
  assert.isNotNull(proposals);
193
160
  const pathExistsCompletion = proposals.items.find(completion => completion.label === 'pathExists');
194
161
  assert.isDefined(pathExistsCompletion);
195
162
  server.didCloseTextDocument({ textDocument: doc });
196
- })).timeout(10000);
197
- it('includes completions with invalid identifier names', () => __awaiter(void 0, void 0, void 0, function* () {
163
+ });
164
+ it('includes completions with invalid identifier names', async () => {
198
165
  const doc = {
199
- uri: (0, test_utils_1.uri)('bar.ts'),
166
+ uri: uri('bar.ts'),
200
167
  languageId: 'typescript',
201
168
  version: 1,
202
169
  text: `
@@ -206,159 +173,159 @@ describe('completion', () => {
206
173
 
207
174
  const foo: Foo
208
175
  foo.i
209
- `
176
+ `,
210
177
  };
211
178
  server.didOpenTextDocument({ textDocument: doc });
212
- const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.positionAfter)(doc, '.i') });
179
+ const proposals = await server.completion({ textDocument: doc, position: positionAfter(doc, '.i') });
213
180
  assert.isNotNull(proposals);
214
181
  const completion = proposals.items.find(completion => completion.label === 'invalid-identifier-name');
215
182
  assert.isDefined(completion);
216
183
  assert.isDefined(completion.textEdit);
217
184
  assert.equal(completion.textEdit.newText, '["invalid-identifier-name"]');
218
185
  server.didCloseTextDocument({ textDocument: doc });
219
- })).timeout(10000);
220
- it('includes detail field with package name for auto-imports', () => __awaiter(void 0, void 0, void 0, function* () {
186
+ });
187
+ it('includes detail field with package name for auto-imports', async () => {
221
188
  const doc = {
222
- uri: (0, test_utils_1.uri)('bar.ts'),
189
+ uri: uri('bar.ts'),
223
190
  languageId: 'typescript',
224
191
  version: 1,
225
- text: 'readFile'
192
+ text: 'readFile',
226
193
  };
227
194
  server.didOpenTextDocument({ textDocument: doc });
228
- const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.positionAfter)(doc, 'readFile') });
195
+ const proposals = await server.completion({ textDocument: doc, position: positionAfter(doc, 'readFile') });
229
196
  assert.isNotNull(proposals);
230
197
  const completion = proposals.items.find(completion => completion.label === 'readFile');
231
198
  assert.isDefined(completion);
232
199
  assert.strictEqual(completion.detail, 'fs');
233
200
  assert.strictEqual(completion.insertTextFormat, /* snippet */ 2);
234
201
  server.didCloseTextDocument({ textDocument: doc });
235
- })).timeout(10000);
236
- it('resolves text edit for auto-import completion', () => __awaiter(void 0, void 0, void 0, function* () {
202
+ });
203
+ it('resolves text edit for auto-import completion', async () => {
237
204
  const doc = {
238
- uri: (0, test_utils_1.uri)('bar.ts'),
205
+ uri: uri('bar.ts'),
239
206
  languageId: 'typescript',
240
207
  version: 1,
241
- text: 'readFile'
208
+ text: 'readFile',
242
209
  };
243
210
  server.didOpenTextDocument({ textDocument: doc });
244
- const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.positionAfter)(doc, 'readFile') });
211
+ const proposals = await server.completion({ textDocument: doc, position: positionAfter(doc, 'readFile') });
245
212
  assert.isNotNull(proposals);
246
213
  const completion = proposals.items.find(completion => completion.label === 'readFile');
247
214
  assert.isDefined(completion);
248
- const resolvedItem = yield server.completionResolve(completion);
215
+ const resolvedItem = await server.completionResolve(completion);
249
216
  assert.deepEqual(resolvedItem.additionalTextEdits, [
250
217
  {
251
218
  newText: 'import { readFile } from "fs";\n\n',
252
219
  range: {
253
220
  end: {
254
221
  character: 0,
255
- line: 0
222
+ line: 0,
256
223
  },
257
224
  start: {
258
225
  character: 0,
259
- line: 0
260
- }
261
- }
262
- }
226
+ line: 0,
227
+ },
228
+ },
229
+ },
263
230
  ]);
264
231
  server.didCloseTextDocument({ textDocument: doc });
265
- })).timeout(10000);
266
- it('resolves text edit for auto-import completion in right format', () => __awaiter(void 0, void 0, void 0, function* () {
232
+ });
233
+ it('resolves text edit for auto-import completion in right format', async () => {
267
234
  server.didChangeConfiguration({
268
235
  settings: {
269
236
  typescript: {
270
237
  format: {
271
238
  semicolons: 'remove',
272
- insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: false
273
- }
274
- }
275
- }
239
+ insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: false,
240
+ },
241
+ },
242
+ },
276
243
  });
277
244
  const doc = {
278
- uri: (0, test_utils_1.uri)('bar.ts'),
245
+ uri: uri('bar.ts'),
279
246
  languageId: 'typescript',
280
247
  version: 1,
281
- text: 'readFile'
248
+ text: 'readFile',
282
249
  };
283
250
  server.didOpenTextDocument({ textDocument: doc });
284
- const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.positionAfter)(doc, 'readFile') });
251
+ const proposals = await server.completion({ textDocument: doc, position: positionAfter(doc, 'readFile') });
285
252
  assert.isNotNull(proposals);
286
253
  const completion = proposals.items.find(completion => completion.label === 'readFile');
287
254
  assert.isDefined(completion);
288
- const resolvedItem = yield server.completionResolve(completion);
255
+ const resolvedItem = await server.completionResolve(completion);
289
256
  assert.deepEqual(resolvedItem.additionalTextEdits, [
290
257
  {
291
258
  newText: 'import {readFile} from "fs"\n\n',
292
259
  range: {
293
260
  end: {
294
261
  character: 0,
295
- line: 0
262
+ line: 0,
296
263
  },
297
264
  start: {
298
265
  character: 0,
299
- line: 0
300
- }
301
- }
302
- }
266
+ line: 0,
267
+ },
268
+ },
269
+ },
303
270
  ]);
304
271
  server.didCloseTextDocument({ textDocument: doc });
305
272
  server.didChangeConfiguration({
306
273
  settings: {
307
274
  completions: {
308
- completeFunctionCalls: true
275
+ completeFunctionCalls: true,
309
276
  },
310
277
  typescript: {
311
278
  format: {
312
279
  semicolons: 'ignore',
313
- insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true
314
- }
315
- }
316
- }
280
+ insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
281
+ },
282
+ },
283
+ },
317
284
  });
318
- })).timeout(10000);
319
- it('resolves a snippet for method completion', () => __awaiter(void 0, void 0, void 0, function* () {
285
+ });
286
+ it('resolves a snippet for method completion', async () => {
320
287
  const doc = {
321
- uri: (0, test_utils_1.uri)('bar.ts'),
288
+ uri: uri('bar.ts'),
322
289
  languageId: 'typescript',
323
290
  version: 1,
324
291
  text: `
325
292
  import fs from 'fs'
326
293
  fs.readFile
327
- `
294
+ `,
328
295
  };
329
296
  server.didOpenTextDocument({ textDocument: doc });
330
- const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.positionAfter)(doc, 'readFile') });
297
+ const proposals = await server.completion({ textDocument: doc, position: positionAfter(doc, 'readFile') });
331
298
  assert.isNotNull(proposals);
332
299
  const completion = proposals.items.find(completion => completion.label === 'readFile');
333
300
  assert.strictEqual(completion.insertTextFormat, lsp.InsertTextFormat.Snippet);
334
301
  assert.strictEqual(completion.label, 'readFile');
335
- const resolvedItem = yield server.completionResolve(completion);
302
+ const resolvedItem = await server.completionResolve(completion);
336
303
  assert.strictEqual(resolvedItem.insertTextFormat, lsp.InsertTextFormat.Snippet);
337
304
  // eslint-disable-next-line no-template-curly-in-string
338
305
  assert.strictEqual(resolvedItem.insertText, 'readFile(${1:path}, ${2:options}, ${3:callback})$0');
339
306
  server.didCloseTextDocument({ textDocument: doc });
340
- })).timeout(10000);
341
- it('includes textEdit for string completion', () => __awaiter(void 0, void 0, void 0, function* () {
307
+ });
308
+ it('includes textEdit for string completion', async () => {
342
309
  const doc = {
343
- uri: (0, test_utils_1.uri)('bar.ts'),
310
+ uri: uri('bar.ts'),
344
311
  languageId: 'typescript',
345
312
  version: 1,
346
313
  text: `
347
314
  function test(value: "fs/read" | "hello/world") {
348
315
  return true;
349
316
  }
350
-
317
+
351
318
  test("fs/")
352
- `
319
+ `,
353
320
  };
354
321
  server.didOpenTextDocument({ textDocument: doc });
355
- const proposals = yield server.completion({
322
+ const proposals = await server.completion({
356
323
  textDocument: doc,
357
- position: (0, test_utils_1.positionAfter)(doc, 'test("fs/'),
324
+ position: positionAfter(doc, 'test("fs/'),
358
325
  context: {
359
326
  triggerCharacter: '/',
360
- triggerKind: 2
361
- }
327
+ triggerKind: 2,
328
+ },
362
329
  });
363
330
  assert.isNotNull(proposals);
364
331
  const completion = proposals.items.find(completion => completion.label === 'fs/read');
@@ -366,38 +333,183 @@ describe('completion', () => {
366
333
  assert.deepStrictEqual(completion.textEdit, {
367
334
  range: {
368
335
  start: { line: 5, character: 20 },
369
- end: { line: 5, character: 23 }
336
+ end: { line: 5, character: 23 },
337
+ },
338
+ newText: 'fs/read',
339
+ });
340
+ });
341
+ it('includes labelDetails with useLabelDetailsInCompletionEntries enabled', async () => {
342
+ const doc = {
343
+ uri: uri('foo.ts'),
344
+ languageId: 'typescript',
345
+ version: 1,
346
+ text: `
347
+ interface IFoo {
348
+ bar(x: number): void;
349
+ }
350
+ const obj: IFoo = {
351
+ /*a*/
352
+ }
353
+ `,
354
+ };
355
+ server.didOpenTextDocument({ textDocument: doc });
356
+ const proposals = await server.completion({
357
+ textDocument: doc,
358
+ position: positionAfter(doc, '/*a*/'),
359
+ });
360
+ assert.isNotNull(proposals);
361
+ assert.lengthOf(proposals.items, 2);
362
+ assert.deepInclude(proposals.items[0], {
363
+ label: 'bar',
364
+ kind: 2,
365
+ insertTextFormat: 2,
366
+ });
367
+ assert.deepInclude(proposals.items[1], {
368
+ label: 'bar',
369
+ labelDetails: {
370
+ detail: '(x)',
371
+ },
372
+ kind: 2,
373
+ insertTextFormat: 2,
374
+ insertText: toPlatformEOL('bar(x) {\n $0\n},'),
375
+ });
376
+ });
377
+ });
378
+ describe('definition', () => {
379
+ it('goes to definition', async () => {
380
+ // NOTE: This test needs to reference files that physically exist for the feature to work.
381
+ const indexUri = uri('source-definition', 'index.ts');
382
+ const indexDoc = {
383
+ uri: indexUri,
384
+ languageId: 'typescript',
385
+ version: 1,
386
+ text: readContents(filePath('source-definition', 'index.ts')),
387
+ };
388
+ server.didOpenTextDocument({ textDocument: indexDoc });
389
+ const definitions = await server.definition({
390
+ textDocument: indexDoc,
391
+ position: position(indexDoc, 'a/*identifier*/'),
392
+ });
393
+ assert.isArray(definitions);
394
+ assert.equal(definitions.length, 1);
395
+ assert.deepEqual(definitions[0], {
396
+ uri: uri('source-definition', 'a.d.ts'),
397
+ range: {
398
+ start: {
399
+ line: 0,
400
+ character: 21,
401
+ },
402
+ end: {
403
+ line: 0,
404
+ character: 22,
405
+ },
406
+ },
407
+ });
408
+ });
409
+ });
410
+ describe('definition (definition link supported)', () => {
411
+ let localServer;
412
+ before(async () => {
413
+ const clientCapabilitiesOverride = {
414
+ textDocument: {
415
+ definition: {
416
+ linkSupport: true,
417
+ },
418
+ },
419
+ };
420
+ localServer = await createServer({
421
+ rootUri: uri('source-definition'),
422
+ publishDiagnostics: args => diagnostics.set(args.uri, args),
423
+ clientCapabilitiesOverride,
424
+ });
425
+ });
426
+ beforeEach(() => {
427
+ localServer.closeAll();
428
+ // "closeAll" triggers final publishDiagnostics with an empty list so clear last.
429
+ diagnostics.clear();
430
+ localServer.workspaceEdits = [];
431
+ });
432
+ after(() => {
433
+ localServer.closeAll();
434
+ localServer.shutdown();
435
+ });
436
+ it('goes to definition', async () => {
437
+ // NOTE: This test needs to reference files that physically exist for the feature to work.
438
+ const indexUri = uri('source-definition', 'index.ts');
439
+ const indexDoc = {
440
+ uri: indexUri,
441
+ languageId: 'typescript',
442
+ version: 1,
443
+ text: readContents(filePath('source-definition', 'index.ts')),
444
+ };
445
+ localServer.didOpenTextDocument({ textDocument: indexDoc });
446
+ const definitions = await localServer.definition({
447
+ textDocument: indexDoc,
448
+ position: position(indexDoc, 'a/*identifier*/'),
449
+ });
450
+ assert.isArray(definitions);
451
+ assert.equal(definitions.length, 1);
452
+ assert.deepEqual(definitions[0], {
453
+ originSelectionRange: {
454
+ start: {
455
+ line: 1,
456
+ character: 0,
457
+ },
458
+ end: {
459
+ line: 1,
460
+ character: 1,
461
+ },
462
+ },
463
+ targetRange: {
464
+ start: {
465
+ line: 0,
466
+ character: 0,
467
+ },
468
+ end: {
469
+ line: 0,
470
+ character: 30,
471
+ },
472
+ },
473
+ targetUri: uri('source-definition', 'a.d.ts'),
474
+ targetSelectionRange: {
475
+ start: {
476
+ line: 0,
477
+ character: 21,
478
+ },
479
+ end: {
480
+ line: 0,
481
+ character: 22,
482
+ },
370
483
  },
371
- newText: 'fs/read'
372
484
  });
373
- })).timeout(10000);
485
+ });
374
486
  });
375
487
  describe('diagnostics', () => {
376
- it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
488
+ it('simple test', async () => {
377
489
  const doc = {
378
- uri: (0, test_utils_1.uri)('diagnosticsBar.ts'),
490
+ uri: uri('diagnosticsBar.ts'),
379
491
  languageId: 'typescript',
380
492
  version: 1,
381
493
  text: `
382
494
  export function foo(): void {
383
495
  missing('test')
384
496
  }
385
- `
497
+ `,
386
498
  };
387
499
  server.didOpenTextDocument({
388
- textDocument: doc
500
+ textDocument: doc,
389
501
  });
390
- yield server.requestDiagnostics();
391
- yield new Promise(resolve => setTimeout(resolve, 200));
502
+ await server.requestDiagnostics();
503
+ await new Promise(resolve => setTimeout(resolve, 200));
392
504
  const resultsForFile = diagnostics.get(doc.uri);
393
505
  assert.isDefined(resultsForFile);
394
506
  const fileDiagnostics = resultsForFile.diagnostics;
395
507
  assert.equal(fileDiagnostics.length, 1);
396
508
  assert.equal("Cannot find name 'missing'.", fileDiagnostics[0].message);
397
- })).timeout(10000);
398
- it('supports diagnostic tags', () => __awaiter(void 0, void 0, void 0, function* () {
509
+ });
510
+ it('supports diagnostic tags', async () => {
399
511
  const doc = {
400
- uri: (0, test_utils_1.uri)('diagnosticsBar.ts'),
512
+ uri: uri('diagnosticsBar.ts'),
401
513
  languageId: 'typescript',
402
514
  version: 1,
403
515
  text: `
@@ -406,13 +518,13 @@ describe('diagnostics', () => {
406
518
  /** @deprecated */
407
519
  function foo(): void {}
408
520
  foo();
409
- `
521
+ `,
410
522
  };
411
523
  server.didOpenTextDocument({
412
- textDocument: doc
524
+ textDocument: doc,
413
525
  });
414
- yield server.requestDiagnostics();
415
- yield new Promise(resolve => setTimeout(resolve, 200));
526
+ await server.requestDiagnostics();
527
+ await new Promise(resolve => setTimeout(resolve, 200));
416
528
  const resultsForFile = diagnostics.get(doc.uri);
417
529
  assert.isDefined(resultsForFile);
418
530
  const fileDiagnostics = resultsForFile.diagnostics;
@@ -423,36 +535,36 @@ describe('diagnostics', () => {
423
535
  const deprecatedDiagnostic = fileDiagnostics.find(d => d.code === 6387);
424
536
  assert.isDefined(deprecatedDiagnostic);
425
537
  assert.deepEqual(deprecatedDiagnostic.tags, [lsp.DiagnosticTag.Deprecated]);
426
- })).timeout(10000);
427
- it('multiple files test', () => __awaiter(void 0, void 0, void 0, function* () {
538
+ });
539
+ it('multiple files test', async () => {
428
540
  const doc = {
429
- uri: (0, test_utils_1.uri)('multipleFileDiagnosticsBar.ts'),
541
+ uri: uri('multipleFileDiagnosticsBar.ts'),
430
542
  languageId: 'typescript',
431
543
  version: 1,
432
544
  text: `
433
545
  export function bar(): void {
434
546
  missing('test')
435
547
  }
436
- `
548
+ `,
437
549
  };
438
550
  const doc2 = {
439
- uri: (0, test_utils_1.uri)('multipleFileDiagnosticsFoo.ts'),
551
+ uri: uri('multipleFileDiagnosticsFoo.ts'),
440
552
  languageId: 'typescript',
441
553
  version: 1,
442
554
  text: `
443
555
  export function foo(): void {
444
556
  missing('test')
445
557
  }
446
- `
558
+ `,
447
559
  };
448
560
  server.didOpenTextDocument({
449
- textDocument: doc
561
+ textDocument: doc,
450
562
  });
451
563
  server.didOpenTextDocument({
452
- textDocument: doc2
564
+ textDocument: doc2,
453
565
  });
454
- yield server.requestDiagnostics();
455
- yield new Promise(resolve => setTimeout(resolve, 200));
566
+ await server.requestDiagnostics();
567
+ await new Promise(resolve => setTimeout(resolve, 200));
456
568
  assert.equal(diagnostics.size, 2);
457
569
  const diagnosticsForDoc = diagnostics.get(doc.uri);
458
570
  const diagnosticsForDoc2 = diagnostics.get(doc2.uri);
@@ -460,17 +572,17 @@ describe('diagnostics', () => {
460
572
  assert.isDefined(diagnosticsForDoc2);
461
573
  assert.equal(diagnosticsForDoc.diagnostics.length, 1, JSON.stringify(diagnostics));
462
574
  assert.equal(diagnosticsForDoc2.diagnostics.length, 1, JSON.stringify(diagnostics));
463
- })).timeout(10000);
464
- it('code 6133 (ununsed variable) is ignored', () => __awaiter(void 0, void 0, void 0, function* () {
575
+ });
576
+ it('code 6133 (ununsed variable) is ignored', async () => {
465
577
  server.didChangeConfiguration({
466
578
  settings: {
467
579
  diagnostics: {
468
- ignoredCodes: [6133]
469
- }
470
- }
580
+ ignoredCodes: [6133],
581
+ },
582
+ },
471
583
  });
472
584
  const doc = {
473
- uri: (0, test_utils_1.uri)('diagnosticsBar2.ts'),
585
+ uri: uri('diagnosticsBar2.ts'),
474
586
  languageId: 'typescript',
475
587
  version: 1,
476
588
  text: `
@@ -478,23 +590,23 @@ describe('diagnostics', () => {
478
590
  const x = 42;
479
591
  return 1;
480
592
  }
481
- `
593
+ `,
482
594
  };
483
595
  server.didOpenTextDocument({
484
- textDocument: doc
596
+ textDocument: doc,
485
597
  });
486
- yield server.requestDiagnostics();
487
- yield new Promise(resolve => setTimeout(resolve, 200));
598
+ await server.requestDiagnostics();
599
+ await new Promise(resolve => setTimeout(resolve, 200));
488
600
  const diagnosticsForThisFile = diagnostics.get(doc.uri);
489
601
  assert.isDefined(diagnosticsForThisFile);
490
602
  const fileDiagnostics = diagnosticsForThisFile.diagnostics;
491
603
  assert.equal(fileDiagnostics.length, 0, JSON.stringify(fileDiagnostics));
492
- })).timeout(10000);
604
+ });
493
605
  });
494
606
  describe('document symbol', () => {
495
- it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
607
+ it('simple test', async () => {
496
608
  const doc = {
497
- uri: (0, test_utils_1.uri)('bar.ts'),
609
+ uri: uri('bar.ts'),
498
610
  languageId: 'typescript',
499
611
  version: 1,
500
612
  text: `
@@ -503,24 +615,21 @@ describe('document symbol', () => {
503
615
  public myFunction(arg: string) {
504
616
  }
505
617
  }
506
- `
618
+ `,
507
619
  };
508
620
  server.didOpenTextDocument({
509
- textDocument: doc
510
- });
511
- const symbols = yield server.documentSymbol({
512
621
  textDocument: doc,
513
- position: lsp.Position.create(1, 1)
514
622
  });
623
+ const symbols = await server.documentSymbol({ textDocument: doc });
515
624
  assert.equal(`
516
625
  Foo
517
626
  foo
518
627
  myFunction
519
628
  `, symbolsAsString(symbols) + '\n');
520
- })).timeout(10000);
521
- it('merges interfaces correctly', () => __awaiter(void 0, void 0, void 0, function* () {
629
+ });
630
+ it('merges interfaces correctly', async () => {
522
631
  const doc = {
523
- uri: (0, test_utils_1.uri)('bar.ts'),
632
+ uri: uri('bar.ts'),
524
633
  languageId: 'typescript',
525
634
  version: 1,
526
635
  text: `
@@ -531,15 +640,12 @@ interface Box {
531
640
 
532
641
  interface Box {
533
642
  scale: number;
534
- }`
643
+ }`,
535
644
  };
536
645
  server.didOpenTextDocument({
537
- textDocument: doc
538
- });
539
- const symbols = yield server.documentSymbol({
540
646
  textDocument: doc,
541
- position: lsp.Position.create(1, 1)
542
647
  });
648
+ const symbols = await server.documentSymbol({ textDocument: doc });
543
649
  assert.equal(`
544
650
  Box
545
651
  height
@@ -547,10 +653,10 @@ Box
547
653
  Box
548
654
  scale
549
655
  `, symbolsAsString(symbols) + '\n');
550
- })).timeout(10000);
551
- it('duplication test', () => __awaiter(void 0, void 0, void 0, function* () {
656
+ });
657
+ it('duplication test', async () => {
552
658
  const doc = {
553
- uri: (0, test_utils_1.uri)('bar.ts'),
659
+ uri: uri('bar.ts'),
554
660
  languageId: 'typescript',
555
661
  version: 1,
556
662
  text: `
@@ -564,15 +670,12 @@ Box
564
670
  public myFunction(arg: string) {
565
671
  }
566
672
  }
567
- `
673
+ `,
568
674
  };
569
675
  server.didOpenTextDocument({
570
- textDocument: doc
571
- });
572
- const symbols = yield server.documentSymbol({
573
676
  textDocument: doc,
574
- position: lsp.Position.create(1, 1)
575
677
  });
678
+ const symbols = await server.documentSymbol({ textDocument: doc });
576
679
  const expectation = `
577
680
  Foo
578
681
  foo
@@ -586,7 +689,7 @@ Foo
586
689
  assert.deepEqual(symbols[0].range, { start: { line: 1, character: 8 }, end: { line: 5, character: 9 } });
587
690
  assert.deepEqual(symbols[1].selectionRange, symbols[1].range);
588
691
  assert.deepEqual(symbols[1].range, { start: { line: 6, character: 8 }, end: { line: 10, character: 9 } });
589
- })).timeout(10000);
692
+ });
590
693
  });
591
694
  function symbolsAsString(symbols, indentation = '') {
592
695
  return symbols.map(symbol => {
@@ -605,18 +708,18 @@ function symbolsAsString(symbols, indentation = '') {
605
708
  }).join('');
606
709
  }
607
710
  describe('editing', () => {
608
- it('open and change', () => __awaiter(void 0, void 0, void 0, function* () {
711
+ it('open and change', async () => {
609
712
  const doc = {
610
- uri: (0, test_utils_1.uri)('openAndChangeBar.ts'),
713
+ uri: uri('openAndChangeBar.ts'),
611
714
  languageId: 'typescript',
612
715
  version: 1,
613
716
  text: `
614
717
  export function foo(): void {
615
718
  }
616
- `
719
+ `,
617
720
  };
618
721
  server.didOpenTextDocument({
619
- textDocument: doc
722
+ textDocument: doc,
620
723
  });
621
724
  server.didChangeTextDocument({
622
725
  textDocument: doc,
@@ -626,142 +729,141 @@ describe('editing', () => {
626
729
  export function foo(): void {
627
730
  missing('test');
628
731
  }
629
- `
630
- }
631
- ]
732
+ `,
733
+ },
734
+ ],
632
735
  });
633
- yield server.requestDiagnostics();
634
- yield new Promise(resolve => setTimeout(resolve, 200));
736
+ await server.requestDiagnostics();
737
+ await new Promise(resolve => setTimeout(resolve, 200));
635
738
  const resultsForFile = diagnostics.get(doc.uri);
636
739
  assert.isDefined(resultsForFile);
637
740
  const fileDiagnostics = resultsForFile.diagnostics;
638
741
  assert.isTrue(fileDiagnostics.length >= 1, fileDiagnostics.map(d => d.message).join(','));
639
742
  assert.equal("Cannot find name 'missing'.", fileDiagnostics[0].message);
640
- })).timeout(10000);
743
+ });
641
744
  });
642
745
  describe('references', () => {
643
- it('respects "includeDeclaration" in the request', () => __awaiter(void 0, void 0, void 0, function* () {
746
+ it('respects "includeDeclaration" in the request', async () => {
644
747
  const doc = {
645
- uri: (0, test_utils_1.uri)('foo.ts'),
748
+ uri: uri('foo.ts'),
646
749
  languageId: 'typescript',
647
750
  version: 1,
648
751
  text: `
649
- export let foo = 1;
650
- foo++;
651
- foo = 1;
652
- `
752
+ function foo() {};
753
+ foo();
754
+ `,
653
755
  };
654
756
  server.didOpenTextDocument({
655
- textDocument: doc
757
+ textDocument: doc,
656
758
  });
657
759
  // Without declaration/definition.
658
- let references = yield server.references({
760
+ const position = lastPosition(doc, 'function foo()');
761
+ let references = await server.references({
659
762
  context: { includeDeclaration: false },
660
763
  textDocument: doc,
661
- position: (0, test_utils_1.lastPosition)(doc, 'foo')
764
+ position,
662
765
  });
663
- assert.strictEqual(references.length, 2);
766
+ assert.strictEqual(references.length, 1);
664
767
  assert.strictEqual(references[0].range.start.line, 2);
665
- assert.strictEqual(references[1].range.start.line, 3);
666
768
  // With declaration/definition.
667
- references = yield server.references({
769
+ references = await server.references({
668
770
  context: { includeDeclaration: true },
669
771
  textDocument: doc,
670
- position: (0, test_utils_1.lastPosition)(doc, 'foo')
772
+ position,
671
773
  });
672
- assert.strictEqual(references.length, 3);
673
- })).timeout(10000);
674
- });
675
- describe('workspace configuration', () => {
676
- it('receives workspace configuration notification', () => __awaiter(void 0, void 0, void 0, function* () {
677
- const doc = {
678
- uri: (0, test_utils_1.uri)('bar.ts'),
679
- languageId: 'typescript',
680
- version: 1,
681
- text: `
682
- export function foo(): void {
683
- console.log('test')
684
- }
685
- `
686
- };
687
- server.didOpenTextDocument({
688
- textDocument: doc
689
- });
690
- server.didChangeConfiguration({
691
- settings: {
692
- typescript: {
693
- format: {
694
- insertSpaceAfterCommaDelimiter: true
695
- }
696
- },
697
- javascript: {
698
- format: {
699
- insertSpaceAfterCommaDelimiter: false
700
- }
701
- }
702
- }
703
- });
704
- const file = (0, test_utils_1.filePath)('bar.ts');
705
- const settings = server.getWorkspacePreferencesForDocument(file);
706
- assert.deepEqual(settings, { format: { insertSpaceAfterCommaDelimiter: true } });
707
- }));
774
+ assert.strictEqual(references.length, 2);
775
+ });
708
776
  });
777
+ // describe('workspace configuration', () => {
778
+ // it('receives workspace configuration notification', async ()=>{
779
+ // const doc = {
780
+ // uri: uri('bar.ts'),
781
+ // languageId: 'typescript',
782
+ // version: 1,
783
+ // text: `
784
+ // export function foo(): void {
785
+ // console.log('test')
786
+ // }
787
+ // `
788
+ // };
789
+ // server.didOpenTextDocument({
790
+ // textDocument: doc
791
+ // });
792
+ // server.didChangeConfiguration({
793
+ // settings: {
794
+ // typescript: {
795
+ // format: {
796
+ // insertSpaceAfterCommaDelimiter: true
797
+ // }
798
+ // },
799
+ // javascript: {
800
+ // format: {
801
+ // insertSpaceAfterCommaDelimiter: false
802
+ // }
803
+ // }
804
+ // }
805
+ // });
806
+ // const file = filePath('bar.ts');
807
+ // const settings = server.getWorkspacePreferencesForDocument(file);
808
+ // assert.deepEqual(settings, { format: { insertSpaceAfterCommaDelimiter: true } });
809
+ // });
810
+ // });
709
811
  describe('formatting', () => {
710
- const uriString = (0, test_utils_1.uri)('bar.ts');
812
+ const uriString = uri('bar.ts');
711
813
  const languageId = 'typescript';
712
814
  const version = 1;
713
- it('full document formatting', () => __awaiter(void 0, void 0, void 0, function* () {
815
+ it('full document formatting', async () => {
714
816
  const text = 'export function foo ( ) : void { }';
715
817
  const textDocument = {
716
- uri: uriString, languageId, version, text
818
+ uri: uriString, languageId, version, text,
717
819
  };
718
820
  server.didOpenTextDocument({ textDocument });
719
- const edits = yield server.documentFormatting({
821
+ const edits = await server.documentFormatting({
720
822
  textDocument,
721
823
  options: {
722
824
  tabSize: 4,
723
- insertSpaces: true
724
- }
825
+ insertSpaces: true,
826
+ },
725
827
  });
726
- const result = vscode_languageserver_textdocument_1.TextDocument.applyEdits(vscode_languageserver_textdocument_1.TextDocument.create(uriString, languageId, version, text), edits);
828
+ const result = TextDocument.applyEdits(TextDocument.create(uriString, languageId, version, text), edits);
727
829
  assert.equal('export function foo(): void { }', result);
728
- })).timeout(10000);
729
- it('indent settings (3 spaces)', () => __awaiter(void 0, void 0, void 0, function* () {
830
+ });
831
+ it('indent settings (3 spaces)', async () => {
730
832
  const text = 'function foo() {\n// some code\n}';
731
833
  const textDocument = {
732
- uri: uriString, languageId, version, text
834
+ uri: uriString, languageId, version, text,
733
835
  };
734
836
  server.didOpenTextDocument({ textDocument });
735
- const edits = yield server.documentFormatting({
837
+ const edits = await server.documentFormatting({
736
838
  textDocument,
737
839
  options: {
738
840
  tabSize: 3,
739
- insertSpaces: true
740
- }
841
+ insertSpaces: true,
842
+ },
741
843
  });
742
- const result = vscode_languageserver_textdocument_1.TextDocument.applyEdits(vscode_languageserver_textdocument_1.TextDocument.create(uriString, languageId, version, text), edits);
844
+ const result = TextDocument.applyEdits(TextDocument.create(uriString, languageId, version, text), edits);
743
845
  assert.equal('function foo() {\n // some code\n}', result);
744
- })).timeout(10000);
745
- it('indent settings (tabs)', () => __awaiter(void 0, void 0, void 0, function* () {
846
+ });
847
+ it('indent settings (tabs)', async () => {
746
848
  const text = 'function foo() {\n// some code\n}';
747
849
  const textDocument = {
748
- uri: uriString, languageId, version, text
850
+ uri: uriString, languageId, version, text,
749
851
  };
750
852
  server.didOpenTextDocument({ textDocument });
751
- const edits = yield server.documentFormatting({
853
+ const edits = await server.documentFormatting({
752
854
  textDocument,
753
855
  options: {
754
856
  tabSize: 4,
755
- insertSpaces: false
756
- }
857
+ insertSpaces: false,
858
+ },
757
859
  });
758
- const result = vscode_languageserver_textdocument_1.TextDocument.applyEdits(vscode_languageserver_textdocument_1.TextDocument.create(uriString, languageId, version, text), edits);
860
+ const result = TextDocument.applyEdits(TextDocument.create(uriString, languageId, version, text), edits);
759
861
  assert.equal('function foo() {\n\t// some code\n}', result);
760
- })).timeout(10000);
761
- it('formatting setting set through workspace configuration', () => __awaiter(void 0, void 0, void 0, function* () {
862
+ });
863
+ it('formatting setting set through workspace configuration', async () => {
762
864
  const text = 'function foo() {\n// some code\n}';
763
865
  const textDocument = {
764
- uri: uriString, languageId, version, text
866
+ uri: uriString, languageId, version, text,
765
867
  };
766
868
  server.didOpenTextDocument({ textDocument });
767
869
  server.didChangeConfiguration({
@@ -769,104 +871,141 @@ describe('formatting', () => {
769
871
  typescript: {
770
872
  format: {
771
873
  newLineCharacter: '\n',
772
- placeOpenBraceOnNewLineForFunctions: true
773
- }
774
- }
775
- }
874
+ placeOpenBraceOnNewLineForFunctions: true,
875
+ },
876
+ },
877
+ },
776
878
  });
777
- const edits = yield server.documentFormatting({
879
+ const edits = await server.documentFormatting({
778
880
  textDocument,
779
881
  options: {
780
882
  tabSize: 4,
781
- insertSpaces: false
782
- }
883
+ insertSpaces: false,
884
+ },
783
885
  });
784
- const result = vscode_languageserver_textdocument_1.TextDocument.applyEdits(vscode_languageserver_textdocument_1.TextDocument.create(uriString, languageId, version, text), edits);
886
+ const result = TextDocument.applyEdits(TextDocument.create(uriString, languageId, version, text), edits);
785
887
  assert.equal('function foo()\n{\n\t// some code\n}', result);
786
- })).timeout(10000);
787
- it('selected range', () => __awaiter(void 0, void 0, void 0, function* () {
888
+ });
889
+ it('selected range', async () => {
788
890
  const text = 'function foo() {\nconst first = 1;\nconst second = 2;\nconst val = foo( "something" );\n//const fourth = 4;\n}';
789
891
  const textDocument = {
790
- uri: uriString, languageId, version, text
892
+ uri: uriString, languageId, version, text,
791
893
  };
792
894
  server.didOpenTextDocument({ textDocument });
793
- const edits = yield server.documentRangeFormatting({
895
+ const edits = await server.documentRangeFormatting({
794
896
  textDocument,
795
897
  range: {
796
898
  start: {
797
899
  line: 2,
798
- character: 0
900
+ character: 0,
799
901
  },
800
902
  end: {
801
903
  line: 3,
802
- character: 30
803
- }
904
+ character: 30,
905
+ },
804
906
  },
805
907
  options: {
806
908
  tabSize: 4,
807
- insertSpaces: true
808
- }
909
+ insertSpaces: true,
910
+ },
809
911
  });
810
- const result = vscode_languageserver_textdocument_1.TextDocument.applyEdits(vscode_languageserver_textdocument_1.TextDocument.create(uriString, languageId, version, text), edits);
912
+ const result = TextDocument.applyEdits(TextDocument.create(uriString, languageId, version, text), edits);
811
913
  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);
914
+ });
813
915
  });
814
916
  describe('signatureHelp', () => {
815
- it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
917
+ it('simple test', async () => {
816
918
  const doc = {
817
- uri: (0, test_utils_1.uri)('bar.ts'),
919
+ uri: uri('bar.ts'),
818
920
  languageId: 'typescript',
819
921
  version: 1,
820
922
  text: `
821
923
  export function foo(bar: string, baz?:boolean): void {}
924
+ export function foo(n: number, baz?: boolean): void
822
925
  foo(param1, param2)
823
- `
926
+ `,
824
927
  };
825
928
  server.didOpenTextDocument({
826
- textDocument: doc
929
+ textDocument: doc,
827
930
  });
828
- let result = (yield server.signatureHelp({
931
+ let result = (await server.signatureHelp({
829
932
  textDocument: doc,
830
- position: (0, test_utils_1.position)(doc, 'param1')
933
+ position: position(doc, 'param1'),
831
934
  }));
935
+ assert.equal(result.signatures.length, 2);
832
936
  assert.equal('bar: string', result.signatures[result.activeSignature].parameters[result.activeParameter].label);
833
- result = (yield server.signatureHelp({
937
+ result = (await server.signatureHelp({
834
938
  textDocument: doc,
835
- position: (0, test_utils_1.position)(doc, 'param2')
939
+ position: position(doc, 'param2'),
836
940
  }));
837
941
  assert.equal('baz?: boolean', result.signatures[result.activeSignature].parameters[result.activeParameter].label);
838
- })).timeout(10000);
942
+ });
943
+ it('retrigger with specific signature active', async () => {
944
+ const doc = {
945
+ uri: uri('bar.ts'),
946
+ languageId: 'typescript',
947
+ version: 1,
948
+ text: `
949
+ export function foo(bar: string, baz?: boolean): void {}
950
+ export function foo(n: number, baz?: boolean): void
951
+ foo(param1, param2)
952
+ `,
953
+ };
954
+ server.didOpenTextDocument({ textDocument: doc });
955
+ let result = await server.signatureHelp({
956
+ textDocument: doc,
957
+ position: position(doc, 'param1'),
958
+ });
959
+ assert.equal(result.signatures.length, 2);
960
+ result = (await server.signatureHelp({
961
+ textDocument: doc,
962
+ position: position(doc, 'param1'),
963
+ context: {
964
+ isRetrigger: true,
965
+ triggerKind: lsp.SignatureHelpTriggerKind.Invoked,
966
+ activeSignatureHelp: {
967
+ signatures: result.signatures,
968
+ activeSignature: 1, // select second signature
969
+ },
970
+ },
971
+ }));
972
+ const { activeSignature, signatures } = result;
973
+ assert.equal(activeSignature, 1);
974
+ assert.deepInclude(signatures[activeSignature], {
975
+ label: 'foo(n: number, baz?: boolean): void',
976
+ });
977
+ });
839
978
  });
840
979
  describe('code actions', () => {
841
980
  const doc = {
842
- uri: (0, test_utils_1.uri)('bar.ts'),
981
+ uri: uri('bar.ts'),
843
982
  languageId: 'typescript',
844
983
  version: 1,
845
984
  text: `import { something } from "something";
846
985
  export function foo(bar: string, baz?:boolean): void {}
847
986
  foo(param1, param2)
848
- `
987
+ `,
849
988
  };
850
- it('can provide quickfix code actions', () => __awaiter(void 0, void 0, void 0, function* () {
989
+ it('can provide quickfix code actions', async () => {
851
990
  server.didOpenTextDocument({
852
- textDocument: doc
991
+ textDocument: doc,
853
992
  });
854
- const result = (yield server.codeAction({
993
+ const result = (await server.codeAction({
855
994
  textDocument: doc,
856
995
  range: {
857
996
  start: { line: 1, character: 25 },
858
- end: { line: 1, character: 49 }
997
+ end: { line: 1, character: 49 },
859
998
  },
860
999
  context: {
861
1000
  diagnostics: [{
862
1001
  range: {
863
1002
  start: { line: 1, character: 25 },
864
- end: { line: 1, character: 49 }
1003
+ end: { line: 1, character: 49 },
865
1004
  },
866
1005
  code: 6133,
867
- message: 'unused arg'
868
- }]
869
- }
1006
+ message: 'unused arg',
1007
+ }],
1008
+ },
870
1009
  }));
871
1010
  assert.strictEqual(result.length, 2);
872
1011
  const quickFixDiagnostic = result.find(diagnostic => diagnostic.kind === 'quickfix');
@@ -881,30 +1020,30 @@ describe('code actions', () => {
881
1020
  documentChanges: [
882
1021
  {
883
1022
  textDocument: {
884
- uri: (0, test_utils_1.uri)('bar.ts'),
885
- version: 1
1023
+ uri: uri('bar.ts'),
1024
+ version: 1,
886
1025
  },
887
1026
  edits: [
888
1027
  {
889
1028
  range: {
890
1029
  start: {
891
1030
  line: 1,
892
- character: 24
1031
+ character: 24,
893
1032
  },
894
1033
  end: {
895
1034
  line: 1,
896
- character: 27
897
- }
1035
+ character: 27,
1036
+ },
898
1037
  },
899
- newText: '_bar'
900
- }
901
- ]
902
- }
903
- ]
904
- }
905
- ]
1038
+ newText: '_bar',
1039
+ },
1040
+ ],
1041
+ },
1042
+ ],
1043
+ },
1044
+ ],
906
1045
  },
907
- kind: 'quickfix'
1046
+ kind: 'quickfix',
908
1047
  });
909
1048
  const refactorDiagnostic = result.find(diagnostic => diagnostic.kind === 'refactor');
910
1049
  assert.isDefined(refactorDiagnostic);
@@ -915,40 +1054,40 @@ describe('code actions', () => {
915
1054
  command: '_typescript.applyRefactoring',
916
1055
  arguments: [
917
1056
  {
918
- file: (0, test_utils_1.filePath)('bar.ts'),
1057
+ file: filePath('bar.ts'),
919
1058
  startLine: 2,
920
1059
  startOffset: 26,
921
1060
  endLine: 2,
922
1061
  endOffset: 50,
923
1062
  refactor: 'Convert parameters to destructured object',
924
- action: 'Convert parameters to destructured object'
925
- }
926
- ]
1063
+ action: 'Convert parameters to destructured object',
1064
+ },
1065
+ ],
927
1066
  },
928
- kind: 'refactor'
1067
+ kind: 'refactor',
929
1068
  });
930
- })).timeout(10000);
931
- it('can filter quickfix code actions filtered by only', () => __awaiter(void 0, void 0, void 0, function* () {
1069
+ });
1070
+ it('can filter quickfix code actions filtered by only', async () => {
932
1071
  server.didOpenTextDocument({
933
- textDocument: doc
1072
+ textDocument: doc,
934
1073
  });
935
- const result = (yield server.codeAction({
1074
+ const result = (await server.codeAction({
936
1075
  textDocument: doc,
937
1076
  range: {
938
1077
  start: { line: 1, character: 25 },
939
- end: { line: 1, character: 49 }
1078
+ end: { line: 1, character: 49 },
940
1079
  },
941
1080
  context: {
942
1081
  diagnostics: [{
943
1082
  range: {
944
1083
  start: { line: 1, character: 25 },
945
- end: { line: 1, character: 49 }
1084
+ end: { line: 1, character: 49 },
946
1085
  },
947
1086
  code: 6133,
948
- message: 'unused arg'
1087
+ message: 'unused arg',
949
1088
  }],
950
- only: ['refactor', 'invalid-action']
951
- }
1089
+ only: ['refactor', 'invalid-action'],
1090
+ },
952
1091
  }));
953
1092
  assert.deepEqual(result, [
954
1093
  {
@@ -958,72 +1097,72 @@ describe('code actions', () => {
958
1097
  action: 'Convert parameters to destructured object',
959
1098
  endLine: 2,
960
1099
  endOffset: 50,
961
- file: (0, test_utils_1.filePath)('bar.ts'),
1100
+ file: filePath('bar.ts'),
962
1101
  refactor: 'Convert parameters to destructured object',
963
1102
  startLine: 2,
964
- startOffset: 26
965
- }
1103
+ startOffset: 26,
1104
+ },
966
1105
  ],
967
1106
  command: '_typescript.applyRefactoring',
968
- title: 'Convert parameters to destructured object'
1107
+ title: 'Convert parameters to destructured object',
969
1108
  },
970
1109
  kind: 'refactor',
971
- title: 'Convert parameters to destructured object'
972
- }
1110
+ title: 'Convert parameters to destructured object',
1111
+ },
973
1112
  ]);
974
- })).timeout(10000);
975
- it('does not provide organize imports when there are errors', () => __awaiter(void 0, void 0, void 0, function* () {
1113
+ });
1114
+ it('does not provide organize imports when there are errors', async () => {
976
1115
  server.didOpenTextDocument({
977
- textDocument: doc
1116
+ textDocument: doc,
978
1117
  });
979
- yield server.requestDiagnostics();
980
- yield new Promise(resolve => setTimeout(resolve, 200));
981
- const result = (yield server.codeAction({
1118
+ await server.requestDiagnostics();
1119
+ await new Promise(resolve => setTimeout(resolve, 200));
1120
+ const result = (await server.codeAction({
982
1121
  textDocument: doc,
983
1122
  range: {
984
1123
  start: { line: 1, character: 29 },
985
- end: { line: 1, character: 53 }
1124
+ end: { line: 1, character: 53 },
986
1125
  },
987
1126
  context: {
988
1127
  diagnostics: [{
989
1128
  range: {
990
1129
  start: { line: 1, character: 25 },
991
- end: { line: 1, character: 49 }
1130
+ end: { line: 1, character: 49 },
992
1131
  },
993
1132
  code: 6133,
994
- message: 'unused arg'
1133
+ message: 'unused arg',
995
1134
  }],
996
- only: [types_1.CodeActionKind.SourceOrganizeImportsTs.value]
997
- }
1135
+ only: [CodeActionKind.SourceOrganizeImportsTs.value],
1136
+ },
998
1137
  }));
999
1138
  assert.deepEqual(result, []);
1000
- })).timeout(10000);
1001
- it('provides "add missing imports" when explicitly requested in only', () => __awaiter(void 0, void 0, void 0, function* () {
1139
+ });
1140
+ it('provides "add missing imports" when explicitly requested in only', async () => {
1002
1141
  const doc = {
1003
- uri: (0, test_utils_1.uri)('bar.ts'),
1142
+ uri: uri('bar.ts'),
1004
1143
  languageId: 'typescript',
1005
1144
  version: 1,
1006
- text: 'existsSync(\'t\');'
1145
+ text: 'existsSync(\'t\');',
1007
1146
  };
1008
1147
  server.didOpenTextDocument({
1009
- textDocument: doc
1148
+ textDocument: doc,
1010
1149
  });
1011
- yield server.requestDiagnostics();
1012
- yield new Promise(resolve => setTimeout(resolve, 200));
1013
- const result = (yield server.codeAction({
1150
+ await server.requestDiagnostics();
1151
+ await new Promise(resolve => setTimeout(resolve, 200));
1152
+ const result = (await server.codeAction({
1014
1153
  textDocument: doc,
1015
1154
  range: {
1016
1155
  start: { line: 1, character: 29 },
1017
- end: { line: 1, character: 53 }
1156
+ end: { line: 1, character: 53 },
1018
1157
  },
1019
1158
  context: {
1020
1159
  diagnostics: [],
1021
- only: [types_1.CodeActionKind.SourceAddMissingImportsTs.value]
1022
- }
1160
+ only: [CodeActionKind.SourceAddMissingImportsTs.value],
1161
+ },
1023
1162
  }));
1024
1163
  assert.deepEqual(result, [
1025
1164
  {
1026
- kind: types_1.CodeActionKind.SourceAddMissingImportsTs.value,
1165
+ kind: CodeActionKind.SourceAddMissingImportsTs.value,
1027
1166
  title: 'Add all missing imports',
1028
1167
  edit: {
1029
1168
  documentChanges: [
@@ -1035,54 +1174,54 @@ describe('code actions', () => {
1035
1174
  range: {
1036
1175
  end: {
1037
1176
  character: 0,
1038
- line: 0
1177
+ line: 0,
1039
1178
  },
1040
1179
  start: {
1041
1180
  character: 0,
1042
- line: 0
1043
- }
1044
- }
1045
- }
1181
+ line: 0,
1182
+ },
1183
+ },
1184
+ },
1046
1185
  ],
1047
1186
  textDocument: {
1048
- uri: (0, test_utils_1.uri)('bar.ts'),
1049
- version: 1
1050
- }
1051
- }
1052
- ]
1053
- }
1054
- }
1187
+ uri: uri('bar.ts'),
1188
+ version: 1,
1189
+ },
1190
+ },
1191
+ ],
1192
+ },
1193
+ },
1055
1194
  ]);
1056
- })).timeout(10000);
1057
- it('provides "fix all" when explicitly requested in only', () => __awaiter(void 0, void 0, void 0, function* () {
1195
+ });
1196
+ it('provides "fix all" when explicitly requested in only', async () => {
1058
1197
  const doc = {
1059
- uri: (0, test_utils_1.uri)('bar.ts'),
1198
+ uri: uri('bar.ts'),
1060
1199
  languageId: 'typescript',
1061
1200
  version: 1,
1062
1201
  text: `function foo() {
1063
1202
  return
1064
1203
  setTimeout(() => {})
1065
- }`
1204
+ }`,
1066
1205
  };
1067
1206
  server.didOpenTextDocument({
1068
- textDocument: doc
1207
+ textDocument: doc,
1069
1208
  });
1070
- yield server.requestDiagnostics();
1071
- yield new Promise(resolve => setTimeout(resolve, 200));
1072
- const result = (yield server.codeAction({
1209
+ await server.requestDiagnostics();
1210
+ await new Promise(resolve => setTimeout(resolve, 200));
1211
+ const result = (await server.codeAction({
1073
1212
  textDocument: doc,
1074
1213
  range: {
1075
1214
  start: { line: 0, character: 0 },
1076
- end: { line: 4, character: 0 }
1215
+ end: { line: 4, character: 0 },
1077
1216
  },
1078
1217
  context: {
1079
1218
  diagnostics: [],
1080
- only: [types_1.CodeActionKind.SourceFixAllTs.value]
1081
- }
1219
+ only: [CodeActionKind.SourceFixAllTs.value],
1220
+ },
1082
1221
  }));
1083
1222
  assert.deepEqual(result, [
1084
1223
  {
1085
- kind: types_1.CodeActionKind.SourceFixAllTs.value,
1224
+ kind: CodeActionKind.SourceFixAllTs.value,
1086
1225
  title: 'Fix all',
1087
1226
  edit: {
1088
1227
  documentChanges: [
@@ -1093,58 +1232,58 @@ describe('code actions', () => {
1093
1232
  range: {
1094
1233
  end: {
1095
1234
  character: 0,
1096
- line: 3
1235
+ line: 3,
1097
1236
  },
1098
1237
  start: {
1099
1238
  character: 0,
1100
- line: 2
1101
- }
1102
- }
1103
- }
1239
+ line: 2,
1240
+ },
1241
+ },
1242
+ },
1104
1243
  ],
1105
1244
  textDocument: {
1106
- uri: (0, test_utils_1.uri)('bar.ts'),
1107
- version: 1
1108
- }
1109
- }
1110
- ]
1111
- }
1112
- }
1245
+ uri: uri('bar.ts'),
1246
+ version: 1,
1247
+ },
1248
+ },
1249
+ ],
1250
+ },
1251
+ },
1113
1252
  ]);
1114
- })).timeout(10000);
1115
- it('provides organize imports when explicitly requested in only', () => __awaiter(void 0, void 0, void 0, function* () {
1253
+ });
1254
+ it('provides organize imports when explicitly requested in only', async () => {
1116
1255
  const doc = {
1117
- uri: (0, test_utils_1.uri)('bar.ts'),
1256
+ uri: uri('bar.ts'),
1118
1257
  languageId: 'typescript',
1119
1258
  version: 1,
1120
1259
  text: `import { existsSync } from 'fs';
1121
1260
  import { accessSync } from 'fs';
1122
- existsSync('t');`
1261
+ existsSync('t');`,
1123
1262
  };
1124
1263
  server.didOpenTextDocument({
1125
- textDocument: doc
1264
+ textDocument: doc,
1126
1265
  });
1127
- const result = (yield server.codeAction({
1266
+ const result = (await server.codeAction({
1128
1267
  textDocument: doc,
1129
1268
  range: {
1130
1269
  start: { line: 0, character: 0 },
1131
- end: { line: 3, character: 0 }
1270
+ end: { line: 3, character: 0 },
1132
1271
  },
1133
1272
  context: {
1134
1273
  diagnostics: [{
1135
1274
  range: {
1136
1275
  start: { line: 1, character: 25 },
1137
- end: { line: 1, character: 49 }
1276
+ end: { line: 1, character: 49 },
1138
1277
  },
1139
1278
  code: 6133,
1140
- message: 'unused arg'
1279
+ message: 'unused arg',
1141
1280
  }],
1142
- only: [types_1.CodeActionKind.SourceOrganizeImportsTs.value]
1143
- }
1281
+ only: [CodeActionKind.SourceOrganizeImportsTs.value],
1282
+ },
1144
1283
  }));
1145
1284
  assert.deepEqual(result, [
1146
1285
  {
1147
- kind: types_1.CodeActionKind.SourceOrganizeImportsTs.value,
1286
+ kind: CodeActionKind.SourceOrganizeImportsTs.value,
1148
1287
  title: 'Organize imports',
1149
1288
  edit: {
1150
1289
  documentChanges: [
@@ -1155,64 +1294,64 @@ existsSync('t');`
1155
1294
  range: {
1156
1295
  end: {
1157
1296
  character: 0,
1158
- line: 1
1297
+ line: 1,
1159
1298
  },
1160
1299
  start: {
1161
1300
  character: 0,
1162
- line: 0
1163
- }
1164
- }
1301
+ line: 0,
1302
+ },
1303
+ },
1165
1304
  },
1166
1305
  {
1167
1306
  newText: '',
1168
1307
  range: {
1169
1308
  end: {
1170
1309
  character: 0,
1171
- line: 2
1310
+ line: 2,
1172
1311
  },
1173
1312
  start: {
1174
1313
  character: 0,
1175
- line: 1
1176
- }
1177
- }
1178
- }
1314
+ line: 1,
1315
+ },
1316
+ },
1317
+ },
1179
1318
  ],
1180
1319
  textDocument: {
1181
- uri: (0, test_utils_1.uri)('bar.ts'),
1182
- version: 1
1183
- }
1184
- }
1185
- ]
1186
- }
1187
- }
1320
+ uri: uri('bar.ts'),
1321
+ version: 1,
1322
+ },
1323
+ },
1324
+ ],
1325
+ },
1326
+ },
1188
1327
  ]);
1189
- })).timeout(10000);
1190
- it('provides "remove unused" when explicitly requested in only', () => __awaiter(void 0, void 0, void 0, function* () {
1328
+ });
1329
+ it('provides "remove unused" when explicitly requested in only', async () => {
1191
1330
  const doc = {
1192
- uri: (0, test_utils_1.uri)('bar.ts'),
1331
+ uri: uri('bar.ts'),
1193
1332
  languageId: 'typescript',
1194
1333
  version: 1,
1195
- text: 'import { existsSync } from \'fs\';'
1334
+ text: 'import { existsSync } from \'fs\';',
1196
1335
  };
1197
1336
  server.didOpenTextDocument({
1198
- textDocument: doc
1337
+ textDocument: doc,
1199
1338
  });
1200
- yield server.requestDiagnostics();
1201
- yield new Promise(resolve => setTimeout(resolve, 200));
1202
- const result = (yield server.codeAction({
1339
+ await server.requestDiagnostics();
1340
+ await new Promise(resolve => setTimeout(resolve, 200));
1341
+ const result = (await server.codeAction({
1203
1342
  textDocument: doc,
1204
1343
  range: {
1205
- start: (0, test_utils_1.position)(doc, 'existsSync'),
1206
- end: (0, test_utils_1.positionAfter)(doc, 'existsSync')
1344
+ start: position(doc, 'existsSync'),
1345
+ end: positionAfter(doc, 'existsSync'),
1207
1346
  },
1208
1347
  context: {
1209
1348
  diagnostics: [],
1210
- only: [types_1.CodeActionKind.SourceRemoveUnusedTs.value]
1211
- }
1349
+ only: [CodeActionKind.SourceRemoveUnusedTs.value],
1350
+ },
1212
1351
  }));
1213
1352
  assert.deepEqual(result, [
1214
1353
  {
1215
- kind: types_1.CodeActionKind.SourceRemoveUnusedTs.value,
1354
+ kind: CodeActionKind.SourceRemoveUnusedTs.value,
1216
1355
  title: 'Remove all unused code',
1217
1356
  edit: {
1218
1357
  documentChanges: [
@@ -1223,28 +1362,28 @@ existsSync('t');`
1223
1362
  range: {
1224
1363
  end: {
1225
1364
  character: 32,
1226
- line: 0
1365
+ line: 0,
1227
1366
  },
1228
1367
  start: {
1229
1368
  character: 0,
1230
- line: 0
1231
- }
1232
- }
1233
- }
1369
+ line: 0,
1370
+ },
1371
+ },
1372
+ },
1234
1373
  ],
1235
1374
  textDocument: {
1236
- uri: (0, test_utils_1.uri)('bar.ts'),
1237
- version: 1
1238
- }
1239
- }
1240
- ]
1241
- }
1242
- }
1375
+ uri: uri('bar.ts'),
1376
+ version: 1,
1377
+ },
1378
+ },
1379
+ ],
1380
+ },
1381
+ },
1243
1382
  ]);
1244
- })).timeout(10000);
1245
- it('only provides the "source.fixAll" kind if requested in only', () => __awaiter(void 0, void 0, void 0, function* () {
1383
+ });
1384
+ it('only provides the "source.fixAll" kind if requested in only', async () => {
1246
1385
  const doc = {
1247
- uri: (0, test_utils_1.uri)('bar.ts'),
1386
+ uri: uri('bar.ts'),
1248
1387
  languageId: 'typescript',
1249
1388
  version: 1,
1250
1389
  text: `
@@ -1253,28 +1392,28 @@ existsSync('t');`
1253
1392
  return
1254
1393
  setTimeout(() => {})
1255
1394
  }
1256
- `
1395
+ `,
1257
1396
  };
1258
1397
  server.didOpenTextDocument({
1259
- textDocument: doc
1398
+ textDocument: doc,
1260
1399
  });
1261
- yield server.requestDiagnostics();
1262
- yield new Promise(resolve => setTimeout(resolve, 200));
1263
- const result = (yield server.codeAction({
1400
+ await server.requestDiagnostics();
1401
+ await new Promise(resolve => setTimeout(resolve, 200));
1402
+ const result = (await server.codeAction({
1264
1403
  textDocument: doc,
1265
1404
  range: {
1266
1405
  start: { line: 0, character: 0 },
1267
- end: (0, test_utils_1.lastPosition)(doc, '}')
1406
+ end: lastPosition(doc, '}'),
1268
1407
  },
1269
1408
  context: {
1270
1409
  diagnostics: [],
1271
- only: [types_1.CodeActionKind.SourceFixAllTs.value]
1272
- }
1410
+ only: [CodeActionKind.SourceFixAllTs.value],
1411
+ },
1273
1412
  }));
1274
1413
  assert.strictEqual(result.length, 1, JSON.stringify(result, null, 2));
1275
1414
  assert.deepEqual(result, [
1276
1415
  {
1277
- kind: types_1.CodeActionKind.SourceFixAllTs.value,
1416
+ kind: CodeActionKind.SourceFixAllTs.value,
1278
1417
  title: 'Fix all',
1279
1418
  edit: {
1280
1419
  documentChanges: [
@@ -1285,55 +1424,55 @@ existsSync('t');`
1285
1424
  range: {
1286
1425
  start: {
1287
1426
  line: 4,
1288
- character: 0
1427
+ character: 0,
1289
1428
  },
1290
1429
  end: {
1291
1430
  line: 5,
1292
- character: 0
1293
- }
1294
- }
1295
- }
1431
+ character: 0,
1432
+ },
1433
+ },
1434
+ },
1296
1435
  ],
1297
1436
  textDocument: {
1298
- uri: (0, test_utils_1.uri)('bar.ts'),
1299
- version: 1
1300
- }
1301
- }
1302
- ]
1303
- }
1304
- }
1437
+ uri: uri('bar.ts'),
1438
+ version: 1,
1439
+ },
1440
+ },
1441
+ ],
1442
+ },
1443
+ },
1305
1444
  ]);
1306
- })).timeout(10000);
1445
+ });
1307
1446
  });
1308
1447
  describe('executeCommand', () => {
1309
- 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');
1448
+ it('apply refactoring (move to new file)', async () => {
1449
+ const fooUri = uri('foo.ts');
1311
1450
  const doc = {
1312
1451
  uri: fooUri,
1313
1452
  languageId: 'typescript',
1314
1453
  version: 1,
1315
- text: 'export function fn(): void {}\nexport function newFn(): void {}'
1454
+ text: 'export function fn(): void {}\nexport function newFn(): void {}',
1316
1455
  };
1317
1456
  server.didOpenTextDocument({
1318
- textDocument: doc
1457
+ textDocument: doc,
1319
1458
  });
1320
- const codeActions = (yield server.codeAction({
1459
+ const codeActions = (await server.codeAction({
1321
1460
  textDocument: doc,
1322
1461
  range: {
1323
- start: (0, test_utils_1.position)(doc, 'newFn'),
1324
- end: (0, test_utils_1.position)(doc, 'newFn')
1462
+ start: position(doc, 'newFn'),
1463
+ end: position(doc, 'newFn'),
1325
1464
  },
1326
1465
  context: {
1327
- diagnostics: []
1328
- }
1466
+ diagnostics: [],
1467
+ },
1329
1468
  }));
1330
1469
  // 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; });
1470
+ const applyRefactoringAction = codeActions.find(action => action.command?.command === Commands.APPLY_REFACTORING);
1332
1471
  assert.isDefined(applyRefactoringAction);
1333
1472
  // Execute refactoring action.
1334
- yield server.executeCommand({
1473
+ await server.executeCommand({
1335
1474
  command: applyRefactoringAction.command.command,
1336
- arguments: applyRefactoringAction.command.arguments
1475
+ arguments: applyRefactoringAction.command.arguments,
1337
1476
  });
1338
1477
  assert.equal(1, server.workspaceEdits.length);
1339
1478
  const { changes } = server.workspaceEdits[0].edit;
@@ -1341,76 +1480,109 @@ describe('executeCommand', () => {
1341
1480
  assert.equal(2, Object.keys(changes).length);
1342
1481
  const change1 = changes[fooUri];
1343
1482
  assert.isDefined(change1);
1344
- const change2 = changes[(0, test_utils_1.uri)('newFn.ts')];
1483
+ const change2 = changes[uri('newFn.ts')];
1345
1484
  assert.isDefined(change2);
1346
1485
  // Clean up file that is created on applying edit.
1347
- fs.unlink((0, test_utils_1.filePath)('newFn.ts'));
1486
+ fs.unlinkSync(filePath('newFn.ts'));
1348
1487
  assert.deepEqual(change1, [
1349
1488
  {
1350
1489
  range: {
1351
1490
  start: {
1352
1491
  line: 1,
1353
- character: 0
1492
+ character: 0,
1354
1493
  },
1355
1494
  end: {
1356
1495
  line: 1,
1357
- character: 32
1358
- }
1496
+ character: 32,
1497
+ },
1359
1498
  },
1360
- newText: ''
1361
- }
1499
+ newText: '',
1500
+ },
1362
1501
  ]);
1363
1502
  assert.deepEqual(change2, [
1364
1503
  {
1365
1504
  range: {
1366
1505
  start: {
1367
1506
  line: 0,
1368
- character: 0
1507
+ character: 0,
1369
1508
  },
1370
1509
  end: {
1371
1510
  line: 0,
1372
- character: 0
1373
- }
1511
+ character: 0,
1512
+ },
1374
1513
  },
1375
- newText: 'export function newFn(): void { }\n'
1376
- }
1514
+ newText: 'export function newFn(): void { }\n',
1515
+ },
1377
1516
  ]);
1378
- })).timeout(10000);
1517
+ });
1518
+ it('go to source definition', async () => {
1519
+ // NOTE: This test needs to reference files that physically exist for the feature to work.
1520
+ const indexUri = uri('source-definition', 'index.ts');
1521
+ const indexDoc = {
1522
+ uri: indexUri,
1523
+ languageId: 'typescript',
1524
+ version: 1,
1525
+ text: readContents(filePath('source-definition', 'index.ts')),
1526
+ };
1527
+ server.didOpenTextDocument({ textDocument: indexDoc });
1528
+ const result = await server.executeCommand({
1529
+ command: Commands.SOURCE_DEFINITION,
1530
+ arguments: [
1531
+ indexUri,
1532
+ position(indexDoc, '/*identifier*/'),
1533
+ ],
1534
+ });
1535
+ assert.isNotNull(result);
1536
+ assert.equal(result.length, 1);
1537
+ assert.deepEqual(result[0], {
1538
+ uri: uri('source-definition', 'a.js'),
1539
+ range: {
1540
+ start: {
1541
+ line: 0,
1542
+ character: 13,
1543
+ },
1544
+ end: {
1545
+ line: 0,
1546
+ character: 14,
1547
+ },
1548
+ },
1549
+ });
1550
+ });
1379
1551
  });
1380
1552
  describe('documentHighlight', () => {
1381
- it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
1553
+ it('simple test', async () => {
1382
1554
  const barDoc = {
1383
- uri: (0, test_utils_1.uri)('bar.d.ts'),
1555
+ uri: uri('bar.d.ts'),
1384
1556
  languageId: 'typescript',
1385
1557
  version: 1,
1386
1558
  text: `
1387
1559
  export declare const Bar: unique symbol;
1388
1560
  export interface Bar {
1389
1561
  }
1390
- `
1562
+ `,
1391
1563
  };
1392
1564
  server.didOpenTextDocument({
1393
- textDocument: barDoc
1565
+ textDocument: barDoc,
1394
1566
  });
1395
1567
  const fooDoc = {
1396
- uri: (0, test_utils_1.uri)('bar.ts'),
1568
+ uri: uri('bar.ts'),
1397
1569
  languageId: 'typescript',
1398
1570
  version: 1,
1399
1571
  text: `
1400
1572
  import { Bar } from './bar';
1401
1573
  export class Foo implements Bar {
1402
1574
  }
1403
- `
1575
+ `,
1404
1576
  };
1405
1577
  server.didOpenTextDocument({
1406
- textDocument: fooDoc
1578
+ textDocument: fooDoc,
1407
1579
  });
1408
- const result = yield server.documentHighlight({
1580
+ const result = await server.documentHighlight({
1409
1581
  textDocument: fooDoc,
1410
- position: (0, test_utils_1.lastPosition)(fooDoc, 'Bar')
1582
+ position: lastPosition(fooDoc, 'Bar'),
1411
1583
  });
1412
1584
  assert.equal(2, result.length, JSON.stringify(result, undefined, 2));
1413
- })).timeout(10000);
1585
+ });
1414
1586
  });
1415
1587
  describe('calls', () => {
1416
1588
  function resultToString(callsResult, direction) {
@@ -1430,7 +1602,7 @@ describe('calls', () => {
1430
1602
  return out.join('\n');
1431
1603
  }
1432
1604
  const doDoc = {
1433
- uri: (0, test_utils_1.uri)('do.ts'),
1605
+ uri: uri('do.ts'),
1434
1606
  languageId: 'typescript',
1435
1607
  version: 1,
1436
1608
  text: `
@@ -1445,10 +1617,10 @@ export function two() {
1445
1617
  export function three() {
1446
1618
  return "".toString();
1447
1619
  }
1448
- `
1620
+ `,
1449
1621
  };
1450
1622
  const fooDoc = {
1451
- uri: (0, test_utils_1.uri)('foo.ts'),
1623
+ uri: uri('foo.ts'),
1452
1624
  languageId: 'typescript',
1453
1625
  version: 1,
1454
1626
  text: `import { doStuff } from './do';
@@ -1462,21 +1634,17 @@ class MyClass {
1462
1634
  export function factory() {
1463
1635
  new MyClass().doSomething();
1464
1636
  }
1465
- `
1637
+ `,
1466
1638
  };
1467
1639
  function openDocuments() {
1468
- server.didOpenTextDocument({
1469
- textDocument: doDoc
1470
- });
1471
- server.didOpenTextDocument({
1472
- textDocument: fooDoc
1473
- });
1640
+ server.didOpenTextDocument({ textDocument: doDoc });
1641
+ server.didOpenTextDocument({ textDocument: fooDoc });
1474
1642
  }
1475
- it('callers: first step', () => __awaiter(void 0, void 0, void 0, function* () {
1643
+ it('callers: first step', async () => {
1476
1644
  openDocuments();
1477
- const callsResult = yield server.calls({
1645
+ const callsResult = await server.calls({
1478
1646
  textDocument: fooDoc,
1479
- position: lsp.Position.create(3, 9)
1647
+ position: position(fooDoc, 'doStuff();'),
1480
1648
  });
1481
1649
  assert.equal(resultToString(callsResult, lspcalls.CallDirection.Incoming), `
1482
1650
  ↘ doStuff (do.ts#1)
@@ -1484,175 +1652,282 @@ export function factory() {
1484
1652
  ↘ doSomething (foo.ts#2) - foo.ts#3
1485
1653
  ↘ x (foo.ts#4) - foo.ts#4
1486
1654
  `.trim());
1487
- })).timeout(10000);
1488
- it('callers: second step', () => __awaiter(void 0, void 0, void 0, function* () {
1655
+ });
1656
+ it('callers: second step', async () => {
1489
1657
  openDocuments();
1490
- const callsResult = yield server.calls({
1658
+ const callsResult = await server.calls({
1491
1659
  textDocument: fooDoc,
1492
- position: lsp.Position.create(2, 5)
1660
+ position: position(fooDoc, 'doSomething() {'),
1493
1661
  });
1494
1662
  assert.equal(resultToString(callsResult, lspcalls.CallDirection.Incoming), `
1495
1663
  ↘ doSomething (foo.ts#2)
1496
1664
  ↘ factory (foo.ts#8) - foo.ts#9
1497
1665
  `.trim());
1498
- })).timeout(10000);
1499
- it('callees: first step', () => __awaiter(void 0, void 0, void 0, function* () {
1666
+ });
1667
+ it.skip('callees: first step', async () => {
1500
1668
  openDocuments();
1501
1669
  const direction = lspcalls.CallDirection.Outgoing;
1502
- const callsResult = yield server.calls({
1670
+ const callsResult = await server.calls({
1503
1671
  direction,
1504
1672
  textDocument: fooDoc,
1505
- position: lsp.Position.create(3, 9)
1673
+ position: position(fooDoc, 'doStuff()'),
1506
1674
  });
1507
1675
  assert.equal(resultToString(callsResult, direction), `
1508
1676
  ↖ doStuff (do.ts#1)
1509
1677
  ↖ two (do.ts#4) - do.ts#2
1510
1678
  `.trim());
1511
- })).timeout(10000);
1512
- it('callees: second step', () => __awaiter(void 0, void 0, void 0, function* () {
1679
+ });
1680
+ it.skip('callees: second step', async () => {
1513
1681
  openDocuments();
1514
1682
  const direction = lspcalls.CallDirection.Outgoing;
1515
- const callsResult = yield server.calls({
1683
+ const callsResult = await server.calls({
1516
1684
  direction,
1517
1685
  textDocument: doDoc,
1518
- position: lsp.Position.create(4, 17)
1686
+ position: position(doDoc, 'function two()'),
1519
1687
  });
1520
1688
  assert.equal(resultToString(callsResult, direction), `
1521
1689
  ↖ two (do.ts#4)
1522
1690
  ↖ three (do.ts#9) - do.ts#5
1523
1691
  ↖ ttt (do.ts#6) - do.ts#7
1524
1692
  `.trim());
1525
- })).timeout(10000);
1693
+ });
1526
1694
  });
1527
1695
  describe('diagnostics (no client support)', () => {
1528
- before(() => __awaiter(void 0, void 0, void 0, function* () {
1529
- var _a;
1530
- // Remove the "textDocument.publishDiagnostics" client capability.
1531
- const clientCapabilitiesOverride = (0, test_utils_1.getDefaultClientCapabilities)();
1532
- (_a = clientCapabilitiesOverride.textDocument) === null || _a === void 0 ? true : delete _a.publishDiagnostics;
1533
- server = yield (0, test_utils_1.createServer)({
1696
+ let localServer;
1697
+ before(async () => {
1698
+ const clientCapabilitiesOverride = {
1699
+ textDocument: {
1700
+ publishDiagnostics: undefined,
1701
+ },
1702
+ };
1703
+ localServer = await createServer({
1534
1704
  rootUri: null,
1535
1705
  publishDiagnostics: args => diagnostics.set(args.uri, args),
1536
- clientCapabilitiesOverride
1706
+ clientCapabilitiesOverride,
1537
1707
  });
1538
- }));
1539
- it('diagnostics are published', () => __awaiter(void 0, void 0, void 0, function* () {
1708
+ });
1709
+ beforeEach(() => {
1710
+ localServer.closeAll();
1711
+ // "closeAll" triggers final publishDiagnostics with an empty list so clear last.
1712
+ diagnostics.clear();
1713
+ localServer.workspaceEdits = [];
1714
+ });
1715
+ after(() => {
1716
+ localServer.closeAll();
1717
+ localServer.shutdown();
1718
+ });
1719
+ it('diagnostic tags are not returned', async () => {
1540
1720
  const doc = {
1541
- uri: (0, test_utils_1.uri)('diagnosticsBar.ts'),
1721
+ uri: uri('diagnosticsBar.ts'),
1542
1722
  languageId: 'typescript',
1543
1723
  version: 1,
1544
1724
  text: `
1545
1725
  export function foo(): void {
1546
1726
  missing('test')
1547
1727
  }
1548
- `
1728
+ `,
1549
1729
  };
1550
- server.didOpenTextDocument({
1551
- textDocument: doc
1730
+ localServer.didOpenTextDocument({
1731
+ textDocument: doc,
1552
1732
  });
1553
- yield server.requestDiagnostics();
1554
- yield new Promise(resolve => setTimeout(resolve, 200));
1733
+ await localServer.requestDiagnostics();
1734
+ await new Promise(resolve => setTimeout(resolve, 200));
1555
1735
  const resultsForFile = diagnostics.get(doc.uri);
1556
1736
  assert.isDefined(resultsForFile);
1557
- assert.strictEqual(resultsForFile === null || resultsForFile === void 0 ? void 0 : resultsForFile.diagnostics.length, 1);
1558
- })).timeout(10000);
1737
+ assert.strictEqual(resultsForFile.diagnostics.length, 1);
1738
+ assert.notProperty(resultsForFile.diagnostics[0], 'tags');
1739
+ });
1559
1740
  });
1560
1741
  describe('jsx/tsx project', () => {
1561
- 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'),
1564
- publishDiagnostics: args => diagnostics.set(args.uri, args)
1742
+ let localServer;
1743
+ before(async () => {
1744
+ localServer = await createServer({
1745
+ rootUri: uri('jsx'),
1746
+ publishDiagnostics: args => diagnostics.set(args.uri, args),
1565
1747
  });
1566
- }));
1567
- it('includes snippet completion for element prop', () => __awaiter(void 0, void 0, void 0, function* () {
1748
+ });
1749
+ beforeEach(() => {
1750
+ localServer.closeAll();
1751
+ // "closeAll" triggers final publishDiagnostics with an empty list so clear last.
1752
+ diagnostics.clear();
1753
+ localServer.workspaceEdits = [];
1754
+ });
1755
+ after(() => {
1756
+ localServer.closeAll();
1757
+ localServer.shutdown();
1758
+ });
1759
+ it('includes snippet completion for element prop', async () => {
1568
1760
  const doc = {
1569
- uri: (0, test_utils_1.uri)('jsx', 'app.tsx'),
1761
+ uri: uri('jsx', 'app.tsx'),
1570
1762
  languageId: 'typescriptreact',
1571
1763
  version: 1,
1572
- text: (0, test_utils_1.readContents)((0, test_utils_1.filePath)('jsx', 'app.tsx'))
1764
+ text: readContents(filePath('jsx', 'app.tsx')),
1573
1765
  };
1574
- server.didOpenTextDocument({
1575
- textDocument: doc
1766
+ localServer.didOpenTextDocument({
1767
+ textDocument: doc,
1576
1768
  });
1577
- const completion = yield server.completion({ textDocument: doc, position: (0, test_utils_1.position)(doc, 'title') });
1769
+ const completion = await localServer.completion({ textDocument: doc, position: position(doc, 'title') });
1578
1770
  assert.isNotNull(completion);
1579
1771
  const item = completion.items.find(i => i.label === 'title');
1580
1772
  assert.isDefined(item);
1581
- assert.strictEqual(item === null || item === void 0 ? void 0 : item.insertTextFormat, 2);
1582
- })).timeout(10000);
1773
+ assert.strictEqual(item?.insertTextFormat, 2);
1774
+ });
1583
1775
  });
1584
1776
  describe('inlayHints', () => {
1585
- it('inlayHints', () => __awaiter(void 0, void 0, void 0, function* () {
1777
+ before(async () => {
1778
+ server.didChangeConfiguration({
1779
+ settings: {
1780
+ typescript: {
1781
+ inlayHints: {
1782
+ includeInlayFunctionLikeReturnTypeHints: true,
1783
+ },
1784
+ },
1785
+ },
1786
+ });
1787
+ });
1788
+ after(() => {
1789
+ server.didChangeConfiguration({
1790
+ settings: {
1791
+ typescript: {
1792
+ inlayHints: {
1793
+ includeInlayFunctionLikeReturnTypeHints: false,
1794
+ },
1795
+ },
1796
+ },
1797
+ });
1798
+ });
1799
+ it('inlayHints', async () => {
1586
1800
  const doc = {
1587
- uri: (0, test_utils_1.uri)('module.ts'),
1801
+ uri: uri('module.ts'),
1588
1802
  languageId: 'typescript',
1589
1803
  version: 1,
1590
1804
  text: `
1591
1805
  export function foo() {
1592
1806
  return 3
1593
1807
  }
1594
- `
1808
+ `,
1595
1809
  };
1596
- yield server.initialize({
1597
- initializationOptions: {
1598
- preferences: {
1599
- includeInlayFunctionLikeReturnTypeHints: true
1600
- }
1601
- },
1602
- processId: null,
1603
- capabilities: (0, test_utils_1.getDefaultClientCapabilities)(),
1604
- workspaceFolders: [],
1605
- rootUri: ''
1606
- });
1607
- server.didOpenTextDocument({
1608
- textDocument: doc
1609
- });
1610
- const { inlayHints } = yield server.inlayHints({
1611
- textDocument: doc
1612
- });
1810
+ server.didOpenTextDocument({ textDocument: doc });
1811
+ const inlayHints = await server.inlayHints({ textDocument: doc, range: lsp.Range.create(0, 0, 4, 0) });
1613
1812
  assert.isDefined(inlayHints);
1614
1813
  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* () {
1814
+ assert.deepEqual(inlayHints[0], {
1815
+ label: ': number',
1816
+ position: { line: 1, character: 29 },
1817
+ kind: lsp.InlayHintKind.Type,
1818
+ paddingLeft: true,
1819
+ });
1820
+ });
1821
+ it('inlayHints (legacy)', async () => {
1620
1822
  const doc = {
1621
- uri: (0, test_utils_1.uri)('module.ts'),
1823
+ uri: uri('module.ts'),
1622
1824
  languageId: 'typescript',
1623
1825
  version: 1,
1624
1826
  text: `
1625
1827
  export function foo() {
1626
1828
  return 3
1627
1829
  }
1628
- `
1830
+ `,
1629
1831
  };
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
- });
1832
+ server.didOpenTextDocument({ textDocument: doc });
1833
+ const { inlayHints } = await server.inlayHintsLegacy({ textDocument: doc });
1651
1834
  assert.isDefined(inlayHints);
1652
1835
  assert.strictEqual(inlayHints.length, 1);
1653
1836
  assert.strictEqual(inlayHints[0].text, ': number');
1654
1837
  assert.strictEqual(inlayHints[0].kind, 'Type');
1655
1838
  assert.deepStrictEqual(inlayHints[0].position, { line: 1, character: 29 });
1656
- })).timeout(10000);
1839
+ });
1840
+ });
1841
+ describe('completions without client snippet support', () => {
1842
+ let localServer;
1843
+ before(async () => {
1844
+ const clientCapabilitiesOverride = {
1845
+ textDocument: {
1846
+ completion: {
1847
+ completionItem: {
1848
+ snippetSupport: false,
1849
+ },
1850
+ },
1851
+ },
1852
+ };
1853
+ localServer = await createServer({
1854
+ rootUri: null,
1855
+ publishDiagnostics: args => diagnostics.set(args.uri, args),
1856
+ clientCapabilitiesOverride,
1857
+ });
1858
+ });
1859
+ beforeEach(() => {
1860
+ localServer.closeAll();
1861
+ // "closeAll" triggers final publishDiagnostics with an empty list so clear last.
1862
+ diagnostics.clear();
1863
+ localServer.workspaceEdits = [];
1864
+ });
1865
+ after(() => {
1866
+ localServer.closeAll();
1867
+ localServer.shutdown();
1868
+ });
1869
+ it('resolves completion for method completion does not contain snippet', async () => {
1870
+ const doc = {
1871
+ uri: uri('bar.ts'),
1872
+ languageId: 'typescript',
1873
+ version: 1,
1874
+ text: `
1875
+ import fs from 'fs'
1876
+ fs.readFile
1877
+ `,
1878
+ };
1879
+ localServer.didOpenTextDocument({ textDocument: doc });
1880
+ const proposals = await localServer.completion({ textDocument: doc, position: positionAfter(doc, 'readFile') });
1881
+ assert.isNotNull(proposals);
1882
+ const completion = proposals.items.find(completion => completion.label === 'readFile');
1883
+ assert.notEqual(completion.insertTextFormat, lsp.InsertTextFormat.Snippet);
1884
+ assert.strictEqual(completion.label, 'readFile');
1885
+ const resolvedItem = await localServer.completionResolve(completion);
1886
+ assert.strictEqual(resolvedItem.label, 'readFile');
1887
+ assert.strictEqual(resolvedItem.insertText, undefined);
1888
+ assert.strictEqual(resolvedItem.insertTextFormat, undefined);
1889
+ localServer.didCloseTextDocument({ textDocument: doc });
1890
+ });
1891
+ it('does not include snippet completions for element prop', async () => {
1892
+ const doc = {
1893
+ uri: uri('jsx', 'app.tsx'),
1894
+ languageId: 'typescriptreact',
1895
+ version: 1,
1896
+ text: readContents(filePath('jsx', 'app.tsx')),
1897
+ };
1898
+ localServer.didOpenTextDocument({
1899
+ textDocument: doc,
1900
+ });
1901
+ const completion = await localServer.completion({ textDocument: doc, position: position(doc, 'title') });
1902
+ assert.isNotNull(completion);
1903
+ const item = completion.items.find(i => i.label === 'title');
1904
+ assert.isUndefined(item);
1905
+ });
1906
+ it('does not include snippet completions for object methods', async () => {
1907
+ const doc = {
1908
+ uri: uri('foo.ts'),
1909
+ languageId: 'typescript',
1910
+ version: 1,
1911
+ text: `
1912
+ interface IFoo {
1913
+ bar(x: number): void;
1914
+ }
1915
+ const obj: IFoo = {
1916
+ /*a*/
1917
+ }
1918
+ `,
1919
+ };
1920
+ localServer.didOpenTextDocument({ textDocument: doc });
1921
+ const proposals = await localServer.completion({
1922
+ textDocument: doc,
1923
+ position: positionAfter(doc, '/*a*/'),
1924
+ });
1925
+ assert.isNotNull(proposals);
1926
+ assert.lengthOf(proposals.items, 1);
1927
+ assert.deepInclude(proposals.items[0], {
1928
+ label: 'bar',
1929
+ kind: 2,
1930
+ });
1931
+ });
1657
1932
  });
1658
1933
  //# sourceMappingURL=lsp-server.spec.js.map