typescript-language-server 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +253 -31
  3. package/lib/calls.js +9 -9
  4. package/lib/calls.js.map +1 -1
  5. package/lib/cli.js +6 -11
  6. package/lib/cli.js.map +1 -1
  7. package/lib/commands.d.ts +4 -1
  8. package/lib/commands.d.ts.map +1 -1
  9. package/lib/commands.js +5 -2
  10. package/lib/commands.js.map +1 -1
  11. package/lib/completion.d.ts.map +1 -1
  12. package/lib/completion.js +60 -34
  13. package/lib/completion.js.map +1 -1
  14. package/lib/diagnostic-queue.d.ts +4 -4
  15. package/lib/diagnostic-queue.d.ts.map +1 -1
  16. package/lib/diagnostic-queue.js +3 -3
  17. package/lib/diagnostic-queue.js.map +1 -1
  18. package/lib/document-symbol.js +8 -8
  19. package/lib/document-symbol.js.map +1 -1
  20. package/lib/file-lsp-server.spec.js +27 -5
  21. package/lib/file-lsp-server.spec.js.map +1 -1
  22. package/lib/hover.js +6 -6
  23. package/lib/hover.js.map +1 -1
  24. package/lib/lsp-connection.d.ts.map +1 -1
  25. package/lib/lsp-connection.js +3 -0
  26. package/lib/lsp-connection.js.map +1 -1
  27. package/lib/lsp-protocol.calls.proposed.d.ts.map +1 -1
  28. package/lib/lsp-protocol.calls.proposed.js.map +1 -1
  29. package/lib/lsp-protocol.inlayHints.proposed.d.ts +36 -0
  30. package/lib/lsp-protocol.inlayHints.proposed.d.ts.map +1 -0
  31. package/lib/lsp-protocol.inlayHints.proposed.js +25 -0
  32. package/lib/lsp-protocol.inlayHints.proposed.js.map +1 -0
  33. package/lib/lsp-server.d.ts +10 -2
  34. package/lib/lsp-server.d.ts.map +1 -1
  35. package/lib/lsp-server.js +241 -118
  36. package/lib/lsp-server.js.map +1 -1
  37. package/lib/lsp-server.spec.js +294 -47
  38. package/lib/lsp-server.spec.js.map +1 -1
  39. package/lib/modules-resolver.spec.js +1 -1
  40. package/lib/modules-resolver.spec.js.map +1 -1
  41. package/lib/organize-imports.d.ts +2 -1
  42. package/lib/organize-imports.d.ts.map +1 -1
  43. package/lib/organize-imports.js +7 -5
  44. package/lib/organize-imports.js.map +1 -1
  45. package/lib/organize-imports.spec.js +15 -8
  46. package/lib/organize-imports.spec.js.map +1 -1
  47. package/lib/protocol-translation.d.ts +8 -4
  48. package/lib/protocol-translation.d.ts.map +1 -1
  49. package/lib/protocol-translation.js +22 -11
  50. package/lib/protocol-translation.js.map +1 -1
  51. package/lib/quickfix.js +1 -1
  52. package/lib/quickfix.js.map +1 -1
  53. package/lib/test-utils.js +4 -4
  54. package/lib/test-utils.js.map +1 -1
  55. package/lib/ts-protocol.d.ts +11 -1
  56. package/lib/ts-protocol.d.ts.map +1 -1
  57. package/lib/ts-protocol.js.map +1 -1
  58. package/lib/tsp-client.d.ts +2 -0
  59. package/lib/tsp-client.d.ts.map +1 -1
  60. package/lib/tsp-client.js +20 -11
  61. package/lib/tsp-client.js.map +1 -1
  62. package/lib/tsp-client.spec.js +28 -8
  63. package/lib/tsp-client.spec.js.map +1 -1
  64. package/lib/tsp-command-types.d.ts +14 -1
  65. package/lib/tsp-command-types.d.ts.map +1 -1
  66. package/lib/tsp-command-types.js +21 -1
  67. package/lib/tsp-command-types.js.map +1 -1
  68. package/lib/utils/api.d.ts +45 -0
  69. package/lib/utils/api.d.ts.map +1 -0
  70. package/lib/utils/api.js +95 -0
  71. package/lib/utils/api.js.map +1 -0
  72. package/package.json +5 -5
@@ -39,11 +39,12 @@ const lsp = __importStar(require("vscode-languageserver/node"));
39
39
  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
+ const commands_1 = require("./commands");
42
43
  const assert = chai.assert;
43
44
  const diagnostics = new Map();
44
45
  let server;
45
46
  before(() => __awaiter(void 0, void 0, void 0, function* () {
46
- server = yield test_utils_1.createServer({
47
+ server = yield (0, test_utils_1.createServer)({
47
48
  rootUri: null,
48
49
  publishDiagnostics: args => diagnostics.set(args.uri, args)
49
50
  });
@@ -59,7 +60,7 @@ after(() => {
59
60
  describe('completion', () => {
60
61
  it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
61
62
  const doc = {
62
- uri: test_utils_1.uri('bar.ts'),
63
+ uri: (0, test_utils_1.uri)('bar.ts'),
63
64
  languageId: 'typescript',
64
65
  version: 1,
65
66
  text: `
@@ -71,7 +72,7 @@ describe('completion', () => {
71
72
  server.didOpenTextDocument({
72
73
  textDocument: doc
73
74
  });
74
- const pos = test_utils_1.position(doc, 'console');
75
+ const pos = (0, test_utils_1.position)(doc, 'console');
75
76
  const proposals = yield server.completion({ textDocument: doc, position: pos });
76
77
  assert.isNotNull(proposals);
77
78
  assert.isAtLeast(proposals.items.length, 800);
@@ -84,7 +85,7 @@ describe('completion', () => {
84
85
  })).timeout(10000);
85
86
  it('simple JS test', () => __awaiter(void 0, void 0, void 0, function* () {
86
87
  const doc = {
87
- uri: test_utils_1.uri('bar.js'),
88
+ uri: (0, test_utils_1.uri)('bar.js'),
88
89
  languageId: 'javascript',
89
90
  version: 1,
90
91
  text: `
@@ -96,7 +97,7 @@ describe('completion', () => {
96
97
  server.didOpenTextDocument({
97
98
  textDocument: doc
98
99
  });
99
- const pos = test_utils_1.position(doc, 'console');
100
+ const pos = (0, test_utils_1.position)(doc, 'console');
100
101
  const proposals = yield server.completion({ textDocument: doc, position: pos });
101
102
  assert.isNotNull(proposals);
102
103
  assert.isAtLeast(proposals.items.length, 800);
@@ -117,7 +118,7 @@ describe('completion', () => {
117
118
  })).timeout(10000);
118
119
  it('deprecated by JSDoc', () => __awaiter(void 0, void 0, void 0, function* () {
119
120
  const doc = {
120
- uri: test_utils_1.uri('bar.ts'),
121
+ uri: (0, test_utils_1.uri)('bar.ts'),
121
122
  languageId: 'typescript',
122
123
  version: 1,
123
124
  text: `
@@ -135,7 +136,7 @@ describe('completion', () => {
135
136
  server.didOpenTextDocument({
136
137
  textDocument: doc
137
138
  });
138
- const pos = test_utils_1.position(doc, 'foo(); // call me');
139
+ const pos = (0, test_utils_1.position)(doc, 'foo(); // call me');
139
140
  const proposals = yield server.completion({ textDocument: doc, position: pos });
140
141
  assert.isNotNull(proposals);
141
142
  const item = proposals.items.find(i => i.label === 'foo');
@@ -148,7 +149,7 @@ describe('completion', () => {
148
149
  })).timeout(10000);
149
150
  it('incorrect source location', () => __awaiter(void 0, void 0, void 0, function* () {
150
151
  const doc = {
151
- uri: test_utils_1.uri('bar.ts'),
152
+ uri: (0, test_utils_1.uri)('bar.ts'),
152
153
  languageId: 'typescript',
153
154
  version: 1,
154
155
  text: `
@@ -160,20 +161,20 @@ describe('completion', () => {
160
161
  server.didOpenTextDocument({
161
162
  textDocument: doc
162
163
  });
163
- const pos = test_utils_1.position(doc, 'foo');
164
+ const pos = (0, test_utils_1.position)(doc, 'foo');
164
165
  const proposals = yield server.completion({ textDocument: doc, position: pos });
165
166
  assert.isNull(proposals);
166
167
  server.didCloseTextDocument({ textDocument: doc });
167
168
  })).timeout(10000);
168
169
  it('includes completions from global modules', () => __awaiter(void 0, void 0, void 0, function* () {
169
170
  const doc = {
170
- uri: test_utils_1.uri('bar.ts'),
171
+ uri: (0, test_utils_1.uri)('bar.ts'),
171
172
  languageId: 'typescript',
172
173
  version: 1,
173
174
  text: 'pathex'
174
175
  };
175
176
  server.didOpenTextDocument({ textDocument: doc });
176
- const proposals = yield server.completion({ textDocument: doc, position: test_utils_1.position(doc, 'ex') });
177
+ const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.position)(doc, 'ex') });
177
178
  assert.isNotNull(proposals);
178
179
  const pathExistsCompletion = proposals.items.find(completion => completion.label === 'pathExists');
179
180
  assert.isDefined(pathExistsCompletion);
@@ -181,7 +182,7 @@ describe('completion', () => {
181
182
  })).timeout(10000);
182
183
  it('includes completions with invalid identifier names', () => __awaiter(void 0, void 0, void 0, function* () {
183
184
  const doc = {
184
- uri: test_utils_1.uri('bar.ts'),
185
+ uri: (0, test_utils_1.uri)('bar.ts'),
185
186
  languageId: 'typescript',
186
187
  version: 1,
187
188
  text: `
@@ -194,7 +195,7 @@ describe('completion', () => {
194
195
  `
195
196
  };
196
197
  server.didOpenTextDocument({ textDocument: doc });
197
- const proposals = yield server.completion({ textDocument: doc, position: test_utils_1.positionAfter(doc, '.i') });
198
+ const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.positionAfter)(doc, '.i') });
198
199
  assert.isNotNull(proposals);
199
200
  const completion = proposals.items.find(completion => completion.label === 'invalid-identifier-name');
200
201
  assert.isDefined(completion);
@@ -202,11 +203,57 @@ describe('completion', () => {
202
203
  assert.equal(completion.textEdit.newText, '["invalid-identifier-name"]');
203
204
  server.didCloseTextDocument({ textDocument: doc });
204
205
  })).timeout(10000);
206
+ it('includes detail field with package name for auto-imports', () => __awaiter(void 0, void 0, void 0, function* () {
207
+ const doc = {
208
+ uri: (0, test_utils_1.uri)('bar.ts'),
209
+ languageId: 'typescript',
210
+ version: 1,
211
+ text: 'readFile'
212
+ };
213
+ server.didOpenTextDocument({ textDocument: doc });
214
+ const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.positionAfter)(doc, 'readFile') });
215
+ assert.isNotNull(proposals);
216
+ const completion = proposals.items.find(completion => completion.label === 'readFile');
217
+ assert.isDefined(completion);
218
+ assert.strictEqual(completion.detail, 'fs');
219
+ assert.strictEqual(completion.insertTextFormat, /* snippet */ 2);
220
+ server.didCloseTextDocument({ textDocument: doc });
221
+ })).timeout(10000);
222
+ it('resolves text edit for auto-import completion', () => __awaiter(void 0, void 0, void 0, function* () {
223
+ const doc = {
224
+ uri: (0, test_utils_1.uri)('bar.ts'),
225
+ languageId: 'typescript',
226
+ version: 1,
227
+ text: 'readFile'
228
+ };
229
+ server.didOpenTextDocument({ textDocument: doc });
230
+ const proposals = yield server.completion({ textDocument: doc, position: (0, test_utils_1.positionAfter)(doc, 'readFile') });
231
+ assert.isNotNull(proposals);
232
+ const completion = proposals.items.find(completion => completion.label === 'readFile');
233
+ assert.isDefined(completion);
234
+ const resolvedItem = yield server.completionResolve(completion);
235
+ assert.deepEqual(resolvedItem.additionalTextEdits, [
236
+ {
237
+ newText: 'import { readFile } from "fs";\n\n',
238
+ range: {
239
+ end: {
240
+ character: 0,
241
+ line: 0
242
+ },
243
+ start: {
244
+ character: 0,
245
+ line: 0
246
+ }
247
+ }
248
+ }
249
+ ]);
250
+ server.didCloseTextDocument({ textDocument: doc });
251
+ })).timeout(10000);
205
252
  });
206
253
  describe('diagnostics', () => {
207
254
  it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
208
255
  const doc = {
209
- uri: test_utils_1.uri('diagnosticsBar.ts'),
256
+ uri: (0, test_utils_1.uri)('diagnosticsBar.ts'),
210
257
  languageId: 'typescript',
211
258
  version: 1,
212
259
  text: `
@@ -228,7 +275,7 @@ describe('diagnostics', () => {
228
275
  })).timeout(10000);
229
276
  it('supports diagnostic tags', () => __awaiter(void 0, void 0, void 0, function* () {
230
277
  const doc = {
231
- uri: test_utils_1.uri('diagnosticsBar.ts'),
278
+ uri: (0, test_utils_1.uri)('diagnosticsBar.ts'),
232
279
  languageId: 'typescript',
233
280
  version: 1,
234
281
  text: `
@@ -257,7 +304,7 @@ describe('diagnostics', () => {
257
304
  })).timeout(10000);
258
305
  it('multiple files test', () => __awaiter(void 0, void 0, void 0, function* () {
259
306
  const doc = {
260
- uri: test_utils_1.uri('multipleFileDiagnosticsBar.ts'),
307
+ uri: (0, test_utils_1.uri)('multipleFileDiagnosticsBar.ts'),
261
308
  languageId: 'typescript',
262
309
  version: 1,
263
310
  text: `
@@ -267,7 +314,7 @@ describe('diagnostics', () => {
267
314
  `
268
315
  };
269
316
  const doc2 = {
270
- uri: test_utils_1.uri('multipleFileDiagnosticsFoo.ts'),
317
+ uri: (0, test_utils_1.uri)('multipleFileDiagnosticsFoo.ts'),
271
318
  languageId: 'typescript',
272
319
  version: 1,
273
320
  text: `
@@ -296,7 +343,7 @@ describe('diagnostics', () => {
296
343
  describe('document symbol', () => {
297
344
  it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
298
345
  const doc = {
299
- uri: test_utils_1.uri('bar.ts'),
346
+ uri: (0, test_utils_1.uri)('bar.ts'),
300
347
  languageId: 'typescript',
301
348
  version: 1,
302
349
  text: `
@@ -322,7 +369,7 @@ Foo
322
369
  })).timeout(10000);
323
370
  it('merges interfaces correctly', () => __awaiter(void 0, void 0, void 0, function* () {
324
371
  const doc = {
325
- uri: test_utils_1.uri('bar.ts'),
372
+ uri: (0, test_utils_1.uri)('bar.ts'),
326
373
  languageId: 'typescript',
327
374
  version: 1,
328
375
  text: `
@@ -352,7 +399,7 @@ Box
352
399
  })).timeout(10000);
353
400
  it('duplication test', () => __awaiter(void 0, void 0, void 0, function* () {
354
401
  const doc = {
355
- uri: test_utils_1.uri('bar.ts'),
402
+ uri: (0, test_utils_1.uri)('bar.ts'),
356
403
  languageId: 'typescript',
357
404
  version: 1,
358
405
  text: `
@@ -409,7 +456,7 @@ function symbolsAsString(symbols, indentation = '') {
409
456
  describe('editing', () => {
410
457
  it('open and change', () => __awaiter(void 0, void 0, void 0, function* () {
411
458
  const doc = {
412
- uri: test_utils_1.uri('openAndChangeBar.ts'),
459
+ uri: (0, test_utils_1.uri)('openAndChangeBar.ts'),
413
460
  languageId: 'typescript',
414
461
  version: 1,
415
462
  text: `
@@ -441,8 +488,42 @@ describe('editing', () => {
441
488
  assert.equal("Cannot find name 'missing'.", fileDiagnostics[0].message);
442
489
  })).timeout(10000);
443
490
  });
491
+ describe('workspace configuration', () => {
492
+ it('receives workspace configuration notification', () => __awaiter(void 0, void 0, void 0, function* () {
493
+ const doc = {
494
+ uri: (0, test_utils_1.uri)('bar.ts'),
495
+ languageId: 'typescript',
496
+ version: 1,
497
+ text: `
498
+ export function foo(): void {
499
+ console.log('test')
500
+ }
501
+ `
502
+ };
503
+ server.didOpenTextDocument({
504
+ textDocument: doc
505
+ });
506
+ server.didChangeConfiguration({
507
+ settings: {
508
+ typescript: {
509
+ format: {
510
+ insertSpaceAfterCommaDelimiter: true
511
+ }
512
+ },
513
+ javascript: {
514
+ format: {
515
+ insertSpaceAfterCommaDelimiter: false
516
+ }
517
+ }
518
+ }
519
+ });
520
+ const file = (0, test_utils_1.filePath)('bar.ts');
521
+ const settings = server.getWorkspacePreferencesForDocument(file);
522
+ assert.deepEqual(settings, { format: { insertSpaceAfterCommaDelimiter: true } });
523
+ }));
524
+ });
444
525
  describe('formatting', () => {
445
- const uriString = test_utils_1.uri('bar.ts');
526
+ const uriString = (0, test_utils_1.uri)('bar.ts');
446
527
  const languageId = 'typescript';
447
528
  const version = 1;
448
529
  it('full document formatting', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -493,6 +574,32 @@ describe('formatting', () => {
493
574
  const result = vscode_languageserver_textdocument_1.TextDocument.applyEdits(vscode_languageserver_textdocument_1.TextDocument.create(uriString, languageId, version, text), edits);
494
575
  assert.equal('function foo() {\n\t// some code\n}', result);
495
576
  })).timeout(10000);
577
+ it('formatting setting set through workspace configuration', () => __awaiter(void 0, void 0, void 0, function* () {
578
+ const text = 'function foo() {\n// some code\n}';
579
+ const textDocument = {
580
+ uri: uriString, languageId, version, text
581
+ };
582
+ server.didOpenTextDocument({ textDocument });
583
+ server.didChangeConfiguration({
584
+ settings: {
585
+ typescript: {
586
+ format: {
587
+ newLineCharacter: '\n',
588
+ placeOpenBraceOnNewLineForFunctions: true
589
+ }
590
+ }
591
+ }
592
+ });
593
+ const edits = yield server.documentFormatting({
594
+ textDocument,
595
+ options: {
596
+ tabSize: 4,
597
+ insertSpaces: false
598
+ }
599
+ });
600
+ const result = vscode_languageserver_textdocument_1.TextDocument.applyEdits(vscode_languageserver_textdocument_1.TextDocument.create(uriString, languageId, version, text), edits);
601
+ assert.equal('function foo()\n{\n\t// some code\n}', result);
602
+ })).timeout(10000);
496
603
  it('selected range', () => __awaiter(void 0, void 0, void 0, function* () {
497
604
  const text = 'function foo() {\nconst first = 1;\nconst second = 2;\nconst val = foo( "something" );\n//const fourth = 4;\n}';
498
605
  const textDocument = {
@@ -523,7 +630,7 @@ describe('formatting', () => {
523
630
  describe('signatureHelp', () => {
524
631
  it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
525
632
  const doc = {
526
- uri: test_utils_1.uri('bar.ts'),
633
+ uri: (0, test_utils_1.uri)('bar.ts'),
527
634
  languageId: 'typescript',
528
635
  version: 1,
529
636
  text: `
@@ -536,19 +643,19 @@ describe('signatureHelp', () => {
536
643
  });
537
644
  let result = (yield server.signatureHelp({
538
645
  textDocument: doc,
539
- position: test_utils_1.position(doc, 'param1')
646
+ position: (0, test_utils_1.position)(doc, 'param1')
540
647
  }));
541
648
  assert.equal('bar: string', result.signatures[result.activeSignature].parameters[result.activeParameter].label);
542
649
  result = (yield server.signatureHelp({
543
650
  textDocument: doc,
544
- position: test_utils_1.position(doc, 'param2')
651
+ position: (0, test_utils_1.position)(doc, 'param2')
545
652
  }));
546
653
  assert.equal('baz?: boolean', result.signatures[result.activeSignature].parameters[result.activeParameter].label);
547
654
  })).timeout(10000);
548
655
  });
549
656
  describe('code actions', () => {
550
657
  const doc = {
551
- uri: test_utils_1.uri('bar.ts'),
658
+ uri: (0, test_utils_1.uri)('bar.ts'),
552
659
  languageId: 'typescript',
553
660
  version: 1,
554
661
  text: `import { something } from "something";
@@ -590,7 +697,7 @@ describe('code actions', () => {
590
697
  documentChanges: [
591
698
  {
592
699
  textDocument: {
593
- uri: test_utils_1.uri('bar.ts'),
700
+ uri: (0, test_utils_1.uri)('bar.ts'),
594
701
  version: 1
595
702
  },
596
703
  edits: [
@@ -624,7 +731,7 @@ describe('code actions', () => {
624
731
  command: '_typescript.applyRefactoring',
625
732
  arguments: [
626
733
  {
627
- file: test_utils_1.filePath('bar.ts'),
734
+ file: (0, test_utils_1.filePath)('bar.ts'),
628
735
  startLine: 2,
629
736
  startOffset: 26,
630
737
  endLine: 2,
@@ -667,7 +774,7 @@ describe('code actions', () => {
667
774
  action: 'Convert parameters to destructured object',
668
775
  endLine: 2,
669
776
  endOffset: 50,
670
- file: test_utils_1.filePath('bar.ts'),
777
+ file: (0, test_utils_1.filePath)('bar.ts'),
671
778
  refactor: 'Convert parameters to destructured object',
672
779
  startLine: 2,
673
780
  startOffset: 26
@@ -681,7 +788,39 @@ describe('code actions', () => {
681
788
  }
682
789
  ]);
683
790
  })).timeout(10000);
791
+ it('does not provide organize imports when there are errors', () => __awaiter(void 0, void 0, void 0, function* () {
792
+ server.didOpenTextDocument({
793
+ textDocument: doc
794
+ });
795
+ const result = (yield server.codeAction({
796
+ textDocument: doc,
797
+ range: {
798
+ start: { line: 1, character: 29 },
799
+ end: { line: 1, character: 53 }
800
+ },
801
+ context: {
802
+ diagnostics: [{
803
+ range: {
804
+ start: { line: 1, character: 25 },
805
+ end: { line: 1, character: 49 }
806
+ },
807
+ code: 6133,
808
+ message: 'unused arg'
809
+ }],
810
+ only: [commands_1.CodeActions.SourceOrganizeImportsTsLs]
811
+ }
812
+ }));
813
+ assert.deepEqual(result, []);
814
+ })).timeout(10000);
684
815
  it('can provide organize imports when explicitly requested in only', () => __awaiter(void 0, void 0, void 0, function* () {
816
+ const doc = {
817
+ uri: (0, test_utils_1.uri)('bar.ts'),
818
+ languageId: 'typescript',
819
+ version: 1,
820
+ text: `import { existsSync } from 'fs';
821
+ import { accessSync } from 'fs';
822
+ existsSync('t');`
823
+ };
685
824
  server.didOpenTextDocument({
686
825
  textDocument: doc
687
826
  });
@@ -700,18 +839,51 @@ describe('code actions', () => {
700
839
  code: 6133,
701
840
  message: 'unused arg'
702
841
  }],
703
- only: ['source.organizeImports']
842
+ only: [commands_1.CodeActions.SourceOrganizeImportsTsLs]
704
843
  }
705
844
  }));
706
845
  assert.deepEqual(result, [
707
846
  {
708
- command: {
709
- arguments: [test_utils_1.filePath('bar.ts')],
710
- command: '_typescript.organizeImports',
711
- title: ''
712
- },
713
- kind: 'source.organizeImports',
714
- title: 'Organize imports'
847
+ kind: commands_1.CodeActions.SourceOrganizeImportsTsLs,
848
+ title: 'Organize imports',
849
+ edit: {
850
+ documentChanges: [
851
+ {
852
+ edits: [
853
+ {
854
+ newText: "import { accessSync, existsSync } from 'fs';\n",
855
+ range: {
856
+ end: {
857
+ character: 0,
858
+ line: 1
859
+ },
860
+ start: {
861
+ character: 0,
862
+ line: 0
863
+ }
864
+ }
865
+ },
866
+ {
867
+ newText: '',
868
+ range: {
869
+ end: {
870
+ character: 0,
871
+ line: 2
872
+ },
873
+ start: {
874
+ character: 0,
875
+ line: 1
876
+ }
877
+ }
878
+ }
879
+ ],
880
+ textDocument: {
881
+ uri: (0, test_utils_1.uri)('bar.ts'),
882
+ version: 1
883
+ }
884
+ }
885
+ ]
886
+ }
715
887
  }
716
888
  ]);
717
889
  })).timeout(10000);
@@ -719,7 +891,7 @@ describe('code actions', () => {
719
891
  describe('documentHighlight', () => {
720
892
  it('simple test', () => __awaiter(void 0, void 0, void 0, function* () {
721
893
  const barDoc = {
722
- uri: test_utils_1.uri('bar.d.ts'),
894
+ uri: (0, test_utils_1.uri)('bar.d.ts'),
723
895
  languageId: 'typescript',
724
896
  version: 1,
725
897
  text: `
@@ -732,7 +904,7 @@ describe('documentHighlight', () => {
732
904
  textDocument: barDoc
733
905
  });
734
906
  const fooDoc = {
735
- uri: test_utils_1.uri('bar.ts'),
907
+ uri: (0, test_utils_1.uri)('bar.ts'),
736
908
  languageId: 'typescript',
737
909
  version: 1,
738
910
  text: `
@@ -746,7 +918,7 @@ describe('documentHighlight', () => {
746
918
  });
747
919
  const result = yield server.documentHighlight({
748
920
  textDocument: fooDoc,
749
- position: test_utils_1.lastPosition(fooDoc, 'Bar')
921
+ position: (0, test_utils_1.lastPosition)(fooDoc, 'Bar')
750
922
  });
751
923
  assert.equal(2, result.length, JSON.stringify(result, undefined, 2));
752
924
  })).timeout(10000);
@@ -769,7 +941,7 @@ describe('calls', () => {
769
941
  return out.join('\n');
770
942
  }
771
943
  const doDoc = {
772
- uri: test_utils_1.uri('do.ts'),
944
+ uri: (0, test_utils_1.uri)('do.ts'),
773
945
  languageId: 'typescript',
774
946
  version: 1,
775
947
  text: `
@@ -787,7 +959,7 @@ export function three() {
787
959
  `
788
960
  };
789
961
  const fooDoc = {
790
- uri: test_utils_1.uri('foo.ts'),
962
+ uri: (0, test_utils_1.uri)('foo.ts'),
791
963
  languageId: 'typescript',
792
964
  version: 1,
793
965
  text: `import { doStuff } from './do';
@@ -866,17 +1038,17 @@ describe('diagnostics (no client support)', () => {
866
1038
  before(() => __awaiter(void 0, void 0, void 0, function* () {
867
1039
  var _a;
868
1040
  // Remove the "textDocument.publishDiagnostics" client capability.
869
- const clientCapabilitiesOverride = test_utils_1.getDefaultClientCapabilities();
1041
+ const clientCapabilitiesOverride = (0, test_utils_1.getDefaultClientCapabilities)();
870
1042
  (_a = clientCapabilitiesOverride.textDocument) === null || _a === void 0 ? true : delete _a.publishDiagnostics;
871
- server = yield test_utils_1.createServer({
1043
+ server = yield (0, test_utils_1.createServer)({
872
1044
  rootUri: null,
873
1045
  publishDiagnostics: args => diagnostics.set(args.uri, args),
874
1046
  clientCapabilitiesOverride
875
1047
  });
876
1048
  }));
877
- it('no diagnostics are published', () => __awaiter(void 0, void 0, void 0, function* () {
1049
+ it('diagnostics are published', () => __awaiter(void 0, void 0, void 0, function* () {
878
1050
  const doc = {
879
- uri: test_utils_1.uri('diagnosticsBar.ts'),
1051
+ uri: (0, test_utils_1.uri)('diagnosticsBar.ts'),
880
1052
  languageId: 'typescript',
881
1053
  version: 1,
882
1054
  text: `
@@ -891,7 +1063,82 @@ describe('diagnostics (no client support)', () => {
891
1063
  yield server.requestDiagnostics();
892
1064
  yield new Promise(resolve => setTimeout(resolve, 200));
893
1065
  const resultsForFile = diagnostics.get(doc.uri);
894
- assert.isUndefined(resultsForFile, 'Unexpected diagnostics received');
1066
+ assert.isDefined(resultsForFile);
1067
+ assert.strictEqual(resultsForFile === null || resultsForFile === void 0 ? void 0 : resultsForFile.diagnostics.length, 1);
1068
+ })).timeout(10000);
1069
+ });
1070
+ describe('inlayHints', () => {
1071
+ it('inlayHints', () => __awaiter(void 0, void 0, void 0, function* () {
1072
+ const doc = {
1073
+ uri: (0, test_utils_1.uri)('module.ts'),
1074
+ languageId: 'typescript',
1075
+ version: 1,
1076
+ text: `
1077
+ export function foo() {
1078
+ return 3
1079
+ }
1080
+ `
1081
+ };
1082
+ server.initialize({
1083
+ initializationOptions: {
1084
+ preferences: {
1085
+ includeInlayFunctionLikeReturnTypeHints: true
1086
+ }
1087
+ },
1088
+ processId: null,
1089
+ capabilities: (0, test_utils_1.getDefaultClientCapabilities)(),
1090
+ workspaceFolders: [],
1091
+ rootUri: ''
1092
+ });
1093
+ server.didOpenTextDocument({
1094
+ textDocument: doc
1095
+ });
1096
+ const { inlayHints } = yield server.inlayHints({
1097
+ textDocument: doc
1098
+ });
1099
+ assert.isDefined(inlayHints);
1100
+ assert.strictEqual(inlayHints.length, 1);
1101
+ assert.strictEqual(inlayHints[0].text, ': number');
1102
+ assert.strictEqual(inlayHints[0].kind, 'Type');
1103
+ assert.deepStrictEqual(inlayHints[0].position, { line: 1, character: 29 });
1104
+ })).timeout(10000);
1105
+ it('inlayHints options set through workspace configuration ', () => __awaiter(void 0, void 0, void 0, function* () {
1106
+ const doc = {
1107
+ uri: (0, test_utils_1.uri)('module.ts'),
1108
+ languageId: 'typescript',
1109
+ version: 1,
1110
+ text: `
1111
+ export function foo() {
1112
+ return 3
1113
+ }
1114
+ `
1115
+ };
1116
+ server.initialize({
1117
+ processId: null,
1118
+ capabilities: (0, test_utils_1.getDefaultClientCapabilities)(),
1119
+ workspaceFolders: [],
1120
+ rootUri: ''
1121
+ });
1122
+ server.didChangeConfiguration({
1123
+ settings: {
1124
+ typescript: {
1125
+ inlayHints: {
1126
+ includeInlayFunctionLikeReturnTypeHints: true
1127
+ }
1128
+ }
1129
+ }
1130
+ });
1131
+ server.didOpenTextDocument({
1132
+ textDocument: doc
1133
+ });
1134
+ const { inlayHints } = yield server.inlayHints({
1135
+ textDocument: doc
1136
+ });
1137
+ assert.isDefined(inlayHints);
1138
+ assert.strictEqual(inlayHints.length, 1);
1139
+ assert.strictEqual(inlayHints[0].text, ': number');
1140
+ assert.strictEqual(inlayHints[0].kind, 'Type');
1141
+ assert.deepStrictEqual(inlayHints[0].position, { line: 1, character: 29 });
895
1142
  })).timeout(10000);
896
1143
  });
897
1144
  //# sourceMappingURL=lsp-server.spec.js.map