typescript-language-server 0.6.1 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +245 -19
- package/lib/calls.js +9 -9
- package/lib/calls.js.map +1 -1
- package/lib/cli.js +3 -9
- package/lib/cli.js.map +1 -1
- package/lib/commands.d.ts +1 -1
- package/lib/commands.d.ts.map +1 -1
- package/lib/commands.js +1 -1
- package/lib/commands.js.map +1 -1
- package/lib/completion.d.ts.map +1 -1
- package/lib/completion.js +43 -31
- package/lib/completion.js.map +1 -1
- package/lib/diagnostic-queue.d.ts +4 -4
- package/lib/diagnostic-queue.d.ts.map +1 -1
- package/lib/diagnostic-queue.js +3 -3
- package/lib/diagnostic-queue.js.map +1 -1
- package/lib/document-symbol.js +8 -8
- package/lib/document-symbol.js.map +1 -1
- package/lib/file-lsp-server.spec.js +27 -5
- package/lib/file-lsp-server.spec.js.map +1 -1
- package/lib/hover.js +6 -6
- package/lib/hover.js.map +1 -1
- package/lib/lsp-connection.d.ts.map +1 -1
- package/lib/lsp-connection.js +3 -0
- package/lib/lsp-connection.js.map +1 -1
- package/lib/lsp-protocol.calls.proposed.d.ts.map +1 -1
- package/lib/lsp-protocol.calls.proposed.js.map +1 -1
- package/lib/lsp-protocol.inlayHints.proposed.d.ts +36 -0
- package/lib/lsp-protocol.inlayHints.proposed.d.ts.map +1 -0
- package/lib/lsp-protocol.inlayHints.proposed.js +25 -0
- package/lib/lsp-protocol.inlayHints.proposed.js.map +1 -0
- package/lib/lsp-server.d.ts +8 -1
- package/lib/lsp-server.d.ts.map +1 -1
- package/lib/lsp-server.js +169 -98
- package/lib/lsp-server.js.map +1 -1
- package/lib/lsp-server.spec.js +234 -74
- package/lib/lsp-server.spec.js.map +1 -1
- package/lib/modules-resolver.spec.js +1 -1
- package/lib/modules-resolver.spec.js.map +1 -1
- package/lib/organize-imports.d.ts.map +1 -1
- package/lib/organize-imports.js +2 -1
- package/lib/organize-imports.js.map +1 -1
- package/lib/organize-imports.spec.js +6 -4
- package/lib/organize-imports.spec.js.map +1 -1
- package/lib/protocol-translation.d.ts +14 -1
- package/lib/protocol-translation.d.ts.map +1 -1
- package/lib/protocol-translation.js +28 -5
- package/lib/protocol-translation.js.map +1 -1
- package/lib/quickfix.js +1 -1
- package/lib/quickfix.js.map +1 -1
- package/lib/test-utils.d.ts.map +1 -1
- package/lib/test-utils.js +5 -4
- package/lib/test-utils.js.map +1 -1
- package/lib/ts-protocol.d.ts +11 -1
- package/lib/ts-protocol.d.ts.map +1 -1
- package/lib/ts-protocol.js.map +1 -1
- package/lib/tsp-client.d.ts +2 -1
- package/lib/tsp-client.d.ts.map +1 -1
- package/lib/tsp-client.js +19 -7
- package/lib/tsp-client.js.map +1 -1
- package/lib/tsp-client.spec.js +60 -32
- package/lib/tsp-client.spec.js.map +1 -1
- package/lib/tsp-command-types.d.ts +2 -3
- package/lib/tsp-command-types.d.ts.map +1 -1
- package/lib/tsp-command-types.js.map +1 -1
- package/package.json +6 -6
package/lib/lsp-server.spec.js
CHANGED
|
@@ -40,18 +40,18 @@ const lspcalls = __importStar(require("./lsp-protocol.calls.proposed"));
|
|
|
40
40
|
const test_utils_1 = require("./test-utils");
|
|
41
41
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
42
42
|
const assert = chai.assert;
|
|
43
|
-
|
|
43
|
+
const diagnostics = new Map();
|
|
44
44
|
let server;
|
|
45
45
|
before(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
-
server = yield test_utils_1.createServer({
|
|
46
|
+
server = yield (0, test_utils_1.createServer)({
|
|
47
47
|
rootUri: null,
|
|
48
|
-
publishDiagnostics: args => diagnostics.
|
|
48
|
+
publishDiagnostics: args => diagnostics.set(args.uri, args)
|
|
49
49
|
});
|
|
50
50
|
}));
|
|
51
51
|
beforeEach(() => {
|
|
52
52
|
server.closeAll();
|
|
53
53
|
// "closeAll" triggers final publishDiagnostics with an empty list so clear last.
|
|
54
|
-
diagnostics
|
|
54
|
+
diagnostics.clear();
|
|
55
55
|
});
|
|
56
56
|
after(() => {
|
|
57
57
|
server.closeAll();
|
|
@@ -59,7 +59,7 @@ after(() => {
|
|
|
59
59
|
describe('completion', () => {
|
|
60
60
|
it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
61
|
const doc = {
|
|
62
|
-
uri: test_utils_1.uri('bar.ts'),
|
|
62
|
+
uri: (0, test_utils_1.uri)('bar.ts'),
|
|
63
63
|
languageId: 'typescript',
|
|
64
64
|
version: 1,
|
|
65
65
|
text: `
|
|
@@ -71,21 +71,20 @@ describe('completion', () => {
|
|
|
71
71
|
server.didOpenTextDocument({
|
|
72
72
|
textDocument: doc
|
|
73
73
|
});
|
|
74
|
-
const pos = test_utils_1.position(doc, 'console');
|
|
74
|
+
const pos = (0, test_utils_1.position)(doc, 'console');
|
|
75
75
|
const proposals = yield server.completion({ textDocument: doc, position: pos });
|
|
76
76
|
assert.isNotNull(proposals);
|
|
77
|
-
assert.
|
|
77
|
+
assert.isAtLeast(proposals.items.length, 800);
|
|
78
78
|
const item = proposals.items.find(i => i.label === 'addEventListener');
|
|
79
79
|
assert.isDefined(item);
|
|
80
80
|
const resolvedItem = yield server.completionResolve(item);
|
|
81
|
-
assert.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
});
|
|
81
|
+
assert.isNotTrue(resolvedItem.deprecated, 'resolved item is not deprecated');
|
|
82
|
+
assert.isDefined(resolvedItem.detail);
|
|
83
|
+
server.didCloseTextDocument({ textDocument: doc });
|
|
85
84
|
})).timeout(10000);
|
|
86
85
|
it('simple JS test', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
86
|
const doc = {
|
|
88
|
-
uri: test_utils_1.uri('bar.js'),
|
|
87
|
+
uri: (0, test_utils_1.uri)('bar.js'),
|
|
89
88
|
languageId: 'javascript',
|
|
90
89
|
version: 1,
|
|
91
90
|
text: `
|
|
@@ -97,13 +96,14 @@ describe('completion', () => {
|
|
|
97
96
|
server.didOpenTextDocument({
|
|
98
97
|
textDocument: doc
|
|
99
98
|
});
|
|
100
|
-
const pos = test_utils_1.position(doc, 'console');
|
|
99
|
+
const pos = (0, test_utils_1.position)(doc, 'console');
|
|
101
100
|
const proposals = yield server.completion({ textDocument: doc, position: pos });
|
|
102
101
|
assert.isNotNull(proposals);
|
|
103
|
-
assert.
|
|
102
|
+
assert.isAtLeast(proposals.items.length, 800);
|
|
104
103
|
const item = proposals.items.find(i => i.label === 'addEventListener');
|
|
104
|
+
assert.isDefined(item);
|
|
105
105
|
const resolvedItem = yield server.completionResolve(item);
|
|
106
|
-
assert.
|
|
106
|
+
assert.isDefined(resolvedItem.detail);
|
|
107
107
|
const containsInvalidCompletions = proposals.items.reduce((accumulator, current) => {
|
|
108
108
|
if (accumulator) {
|
|
109
109
|
return accumulator;
|
|
@@ -113,13 +113,42 @@ describe('completion', () => {
|
|
|
113
113
|
(current.kind !== lsp.CompletionItemKind.Function && current.kind !== lsp.CompletionItemKind.Method);
|
|
114
114
|
}, false);
|
|
115
115
|
assert.isFalse(containsInvalidCompletions);
|
|
116
|
-
server.didCloseTextDocument({
|
|
116
|
+
server.didCloseTextDocument({ textDocument: doc });
|
|
117
|
+
})).timeout(10000);
|
|
118
|
+
it('deprecated by JSDoc', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
119
|
+
const doc = {
|
|
120
|
+
uri: (0, test_utils_1.uri)('bar.ts'),
|
|
121
|
+
languageId: 'typescript',
|
|
122
|
+
version: 1,
|
|
123
|
+
text: `
|
|
124
|
+
/**
|
|
125
|
+
* documentation
|
|
126
|
+
* @deprecated for a reason
|
|
127
|
+
*/
|
|
128
|
+
export function foo() {
|
|
129
|
+
console.log('test')
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
foo(); // call me
|
|
133
|
+
`
|
|
134
|
+
};
|
|
135
|
+
server.didOpenTextDocument({
|
|
117
136
|
textDocument: doc
|
|
118
137
|
});
|
|
138
|
+
const pos = (0, test_utils_1.position)(doc, 'foo(); // call me');
|
|
139
|
+
const proposals = yield server.completion({ textDocument: doc, position: pos });
|
|
140
|
+
assert.isNotNull(proposals);
|
|
141
|
+
const item = proposals.items.find(i => i.label === 'foo');
|
|
142
|
+
assert.isDefined(item);
|
|
143
|
+
const resolvedItem = yield server.completionResolve(item);
|
|
144
|
+
assert.isDefined(resolvedItem.detail);
|
|
145
|
+
assert.isArray(resolvedItem.tags);
|
|
146
|
+
assert.include(resolvedItem.tags, lsp.CompletionItemTag.Deprecated, 'resolved item is deprecated');
|
|
147
|
+
server.didCloseTextDocument({ textDocument: doc });
|
|
119
148
|
})).timeout(10000);
|
|
120
149
|
it('incorrect source location', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
121
150
|
const doc = {
|
|
122
|
-
uri: test_utils_1.uri('bar.ts'),
|
|
151
|
+
uri: (0, test_utils_1.uri)('bar.ts'),
|
|
123
152
|
languageId: 'typescript',
|
|
124
153
|
version: 1,
|
|
125
154
|
text: `
|
|
@@ -131,34 +160,28 @@ describe('completion', () => {
|
|
|
131
160
|
server.didOpenTextDocument({
|
|
132
161
|
textDocument: doc
|
|
133
162
|
});
|
|
134
|
-
const pos = test_utils_1.position(doc, 'foo');
|
|
163
|
+
const pos = (0, test_utils_1.position)(doc, 'foo');
|
|
135
164
|
const proposals = yield server.completion({ textDocument: doc, position: pos });
|
|
136
165
|
assert.isNull(proposals);
|
|
137
|
-
server.didCloseTextDocument({
|
|
138
|
-
textDocument: doc
|
|
139
|
-
});
|
|
166
|
+
server.didCloseTextDocument({ textDocument: doc });
|
|
140
167
|
})).timeout(10000);
|
|
141
168
|
it('includes completions from global modules', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
142
169
|
const doc = {
|
|
143
|
-
uri: test_utils_1.uri('bar.ts'),
|
|
170
|
+
uri: (0, test_utils_1.uri)('bar.ts'),
|
|
144
171
|
languageId: 'typescript',
|
|
145
172
|
version: 1,
|
|
146
173
|
text: 'pathex'
|
|
147
174
|
};
|
|
148
|
-
server.didOpenTextDocument({
|
|
149
|
-
|
|
150
|
-
});
|
|
151
|
-
const proposals = yield server.completion({ textDocument: doc, position: test_utils_1.position(doc, 'ex') });
|
|
175
|
+
server.didOpenTextDocument({ textDocument: doc });
|
|
176
|
+
const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.position)(doc, 'ex') });
|
|
152
177
|
assert.isNotNull(proposals);
|
|
153
178
|
const pathExistsCompletion = proposals.items.find(completion => completion.label === 'pathExists');
|
|
154
179
|
assert.isDefined(pathExistsCompletion);
|
|
155
|
-
server.didCloseTextDocument({
|
|
156
|
-
textDocument: doc
|
|
157
|
-
});
|
|
180
|
+
server.didCloseTextDocument({ textDocument: doc });
|
|
158
181
|
})).timeout(10000);
|
|
159
182
|
it('includes completions with invalid identifier names', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
160
183
|
const doc = {
|
|
161
|
-
uri: test_utils_1.uri('bar.ts'),
|
|
184
|
+
uri: (0, test_utils_1.uri)('bar.ts'),
|
|
162
185
|
languageId: 'typescript',
|
|
163
186
|
version: 1,
|
|
164
187
|
text: `
|
|
@@ -170,24 +193,20 @@ describe('completion', () => {
|
|
|
170
193
|
foo.i
|
|
171
194
|
`
|
|
172
195
|
};
|
|
173
|
-
server.didOpenTextDocument({
|
|
174
|
-
|
|
175
|
-
});
|
|
176
|
-
const proposals = yield server.completion({ textDocument: doc, position: test_utils_1.positionAfter(doc, '.i') });
|
|
196
|
+
server.didOpenTextDocument({ textDocument: doc });
|
|
197
|
+
const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.positionAfter)(doc, '.i') });
|
|
177
198
|
assert.isNotNull(proposals);
|
|
178
199
|
const completion = proposals.items.find(completion => completion.label === 'invalid-identifier-name');
|
|
179
200
|
assert.isDefined(completion);
|
|
180
201
|
assert.isDefined(completion.textEdit);
|
|
181
202
|
assert.equal(completion.textEdit.newText, '["invalid-identifier-name"]');
|
|
182
|
-
server.didCloseTextDocument({
|
|
183
|
-
textDocument: doc
|
|
184
|
-
});
|
|
203
|
+
server.didCloseTextDocument({ textDocument: doc });
|
|
185
204
|
})).timeout(10000);
|
|
186
205
|
});
|
|
187
206
|
describe('diagnostics', () => {
|
|
188
207
|
it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
189
208
|
const doc = {
|
|
190
|
-
uri: test_utils_1.uri('diagnosticsBar.ts'),
|
|
209
|
+
uri: (0, test_utils_1.uri)('diagnosticsBar.ts'),
|
|
191
210
|
languageId: 'typescript',
|
|
192
211
|
version: 1,
|
|
193
212
|
text: `
|
|
@@ -201,15 +220,15 @@ describe('diagnostics', () => {
|
|
|
201
220
|
});
|
|
202
221
|
yield server.requestDiagnostics();
|
|
203
222
|
yield new Promise(resolve => setTimeout(resolve, 200));
|
|
204
|
-
const
|
|
205
|
-
assert.
|
|
206
|
-
const fileDiagnostics =
|
|
223
|
+
const resultsForFile = diagnostics.get(doc.uri);
|
|
224
|
+
assert.isDefined(resultsForFile);
|
|
225
|
+
const fileDiagnostics = resultsForFile.diagnostics;
|
|
207
226
|
assert.equal(fileDiagnostics.length, 1);
|
|
208
227
|
assert.equal("Cannot find name 'missing'.", fileDiagnostics[0].message);
|
|
209
228
|
})).timeout(10000);
|
|
210
229
|
it('supports diagnostic tags', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
211
230
|
const doc = {
|
|
212
|
-
uri: test_utils_1.uri('diagnosticsBar.ts'),
|
|
231
|
+
uri: (0, test_utils_1.uri)('diagnosticsBar.ts'),
|
|
213
232
|
languageId: 'typescript',
|
|
214
233
|
version: 1,
|
|
215
234
|
text: `
|
|
@@ -225,7 +244,7 @@ describe('diagnostics', () => {
|
|
|
225
244
|
});
|
|
226
245
|
yield server.requestDiagnostics();
|
|
227
246
|
yield new Promise(resolve => setTimeout(resolve, 200));
|
|
228
|
-
const resultsForFile = diagnostics.
|
|
247
|
+
const resultsForFile = diagnostics.get(doc.uri);
|
|
229
248
|
assert.isDefined(resultsForFile);
|
|
230
249
|
const fileDiagnostics = resultsForFile.diagnostics;
|
|
231
250
|
assert.equal(fileDiagnostics.length, 2);
|
|
@@ -238,7 +257,7 @@ describe('diagnostics', () => {
|
|
|
238
257
|
})).timeout(10000);
|
|
239
258
|
it('multiple files test', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
240
259
|
const doc = {
|
|
241
|
-
uri: test_utils_1.uri('multipleFileDiagnosticsBar.ts'),
|
|
260
|
+
uri: (0, test_utils_1.uri)('multipleFileDiagnosticsBar.ts'),
|
|
242
261
|
languageId: 'typescript',
|
|
243
262
|
version: 1,
|
|
244
263
|
text: `
|
|
@@ -248,7 +267,7 @@ describe('diagnostics', () => {
|
|
|
248
267
|
`
|
|
249
268
|
};
|
|
250
269
|
const doc2 = {
|
|
251
|
-
uri: test_utils_1.uri('multipleFileDiagnosticsFoo.ts'),
|
|
270
|
+
uri: (0, test_utils_1.uri)('multipleFileDiagnosticsFoo.ts'),
|
|
252
271
|
languageId: 'typescript',
|
|
253
272
|
version: 1,
|
|
254
273
|
text: `
|
|
@@ -265,15 +284,19 @@ describe('diagnostics', () => {
|
|
|
265
284
|
});
|
|
266
285
|
yield server.requestDiagnostics();
|
|
267
286
|
yield new Promise(resolve => setTimeout(resolve, 200));
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
287
|
+
assert.equal(diagnostics.size, 2);
|
|
288
|
+
const diagnosticsForDoc = diagnostics.get(doc.uri);
|
|
289
|
+
const diagnosticsForDoc2 = diagnostics.get(doc2.uri);
|
|
290
|
+
assert.isDefined(diagnosticsForDoc);
|
|
291
|
+
assert.isDefined(diagnosticsForDoc2);
|
|
292
|
+
assert.equal(diagnosticsForDoc.diagnostics.length, 1, JSON.stringify(diagnostics));
|
|
293
|
+
assert.equal(diagnosticsForDoc2.diagnostics.length, 1, JSON.stringify(diagnostics));
|
|
271
294
|
})).timeout(10000);
|
|
272
295
|
});
|
|
273
296
|
describe('document symbol', () => {
|
|
274
297
|
it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
275
298
|
const doc = {
|
|
276
|
-
uri: test_utils_1.uri('bar.ts'),
|
|
299
|
+
uri: (0, test_utils_1.uri)('bar.ts'),
|
|
277
300
|
languageId: 'typescript',
|
|
278
301
|
version: 1,
|
|
279
302
|
text: `
|
|
@@ -299,7 +322,7 @@ Foo
|
|
|
299
322
|
})).timeout(10000);
|
|
300
323
|
it('merges interfaces correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
301
324
|
const doc = {
|
|
302
|
-
uri: test_utils_1.uri('bar.ts'),
|
|
325
|
+
uri: (0, test_utils_1.uri)('bar.ts'),
|
|
303
326
|
languageId: 'typescript',
|
|
304
327
|
version: 1,
|
|
305
328
|
text: `
|
|
@@ -329,7 +352,7 @@ Box
|
|
|
329
352
|
})).timeout(10000);
|
|
330
353
|
it('duplication test', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
331
354
|
const doc = {
|
|
332
|
-
uri: test_utils_1.uri('bar.ts'),
|
|
355
|
+
uri: (0, test_utils_1.uri)('bar.ts'),
|
|
333
356
|
languageId: 'typescript',
|
|
334
357
|
version: 1,
|
|
335
358
|
text: `
|
|
@@ -386,7 +409,7 @@ function symbolsAsString(symbols, indentation = '') {
|
|
|
386
409
|
describe('editing', () => {
|
|
387
410
|
it('open and change', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
388
411
|
const doc = {
|
|
389
|
-
uri: test_utils_1.uri('openAndChangeBar.ts'),
|
|
412
|
+
uri: (0, test_utils_1.uri)('openAndChangeBar.ts'),
|
|
390
413
|
languageId: 'typescript',
|
|
391
414
|
version: 1,
|
|
392
415
|
text: `
|
|
@@ -411,13 +434,49 @@ describe('editing', () => {
|
|
|
411
434
|
});
|
|
412
435
|
yield server.requestDiagnostics();
|
|
413
436
|
yield new Promise(resolve => setTimeout(resolve, 200));
|
|
414
|
-
const
|
|
437
|
+
const resultsForFile = diagnostics.get(doc.uri);
|
|
438
|
+
assert.isDefined(resultsForFile);
|
|
439
|
+
const fileDiagnostics = resultsForFile.diagnostics;
|
|
415
440
|
assert.isTrue(fileDiagnostics.length >= 1, fileDiagnostics.map(d => d.message).join(','));
|
|
416
441
|
assert.equal("Cannot find name 'missing'.", fileDiagnostics[0].message);
|
|
417
442
|
})).timeout(10000);
|
|
418
443
|
});
|
|
444
|
+
describe('workspace configuration', () => {
|
|
445
|
+
it('receives workspace configuration notification', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
446
|
+
const doc = {
|
|
447
|
+
uri: (0, test_utils_1.uri)('bar.ts'),
|
|
448
|
+
languageId: 'typescript',
|
|
449
|
+
version: 1,
|
|
450
|
+
text: `
|
|
451
|
+
export function foo(): void {
|
|
452
|
+
console.log('test')
|
|
453
|
+
}
|
|
454
|
+
`
|
|
455
|
+
};
|
|
456
|
+
server.didOpenTextDocument({
|
|
457
|
+
textDocument: doc
|
|
458
|
+
});
|
|
459
|
+
server.didChangeConfiguration({
|
|
460
|
+
settings: {
|
|
461
|
+
typescript: {
|
|
462
|
+
format: {
|
|
463
|
+
insertSpaceAfterCommaDelimiter: true
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
javascript: {
|
|
467
|
+
format: {
|
|
468
|
+
insertSpaceAfterCommaDelimiter: false
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
const file = (0, test_utils_1.filePath)('bar.ts');
|
|
474
|
+
const settings = server.getWorkspacePreferencesForDocument(file);
|
|
475
|
+
assert.deepEqual(settings, { format: { insertSpaceAfterCommaDelimiter: true } });
|
|
476
|
+
}));
|
|
477
|
+
});
|
|
419
478
|
describe('formatting', () => {
|
|
420
|
-
const uriString = test_utils_1.uri('bar.ts');
|
|
479
|
+
const uriString = (0, test_utils_1.uri)('bar.ts');
|
|
421
480
|
const languageId = 'typescript';
|
|
422
481
|
const version = 1;
|
|
423
482
|
it('full document formatting', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -468,6 +527,32 @@ describe('formatting', () => {
|
|
|
468
527
|
const result = vscode_languageserver_textdocument_1.TextDocument.applyEdits(vscode_languageserver_textdocument_1.TextDocument.create(uriString, languageId, version, text), edits);
|
|
469
528
|
assert.equal('function foo() {\n\t// some code\n}', result);
|
|
470
529
|
})).timeout(10000);
|
|
530
|
+
it('formatting setting set through workspace configuration', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
531
|
+
const text = 'function foo() {\n// some code\n}';
|
|
532
|
+
const textDocument = {
|
|
533
|
+
uri: uriString, languageId, version, text
|
|
534
|
+
};
|
|
535
|
+
server.didOpenTextDocument({ textDocument });
|
|
536
|
+
server.didChangeConfiguration({
|
|
537
|
+
settings: {
|
|
538
|
+
typescript: {
|
|
539
|
+
format: {
|
|
540
|
+
newLineCharacter: '\n',
|
|
541
|
+
placeOpenBraceOnNewLineForFunctions: true
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
const edits = yield server.documentFormatting({
|
|
547
|
+
textDocument,
|
|
548
|
+
options: {
|
|
549
|
+
tabSize: 4,
|
|
550
|
+
insertSpaces: false
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
const result = vscode_languageserver_textdocument_1.TextDocument.applyEdits(vscode_languageserver_textdocument_1.TextDocument.create(uriString, languageId, version, text), edits);
|
|
554
|
+
assert.equal('function foo()\n{\n\t// some code\n}', result);
|
|
555
|
+
})).timeout(10000);
|
|
471
556
|
it('selected range', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
472
557
|
const text = 'function foo() {\nconst first = 1;\nconst second = 2;\nconst val = foo( "something" );\n//const fourth = 4;\n}';
|
|
473
558
|
const textDocument = {
|
|
@@ -498,7 +583,7 @@ describe('formatting', () => {
|
|
|
498
583
|
describe('signatureHelp', () => {
|
|
499
584
|
it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
500
585
|
const doc = {
|
|
501
|
-
uri: test_utils_1.uri('bar.ts'),
|
|
586
|
+
uri: (0, test_utils_1.uri)('bar.ts'),
|
|
502
587
|
languageId: 'typescript',
|
|
503
588
|
version: 1,
|
|
504
589
|
text: `
|
|
@@ -511,19 +596,19 @@ describe('signatureHelp', () => {
|
|
|
511
596
|
});
|
|
512
597
|
let result = (yield server.signatureHelp({
|
|
513
598
|
textDocument: doc,
|
|
514
|
-
position: test_utils_1.position(doc, 'param1')
|
|
599
|
+
position: (0, test_utils_1.position)(doc, 'param1')
|
|
515
600
|
}));
|
|
516
601
|
assert.equal('bar: string', result.signatures[result.activeSignature].parameters[result.activeParameter].label);
|
|
517
602
|
result = (yield server.signatureHelp({
|
|
518
603
|
textDocument: doc,
|
|
519
|
-
position: test_utils_1.position(doc, 'param2')
|
|
604
|
+
position: (0, test_utils_1.position)(doc, 'param2')
|
|
520
605
|
}));
|
|
521
606
|
assert.equal('baz?: boolean', result.signatures[result.activeSignature].parameters[result.activeParameter].label);
|
|
522
607
|
})).timeout(10000);
|
|
523
608
|
});
|
|
524
609
|
describe('code actions', () => {
|
|
525
610
|
const doc = {
|
|
526
|
-
uri: test_utils_1.uri('bar.ts'),
|
|
611
|
+
uri: (0, test_utils_1.uri)('bar.ts'),
|
|
527
612
|
languageId: 'typescript',
|
|
528
613
|
version: 1,
|
|
529
614
|
text: `import { something } from "something";
|
|
@@ -565,7 +650,7 @@ describe('code actions', () => {
|
|
|
565
650
|
documentChanges: [
|
|
566
651
|
{
|
|
567
652
|
textDocument: {
|
|
568
|
-
uri: test_utils_1.uri('bar.ts'),
|
|
653
|
+
uri: (0, test_utils_1.uri)('bar.ts'),
|
|
569
654
|
version: 1
|
|
570
655
|
},
|
|
571
656
|
edits: [
|
|
@@ -599,7 +684,7 @@ describe('code actions', () => {
|
|
|
599
684
|
command: '_typescript.applyRefactoring',
|
|
600
685
|
arguments: [
|
|
601
686
|
{
|
|
602
|
-
file: test_utils_1.filePath('bar.ts'),
|
|
687
|
+
file: (0, test_utils_1.filePath)('bar.ts'),
|
|
603
688
|
startLine: 2,
|
|
604
689
|
startOffset: 26,
|
|
605
690
|
endLine: 2,
|
|
@@ -642,7 +727,7 @@ describe('code actions', () => {
|
|
|
642
727
|
action: 'Convert parameters to destructured object',
|
|
643
728
|
endLine: 2,
|
|
644
729
|
endOffset: 50,
|
|
645
|
-
file: test_utils_1.filePath('bar.ts'),
|
|
730
|
+
file: (0, test_utils_1.filePath)('bar.ts'),
|
|
646
731
|
refactor: 'Convert parameters to destructured object',
|
|
647
732
|
startLine: 2,
|
|
648
733
|
startOffset: 26
|
|
@@ -681,7 +766,7 @@ describe('code actions', () => {
|
|
|
681
766
|
assert.deepEqual(result, [
|
|
682
767
|
{
|
|
683
768
|
command: {
|
|
684
|
-
arguments: [test_utils_1.filePath('bar.ts')],
|
|
769
|
+
arguments: [(0, test_utils_1.filePath)('bar.ts')],
|
|
685
770
|
command: '_typescript.organizeImports',
|
|
686
771
|
title: ''
|
|
687
772
|
},
|
|
@@ -694,7 +779,7 @@ describe('code actions', () => {
|
|
|
694
779
|
describe('documentHighlight', () => {
|
|
695
780
|
it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
696
781
|
const barDoc = {
|
|
697
|
-
uri: test_utils_1.uri('bar.d.ts'),
|
|
782
|
+
uri: (0, test_utils_1.uri)('bar.d.ts'),
|
|
698
783
|
languageId: 'typescript',
|
|
699
784
|
version: 1,
|
|
700
785
|
text: `
|
|
@@ -707,7 +792,7 @@ describe('documentHighlight', () => {
|
|
|
707
792
|
textDocument: barDoc
|
|
708
793
|
});
|
|
709
794
|
const fooDoc = {
|
|
710
|
-
uri: test_utils_1.uri('bar.ts'),
|
|
795
|
+
uri: (0, test_utils_1.uri)('bar.ts'),
|
|
711
796
|
languageId: 'typescript',
|
|
712
797
|
version: 1,
|
|
713
798
|
text: `
|
|
@@ -721,7 +806,7 @@ describe('documentHighlight', () => {
|
|
|
721
806
|
});
|
|
722
807
|
const result = yield server.documentHighlight({
|
|
723
808
|
textDocument: fooDoc,
|
|
724
|
-
position: test_utils_1.lastPosition(fooDoc, 'Bar')
|
|
809
|
+
position: (0, test_utils_1.lastPosition)(fooDoc, 'Bar')
|
|
725
810
|
});
|
|
726
811
|
assert.equal(2, result.length, JSON.stringify(result, undefined, 2));
|
|
727
812
|
})).timeout(10000);
|
|
@@ -744,7 +829,7 @@ describe('calls', () => {
|
|
|
744
829
|
return out.join('\n');
|
|
745
830
|
}
|
|
746
831
|
const doDoc = {
|
|
747
|
-
uri: test_utils_1.uri('do.ts'),
|
|
832
|
+
uri: (0, test_utils_1.uri)('do.ts'),
|
|
748
833
|
languageId: 'typescript',
|
|
749
834
|
version: 1,
|
|
750
835
|
text: `
|
|
@@ -762,7 +847,7 @@ export function three() {
|
|
|
762
847
|
`
|
|
763
848
|
};
|
|
764
849
|
const fooDoc = {
|
|
765
|
-
uri: test_utils_1.uri('foo.ts'),
|
|
850
|
+
uri: (0, test_utils_1.uri)('foo.ts'),
|
|
766
851
|
languageId: 'typescript',
|
|
767
852
|
version: 1,
|
|
768
853
|
text: `import { doStuff } from './do';
|
|
@@ -841,17 +926,17 @@ describe('diagnostics (no client support)', () => {
|
|
|
841
926
|
before(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
842
927
|
var _a;
|
|
843
928
|
// Remove the "textDocument.publishDiagnostics" client capability.
|
|
844
|
-
const clientCapabilitiesOverride = test_utils_1.getDefaultClientCapabilities();
|
|
929
|
+
const clientCapabilitiesOverride = (0, test_utils_1.getDefaultClientCapabilities)();
|
|
845
930
|
(_a = clientCapabilitiesOverride.textDocument) === null || _a === void 0 ? true : delete _a.publishDiagnostics;
|
|
846
|
-
server = yield test_utils_1.createServer({
|
|
931
|
+
server = yield (0, test_utils_1.createServer)({
|
|
847
932
|
rootUri: null,
|
|
848
|
-
publishDiagnostics: args => diagnostics.
|
|
933
|
+
publishDiagnostics: args => diagnostics.set(args.uri, args),
|
|
849
934
|
clientCapabilitiesOverride
|
|
850
935
|
});
|
|
851
936
|
}));
|
|
852
|
-
it('
|
|
937
|
+
it('diagnostics are published', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
853
938
|
const doc = {
|
|
854
|
-
uri: test_utils_1.uri('diagnosticsBar.ts'),
|
|
939
|
+
uri: (0, test_utils_1.uri)('diagnosticsBar.ts'),
|
|
855
940
|
languageId: 'typescript',
|
|
856
941
|
version: 1,
|
|
857
942
|
text: `
|
|
@@ -865,8 +950,83 @@ describe('diagnostics (no client support)', () => {
|
|
|
865
950
|
});
|
|
866
951
|
yield server.requestDiagnostics();
|
|
867
952
|
yield new Promise(resolve => setTimeout(resolve, 200));
|
|
868
|
-
const
|
|
869
|
-
assert.
|
|
953
|
+
const resultsForFile = diagnostics.get(doc.uri);
|
|
954
|
+
assert.isDefined(resultsForFile);
|
|
955
|
+
assert.strictEqual(resultsForFile === null || resultsForFile === void 0 ? void 0 : resultsForFile.diagnostics.length, 1);
|
|
956
|
+
})).timeout(10000);
|
|
957
|
+
});
|
|
958
|
+
describe('inlayHints', () => {
|
|
959
|
+
it('inlayHints', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
960
|
+
const doc = {
|
|
961
|
+
uri: (0, test_utils_1.uri)('module.ts'),
|
|
962
|
+
languageId: 'typescript',
|
|
963
|
+
version: 1,
|
|
964
|
+
text: `
|
|
965
|
+
export function foo() {
|
|
966
|
+
return 3
|
|
967
|
+
}
|
|
968
|
+
`
|
|
969
|
+
};
|
|
970
|
+
server.initialize({
|
|
971
|
+
initializationOptions: {
|
|
972
|
+
preferences: {
|
|
973
|
+
includeInlayFunctionLikeReturnTypeHints: true
|
|
974
|
+
}
|
|
975
|
+
},
|
|
976
|
+
processId: null,
|
|
977
|
+
capabilities: (0, test_utils_1.getDefaultClientCapabilities)(),
|
|
978
|
+
workspaceFolders: [],
|
|
979
|
+
rootUri: ''
|
|
980
|
+
});
|
|
981
|
+
server.didOpenTextDocument({
|
|
982
|
+
textDocument: doc
|
|
983
|
+
});
|
|
984
|
+
const { inlayHints } = yield server.inlayHints({
|
|
985
|
+
textDocument: doc
|
|
986
|
+
});
|
|
987
|
+
assert.isDefined(inlayHints);
|
|
988
|
+
assert.strictEqual(inlayHints.length, 1);
|
|
989
|
+
assert.strictEqual(inlayHints[0].text, ': number');
|
|
990
|
+
assert.strictEqual(inlayHints[0].kind, 'Type');
|
|
991
|
+
assert.deepStrictEqual(inlayHints[0].position, { line: 1, character: 29 });
|
|
992
|
+
})).timeout(10000);
|
|
993
|
+
it('inlayHints options set through workspace configuration ', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
994
|
+
const doc = {
|
|
995
|
+
uri: (0, test_utils_1.uri)('module.ts'),
|
|
996
|
+
languageId: 'typescript',
|
|
997
|
+
version: 1,
|
|
998
|
+
text: `
|
|
999
|
+
export function foo() {
|
|
1000
|
+
return 3
|
|
1001
|
+
}
|
|
1002
|
+
`
|
|
1003
|
+
};
|
|
1004
|
+
server.initialize({
|
|
1005
|
+
processId: null,
|
|
1006
|
+
capabilities: (0, test_utils_1.getDefaultClientCapabilities)(),
|
|
1007
|
+
workspaceFolders: [],
|
|
1008
|
+
rootUri: ''
|
|
1009
|
+
});
|
|
1010
|
+
server.didChangeConfiguration({
|
|
1011
|
+
settings: {
|
|
1012
|
+
typescript: {
|
|
1013
|
+
inlayHints: {
|
|
1014
|
+
includeInlayFunctionLikeReturnTypeHints: true
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
server.didOpenTextDocument({
|
|
1020
|
+
textDocument: doc
|
|
1021
|
+
});
|
|
1022
|
+
const { inlayHints } = yield server.inlayHints({
|
|
1023
|
+
textDocument: doc
|
|
1024
|
+
});
|
|
1025
|
+
assert.isDefined(inlayHints);
|
|
1026
|
+
assert.strictEqual(inlayHints.length, 1);
|
|
1027
|
+
assert.strictEqual(inlayHints[0].text, ': number');
|
|
1028
|
+
assert.strictEqual(inlayHints[0].kind, 'Type');
|
|
1029
|
+
assert.deepStrictEqual(inlayHints[0].position, { line: 1, character: 29 });
|
|
870
1030
|
})).timeout(10000);
|
|
871
1031
|
});
|
|
872
1032
|
//# sourceMappingURL=lsp-server.spec.js.map
|