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.
Files changed (67) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +245 -19
  3. package/lib/calls.js +9 -9
  4. package/lib/calls.js.map +1 -1
  5. package/lib/cli.js +3 -9
  6. package/lib/cli.js.map +1 -1
  7. package/lib/commands.d.ts +1 -1
  8. package/lib/commands.d.ts.map +1 -1
  9. package/lib/commands.js +1 -1
  10. package/lib/commands.js.map +1 -1
  11. package/lib/completion.d.ts.map +1 -1
  12. package/lib/completion.js +43 -31
  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 +8 -1
  34. package/lib/lsp-server.d.ts.map +1 -1
  35. package/lib/lsp-server.js +169 -98
  36. package/lib/lsp-server.js.map +1 -1
  37. package/lib/lsp-server.spec.js +234 -74
  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.map +1 -1
  42. package/lib/organize-imports.js +2 -1
  43. package/lib/organize-imports.js.map +1 -1
  44. package/lib/organize-imports.spec.js +6 -4
  45. package/lib/organize-imports.spec.js.map +1 -1
  46. package/lib/protocol-translation.d.ts +14 -1
  47. package/lib/protocol-translation.d.ts.map +1 -1
  48. package/lib/protocol-translation.js +28 -5
  49. package/lib/protocol-translation.js.map +1 -1
  50. package/lib/quickfix.js +1 -1
  51. package/lib/quickfix.js.map +1 -1
  52. package/lib/test-utils.d.ts.map +1 -1
  53. package/lib/test-utils.js +5 -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 -1
  59. package/lib/tsp-client.d.ts.map +1 -1
  60. package/lib/tsp-client.js +19 -7
  61. package/lib/tsp-client.js.map +1 -1
  62. package/lib/tsp-client.spec.js +60 -32
  63. package/lib/tsp-client.spec.js.map +1 -1
  64. package/lib/tsp-command-types.d.ts +2 -3
  65. package/lib/tsp-command-types.d.ts.map +1 -1
  66. package/lib/tsp-command-types.js.map +1 -1
  67. package/package.json +6 -6
package/lib/lsp-server.js CHANGED
@@ -65,8 +65,9 @@ class LspServer {
65
65
  constructor(options) {
66
66
  this.options = options;
67
67
  this.documents = new document_1.LspDocuments();
68
- this.requestDiagnostics = p_debounce_1.default(() => this.doRequestDiagnostics(), 200);
68
+ this.requestDiagnostics = (0, p_debounce_1.default)(() => this.doRequestDiagnostics(), 200);
69
69
  this.logger = new logger_1.PrefixingLogger(options.logger, '[lspserver]');
70
+ this.workspaceConfiguration = {};
70
71
  }
71
72
  closeAll() {
72
73
  for (const file of [...this.documents.files]) {
@@ -79,23 +80,23 @@ class LspServer {
79
80
  }
80
81
  const tsServerPath = path.join('typescript', 'lib', 'tsserver.js');
81
82
  // 1) look into .yarn/sdks of workspace root
82
- const sdk = modules_resolver_1.findPathToYarnSdk(this.rootPath(), tsServerPath);
83
+ const sdk = (0, modules_resolver_1.findPathToYarnSdk)(this.rootPath(), tsServerPath);
83
84
  if (sdk) {
84
85
  return sdk;
85
86
  }
86
87
  // 2) look into node_modules of workspace root
87
- const executable = modules_resolver_1.findPathToModule(this.rootPath(), tsServerPath);
88
+ const executable = (0, modules_resolver_1.findPathToModule)(this.rootPath(), tsServerPath);
88
89
  if (executable) {
89
90
  return executable;
90
91
  }
91
92
  // 3) use globally installed tsserver
92
- if (commandExists.sync(utils_1.getTsserverExecutable())) {
93
- return utils_1.getTsserverExecutable();
93
+ if (commandExists.sync((0, utils_1.getTsserverExecutable)())) {
94
+ return (0, utils_1.getTsserverExecutable)();
94
95
  }
95
96
  // 4) look into node_modules of typescript-language-server
96
- const bundled = modules_resolver_1.findPathToModule(__dirname, tsServerPath);
97
+ const bundled = (0, modules_resolver_1.findPathToModule)(__dirname, tsServerPath);
97
98
  if (!bundled) {
98
- throw Error(`Couldn't find '${utils_1.getTsserverExecutable()}' executable or 'tsserver.js' module`);
99
+ throw Error(`Couldn't find '${(0, utils_1.getTsserverExecutable)()}' executable or 'tsserver.js' module`);
99
100
  }
100
101
  return bundled;
101
102
  }
@@ -104,11 +105,9 @@ class LspServer {
104
105
  return __awaiter(this, void 0, void 0, function* () {
105
106
  this.logger.log('initialize', params);
106
107
  this.initializeParams = params;
107
- if ((_a = this.initializeParams.capabilities.textDocument) === null || _a === void 0 ? void 0 : _a.publishDiagnostics) {
108
- this.diagnosticQueue = new diagnostic_queue_1.DiagnosticEventQueue(diagnostics => this.options.lspClient.publishDiagnostics(diagnostics), this.documents, this.initializeParams.capabilities.textDocument.publishDiagnostics, this.logger);
109
- }
108
+ this.diagnosticQueue = new diagnostic_queue_1.DiagnosticEventQueue(diagnostics => this.options.lspClient.publishDiagnostics(diagnostics), this.documents, (_a = this.initializeParams.capabilities.textDocument) === null || _a === void 0 ? void 0 : _a.publishDiagnostics, this.logger);
110
109
  const userInitializationOptions = this.initializeParams.initializationOptions || {};
111
- const { hostInfo } = userInitializationOptions;
110
+ const { hostInfo, maxTsServerMemory } = userInitializationOptions;
112
111
  const { logVerbosity, plugins, preferences } = {
113
112
  logVerbosity: userInitializationOptions.logVerbosity || this.options.tsserverLogVerbosity,
114
113
  plugins: userInitializationOptions.plugins || [],
@@ -126,6 +125,7 @@ class LspServer {
126
125
  tsserverPath,
127
126
  logFile,
128
127
  logVerbosity,
128
+ maxTsServerMemory,
129
129
  globalPlugins,
130
130
  pluginProbeLocations,
131
131
  logger: this.options.logger,
@@ -143,7 +143,7 @@ class LspServer {
143
143
  allowNonTsExtensions: true
144
144
  }
145
145
  });
146
- const logFileUri = logFile && protocol_translation_1.pathToUri(logFile, undefined);
146
+ const logFileUri = logFile && (0, protocol_translation_1.pathToUri)(logFile, undefined);
147
147
  this.initializeResult = {
148
148
  capabilities: {
149
149
  textDocumentSync: lsp.TextDocumentSyncKind.Incremental,
@@ -203,13 +203,25 @@ class LspServer {
203
203
  return this.options.tsserverLogFile;
204
204
  }
205
205
  if (this.initializeParams.rootUri) {
206
- return path.join(protocol_translation_1.uriToPath(this.initializeParams.rootUri), '.log/tsserver.log');
206
+ return path.join((0, protocol_translation_1.uriToPath)(this.initializeParams.rootUri), '.log/tsserver.log');
207
207
  }
208
208
  if (this.initializeParams.rootPath) {
209
209
  return path.join(this.initializeParams.rootPath, '.log/tsserver.log');
210
210
  }
211
211
  return undefined;
212
212
  }
213
+ didChangeConfiguration(params) {
214
+ this.workspaceConfiguration = params.settings || {};
215
+ }
216
+ getWorkspacePreferencesForDocument(file) {
217
+ var _a;
218
+ const doc = this.documents.get(file);
219
+ if (!doc) {
220
+ return {};
221
+ }
222
+ const preferencesKey = doc.languageId.startsWith('typescript') ? 'typescript' : 'javascript';
223
+ return (_a = this.workspaceConfiguration[preferencesKey]) !== null && _a !== void 0 ? _a : {};
224
+ }
213
225
  interuptDiagnostics(f) {
214
226
  if (!this.diagnosticsTokenSource) {
215
227
  return f();
@@ -241,7 +253,7 @@ class LspServer {
241
253
  }
242
254
  }
243
255
  didOpenTextDocument(params) {
244
- const file = protocol_translation_1.uriToPath(params.textDocument.uri);
256
+ const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
245
257
  this.logger.log('onDidOpenTextDocument', params, file);
246
258
  if (!file) {
247
259
  return;
@@ -277,7 +289,7 @@ class LspServer {
277
289
  return undefined;
278
290
  }
279
291
  didCloseTextDocument(params) {
280
- const file = protocol_translation_1.uriToPath(params.textDocument.uri);
292
+ const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
281
293
  this.logger.log('onDidCloseTextDocument', params, file);
282
294
  if (!file) {
283
295
  return;
@@ -299,7 +311,7 @@ class LspServer {
299
311
  }
300
312
  didChangeTextDocument(params) {
301
313
  const { textDocument } = params;
302
- const file = protocol_translation_1.uriToPath(textDocument.uri);
314
+ const file = (0, protocol_translation_1.uriToPath)(textDocument.uri);
303
315
  this.logger.log('onDidChangeTextDocument', params, file);
304
316
  if (!file) {
305
317
  return;
@@ -372,7 +384,7 @@ class LspServer {
372
384
  }
373
385
  getDefinition({ type, params }) {
374
386
  return __awaiter(this, void 0, void 0, function* () {
375
- const file = protocol_translation_1.uriToPath(params.textDocument.uri);
387
+ const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
376
388
  this.logger.log(type, params, file);
377
389
  if (!file) {
378
390
  return [];
@@ -382,12 +394,12 @@ class LspServer {
382
394
  line: params.position.line + 1,
383
395
  offset: params.position.character + 1
384
396
  });
385
- return result.body ? result.body.map(fileSpan => protocol_translation_1.toLocation(fileSpan, this.documents)) : [];
397
+ return result.body ? result.body.map(fileSpan => (0, protocol_translation_1.toLocation)(fileSpan, this.documents)) : [];
386
398
  });
387
399
  }
388
400
  documentSymbol(params) {
389
401
  return __awaiter(this, void 0, void 0, function* () {
390
- const file = protocol_translation_1.uriToPath(params.textDocument.uri);
402
+ const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
391
403
  this.logger.log('symbol', params, file);
392
404
  if (!file) {
393
405
  return [];
@@ -402,13 +414,13 @@ class LspServer {
402
414
  if (this.supportHierarchicalDocumentSymbol) {
403
415
  const symbols = [];
404
416
  for (const item of tree.childItems) {
405
- document_symbol_1.collectDocumentSymbols(item, symbols);
417
+ (0, document_symbol_1.collectDocumentSymbols)(item, symbols);
406
418
  }
407
419
  return symbols;
408
420
  }
409
421
  const symbols = [];
410
422
  for (const item of tree.childItems) {
411
- document_symbol_1.collectSymbolInformation(params.textDocument.uri, item, symbols);
423
+ (0, document_symbol_1.collectSymbolInformation)(params.textDocument.uri, item, symbols);
412
424
  }
413
425
  return symbols;
414
426
  });
@@ -424,7 +436,7 @@ class LspServer {
424
436
  */
425
437
  completion(params) {
426
438
  return __awaiter(this, void 0, void 0, function* () {
427
- const file = protocol_translation_1.uriToPath(params.textDocument.uri);
439
+ const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
428
440
  this.logger.log('completion', params, file);
429
441
  if (!file) {
430
442
  return lsp.CompletionList.create([]);
@@ -442,7 +454,7 @@ class LspServer {
442
454
  const { body } = result;
443
455
  const completions = (body ? body.entries : [])
444
456
  .filter(entry => entry.kind !== 'warning')
445
- .map(entry => completion_1.asCompletionItem(entry, file, params.position, document));
457
+ .map(entry => (0, completion_1.asCompletionItem)(entry, file, params.position, document));
446
458
  return lsp.CompletionList.create(completions, body === null || body === void 0 ? void 0 : body.isIncomplete);
447
459
  }
448
460
  catch (error) {
@@ -464,12 +476,12 @@ class LspServer {
464
476
  if (!details) {
465
477
  return item;
466
478
  }
467
- return completion_1.asResolvedCompletionItem(item, details);
479
+ return (0, completion_1.asResolvedCompletionItem)(item, details);
468
480
  });
469
481
  }
470
482
  hover(params) {
471
483
  return __awaiter(this, void 0, void 0, function* () {
472
- const file = protocol_translation_1.uriToPath(params.textDocument.uri);
484
+ const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
473
485
  this.logger.log('hover', params, file);
474
486
  if (!file) {
475
487
  return { contents: [] };
@@ -478,12 +490,13 @@ class LspServer {
478
490
  if (!result || !result.body) {
479
491
  return { contents: [] };
480
492
  }
481
- const range = protocol_translation_1.asRange(result.body);
482
- const contents = [
483
- { language: 'typescript', value: result.body.displayString }
484
- ];
485
- const tags = protocol_translation_1.asTagsDocumentation(result.body.tags);
486
- const documentation = protocol_translation_1.asPlainText(result.body.documentation);
493
+ const range = (0, protocol_translation_1.asRange)(result.body);
494
+ const contents = [];
495
+ if (result.body.displayString) {
496
+ contents.push({ language: 'typescript', value: result.body.displayString });
497
+ }
498
+ const tags = (0, protocol_translation_1.asTagsDocumentation)(result.body.tags);
499
+ const documentation = (0, protocol_translation_1.asPlainText)(result.body.documentation);
487
500
  contents.push(documentation + (tags ? '\n\n' + tags : ''));
488
501
  return {
489
502
  contents,
@@ -507,7 +520,7 @@ class LspServer {
507
520
  }
508
521
  rename(params) {
509
522
  return __awaiter(this, void 0, void 0, function* () {
510
- const file = protocol_translation_1.uriToPath(params.textDocument.uri);
523
+ const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
511
524
  this.logger.log('onRename', params, file);
512
525
  if (!file) {
513
526
  return undefined;
@@ -525,13 +538,13 @@ class LspServer {
525
538
  };
526
539
  result.body.locs
527
540
  .forEach((spanGroup) => {
528
- const uri = protocol_translation_1.pathToUri(spanGroup.file, this.documents), textEdits = workspaceEdit.changes[uri] || (workspaceEdit.changes[uri] = []);
541
+ const uri = (0, protocol_translation_1.pathToUri)(spanGroup.file, this.documents), textEdits = workspaceEdit.changes[uri] || (workspaceEdit.changes[uri] = []);
529
542
  spanGroup.locs.forEach((textSpan) => {
530
543
  textEdits.push({
531
544
  newText: params.newName,
532
545
  range: {
533
- start: protocol_translation_1.toPosition(textSpan.start),
534
- end: protocol_translation_1.toPosition(textSpan.end)
546
+ start: (0, protocol_translation_1.toPosition)(textSpan.start),
547
+ end: (0, protocol_translation_1.toPosition)(textSpan.end)
535
548
  }
536
549
  });
537
550
  });
@@ -541,7 +554,7 @@ class LspServer {
541
554
  }
542
555
  references(params) {
543
556
  return __awaiter(this, void 0, void 0, function* () {
544
- const file = protocol_translation_1.uriToPath(params.textDocument.uri);
557
+ const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
545
558
  this.logger.log('onReferences', params, file);
546
559
  if (!file) {
547
560
  return [];
@@ -555,33 +568,20 @@ class LspServer {
555
568
  return [];
556
569
  }
557
570
  return result.body.refs
558
- .map(fileSpan => protocol_translation_1.toLocation(fileSpan, this.documents));
571
+ .map(fileSpan => (0, protocol_translation_1.toLocation)(fileSpan, this.documents));
559
572
  });
560
573
  }
561
574
  documentFormatting(params) {
562
575
  return __awaiter(this, void 0, void 0, function* () {
563
- const file = protocol_translation_1.uriToPath(params.textDocument.uri);
576
+ const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
564
577
  this.logger.log('documentFormatting', params, file);
565
578
  if (!file) {
566
579
  return [];
567
580
  }
568
- let opts = Object.assign({}, params.options);
569
- // translate
570
- if (opts.convertTabsToSpaces === undefined) {
571
- opts.convertTabsToSpaces = params.options.insertSpaces;
572
- }
573
- if (opts.indentSize === undefined) {
574
- opts.indentSize = params.options.tabSize;
575
- }
576
- try {
577
- opts = JSON.parse(fs.readFileSync(this.rootPath() + '/tsfmt.json', 'utf-8'));
578
- }
579
- catch (err) {
580
- this.logger.log(`No formatting options found ${err}`);
581
- }
581
+ const formatOptions = this.getFormattingOptions(file, params.options);
582
582
  // options are not yet supported in tsserver, but we can send a configure request first
583
583
  yield this.tspClient.request("configure" /* Configure */, {
584
- formatOptions: opts
584
+ formatOptions
585
585
  });
586
586
  const response = yield this.tspClient.request("format" /* Format */, {
587
587
  file,
@@ -589,38 +589,25 @@ class LspServer {
589
589
  offset: 1,
590
590
  endLine: Number.MAX_SAFE_INTEGER,
591
591
  endOffset: Number.MAX_SAFE_INTEGER,
592
- options: opts
592
+ options: formatOptions
593
593
  });
594
594
  if (response.body) {
595
- return response.body.map(e => protocol_translation_1.toTextEdit(e));
595
+ return response.body.map(e => (0, protocol_translation_1.toTextEdit)(e));
596
596
  }
597
597
  return [];
598
598
  });
599
599
  }
600
600
  documentRangeFormatting(params) {
601
601
  return __awaiter(this, void 0, void 0, function* () {
602
- const file = protocol_translation_1.uriToPath(params.textDocument.uri);
602
+ const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
603
603
  this.logger.log('documentRangeFormatting', params, file);
604
604
  if (!file) {
605
605
  return [];
606
606
  }
607
- let opts = Object.assign({}, params.options);
608
- // translate
609
- if (opts.convertTabsToSpaces === undefined) {
610
- opts.convertTabsToSpaces = params.options.insertSpaces;
611
- }
612
- if (opts.indentSize === undefined) {
613
- opts.indentSize = params.options.tabSize;
614
- }
615
- try {
616
- opts = JSON.parse(fs.readFileSync(this.rootPath() + '/tsfmt.json', 'utf-8'));
617
- }
618
- catch (err) {
619
- this.logger.log(`No formatting options found ${err}`);
620
- }
607
+ const formatOptions = this.getFormattingOptions(file, params.options);
621
608
  // options are not yet supported in tsserver, but we can send a configure request first
622
609
  yield this.tspClient.request("configure" /* Configure */, {
623
- formatOptions: opts
610
+ formatOptions
624
611
  });
625
612
  const response = yield this.tspClient.request("format" /* Format */, {
626
613
  file,
@@ -628,17 +615,35 @@ class LspServer {
628
615
  offset: params.range.start.character + 1,
629
616
  endLine: params.range.end.line + 1,
630
617
  endOffset: params.range.end.character + 1,
631
- options: opts
618
+ options: formatOptions
632
619
  });
633
620
  if (response.body) {
634
- return response.body.map(e => protocol_translation_1.toTextEdit(e));
621
+ return response.body.map(e => (0, protocol_translation_1.toTextEdit)(e));
635
622
  }
636
623
  return [];
637
624
  });
638
625
  }
626
+ getFormattingOptions(file, requestOptions) {
627
+ const workspacePreference = this.getWorkspacePreferencesForDocument(file);
628
+ let opts = Object.assign(Object.assign({}, (workspacePreference === null || workspacePreference === void 0 ? void 0 : workspacePreference.format) || {}), requestOptions);
629
+ // translate
630
+ if (opts.convertTabsToSpaces === undefined) {
631
+ opts.convertTabsToSpaces = requestOptions.insertSpaces;
632
+ }
633
+ if (opts.indentSize === undefined) {
634
+ opts.indentSize = requestOptions.tabSize;
635
+ }
636
+ try {
637
+ opts = JSON.parse(fs.readFileSync(this.rootPath() + '/tsfmt.json', 'utf-8'));
638
+ }
639
+ catch (err) {
640
+ this.logger.log(`No formatting options found ${err}`);
641
+ }
642
+ return opts;
643
+ }
639
644
  signatureHelp(params) {
640
645
  return __awaiter(this, void 0, void 0, function* () {
641
- const file = protocol_translation_1.uriToPath(params.textDocument.uri);
646
+ const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
642
647
  this.logger.log('signatureHelp', params, file);
643
648
  if (!file) {
644
649
  return undefined;
@@ -647,7 +652,7 @@ class LspServer {
647
652
  if (!response || !response.body) {
648
653
  return undefined;
649
654
  }
650
- return hover_1.asSignatureHelp(response.body);
655
+ return (0, hover_1.asSignatureHelp)(response.body);
651
656
  });
652
657
  }
653
658
  getSignatureHelp(file, position) {
@@ -666,23 +671,23 @@ class LspServer {
666
671
  }
667
672
  codeAction(params) {
668
673
  return __awaiter(this, void 0, void 0, function* () {
669
- const file = protocol_translation_1.uriToPath(params.textDocument.uri);
674
+ const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
670
675
  this.logger.log('codeAction', params, file);
671
676
  if (!file) {
672
677
  return [];
673
678
  }
674
- const args = protocol_translation_1.toFileRangeRequestArgs(file, params.range);
679
+ const args = (0, protocol_translation_1.toFileRangeRequestArgs)(file, params.range);
675
680
  const actions = [];
676
681
  if (!params.context.only || params.context.only.includes(node_1.CodeActionKind.QuickFix)) {
677
682
  const errorCodes = params.context.diagnostics.map(diagnostic => Number(diagnostic.code));
678
- actions.push(...quickfix_1.provideQuickFix(yield this.getCodeFixes(Object.assign(Object.assign({}, args), { errorCodes })), this.documents));
683
+ actions.push(...(0, quickfix_1.provideQuickFix)(yield this.getCodeFixes(Object.assign(Object.assign({}, args), { errorCodes })), this.documents));
679
684
  }
680
685
  if (!params.context.only || params.context.only.includes(node_1.CodeActionKind.Refactor)) {
681
- actions.push(...refactor_1.provideRefactors(yield this.getRefactors(args), args));
686
+ actions.push(...(0, refactor_1.provideRefactors)(yield this.getRefactors(args), args));
682
687
  }
683
688
  // organize import is provided by tsserver for any line, so we only get it if explicitly requested
684
689
  if (params.context.only && params.context.only.includes(node_1.CodeActionKind.SourceOrganizeImports)) {
685
- actions.push(...organize_imports_1.provideOrganizeImports(yield this.getOrganizeImports({ scope: { type: 'file', args } })));
690
+ actions.push(...(0, organize_imports_1.provideOrganizeImports)(yield this.getOrganizeImports({ scope: { type: 'file', args } })));
686
691
  }
687
692
  return actions;
688
693
  });
@@ -753,9 +758,9 @@ class LspServer {
753
758
  if (renameLocation) {
754
759
  yield this.options.lspClient.rename({
755
760
  textDocument: {
756
- uri: protocol_translation_1.pathToUri(args.file, this.documents)
761
+ uri: (0, protocol_translation_1.pathToUri)(args.file, this.documents)
757
762
  },
758
- position: protocol_translation_1.toPosition(renameLocation)
763
+ position: (0, protocol_translation_1.toPosition)(renameLocation)
759
764
  });
760
765
  }
761
766
  }
@@ -773,6 +778,19 @@ class LspServer {
773
778
  const { sourceUri, targetUri } = arg.arguments[0];
774
779
  this.applyRenameFile(sourceUri, targetUri);
775
780
  }
781
+ else if (arg.command === commands_1.Commands.APPLY_COMPLETION_CODE_ACTION && arg.arguments) {
782
+ const [_, codeActions] = arg.arguments;
783
+ for (const codeAction of codeActions) {
784
+ yield this.applyFileCodeEdits(codeAction.changes);
785
+ if (codeAction.commands && codeAction.commands.length) {
786
+ for (const command of codeAction.commands) {
787
+ yield this.tspClient.request("applyCodeActionCommand" /* ApplyCodeActionCommand */, { command });
788
+ }
789
+ }
790
+ // Execute only the first code action.
791
+ break;
792
+ }
793
+ }
776
794
  else {
777
795
  this.logger.error(`Unknown command ${arg.command}.`);
778
796
  }
@@ -785,7 +803,7 @@ class LspServer {
785
803
  }
786
804
  const changes = {};
787
805
  for (const edit of edits) {
788
- changes[protocol_translation_1.pathToUri(edit.fileName, this.documents)] = edit.textChanges.map(protocol_translation_1.toTextEdit);
806
+ changes[(0, protocol_translation_1.pathToUri)(edit.fileName, this.documents)] = edit.textChanges.map(protocol_translation_1.toTextEdit);
789
807
  }
790
808
  const { applied } = yield this.options.lspClient.applyWorkspaceEdit({
791
809
  edit: { changes }
@@ -801,8 +819,8 @@ class LspServer {
801
819
  }
802
820
  getEditsForFileRename(sourceUri, targetUri) {
803
821
  return __awaiter(this, void 0, void 0, function* () {
804
- const newFilePath = protocol_translation_1.uriToPath(targetUri);
805
- const oldFilePath = protocol_translation_1.uriToPath(sourceUri);
822
+ const newFilePath = (0, protocol_translation_1.uriToPath)(targetUri);
823
+ const oldFilePath = (0, protocol_translation_1.uriToPath)(sourceUri);
806
824
  if (!newFilePath || !oldFilePath) {
807
825
  return [];
808
826
  }
@@ -820,7 +838,7 @@ class LspServer {
820
838
  }
821
839
  documentHighlight(arg) {
822
840
  return __awaiter(this, void 0, void 0, function* () {
823
- const file = protocol_translation_1.uriToPath(arg.textDocument.uri);
841
+ const file = (0, protocol_translation_1.uriToPath)(arg.textDocument.uri);
824
842
  this.logger.log('documentHighlight', arg, file);
825
843
  if (!file) {
826
844
  return [];
@@ -844,8 +862,8 @@ class LspServer {
844
862
  for (const item of response.body) {
845
863
  // tsp returns item.file with POSIX path delimiters, whereas file is platform specific.
846
864
  // Converting to a URI and back to a path ensures consistency.
847
- if (protocol_translation_1.uriToPath(protocol_translation_1.pathToUri(item.file, this.documents)) === file) {
848
- const highlights = protocol_translation_1.toDocumentHighlight(item);
865
+ if ((0, protocol_translation_1.normalizePath)(item.file) === file) {
866
+ const highlights = (0, protocol_translation_1.toDocumentHighlight)(item);
849
867
  result.push(...highlights);
850
868
  }
851
869
  }
@@ -853,7 +871,7 @@ class LspServer {
853
871
  });
854
872
  }
855
873
  rootPath() {
856
- return this.initializeParams.rootUri ? protocol_translation_1.uriToPath(this.initializeParams.rootUri) : this.initializeParams.rootPath;
874
+ return this.initializeParams.rootUri ? (0, protocol_translation_1.uriToPath)(this.initializeParams.rootUri) : this.initializeParams.rootPath;
857
875
  }
858
876
  lastFileOrDummy() {
859
877
  return this.documents.files[0] || this.rootPath();
@@ -870,13 +888,13 @@ class LspServer {
870
888
  return result.body.map(item => {
871
889
  return {
872
890
  location: {
873
- uri: protocol_translation_1.pathToUri(item.file, this.documents),
891
+ uri: (0, protocol_translation_1.pathToUri)(item.file, this.documents),
874
892
  range: {
875
- start: protocol_translation_1.toPosition(item.start),
876
- end: protocol_translation_1.toPosition(item.end)
893
+ start: (0, protocol_translation_1.toPosition)(item.start),
894
+ end: (0, protocol_translation_1.toPosition)(item.end)
877
895
  }
878
896
  },
879
- kind: protocol_translation_1.toSymbolKind(item.kind),
897
+ kind: (0, protocol_translation_1.toSymbolKind)(item.kind),
880
898
  name: item.name
881
899
  };
882
900
  });
@@ -887,7 +905,7 @@ class LspServer {
887
905
  */
888
906
  foldingRanges(params) {
889
907
  return __awaiter(this, void 0, void 0, function* () {
890
- const file = protocol_translation_1.uriToPath(params.textDocument.uri);
908
+ const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
891
909
  this.logger.log('foldingRanges', params, file);
892
910
  if (!file) {
893
911
  return undefined;
@@ -911,7 +929,7 @@ class LspServer {
911
929
  });
912
930
  }
913
931
  asFoldingRange(span, document) {
914
- const range = protocol_translation_1.asRange(span.textSpan);
932
+ const range = (0, protocol_translation_1.asRange)(span.textSpan);
915
933
  const kind = this.asFoldingRangeKind(span);
916
934
  // workaround for https://github.com/Microsoft/vscode/issues/49904
917
935
  if (span.kind === 'comment') {
@@ -954,21 +972,74 @@ class LspServer {
954
972
  calls(params) {
955
973
  return __awaiter(this, void 0, void 0, function* () {
956
974
  let callsResult = { calls: [] };
957
- const file = protocol_translation_1.uriToPath(params.textDocument.uri);
975
+ const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
958
976
  this.logger.log('calls', params, file);
959
977
  if (!file) {
960
978
  return callsResult;
961
979
  }
962
980
  if (params.direction === lspcalls.CallDirection.Outgoing) {
963
981
  const documentProvider = (file) => this.documents.get(file);
964
- callsResult = yield calls_1.computeCallees(this.tspClient, params, documentProvider);
982
+ callsResult = yield (0, calls_1.computeCallees)(this.tspClient, params, documentProvider);
965
983
  }
966
984
  else {
967
- callsResult = yield calls_1.computeCallers(this.tspClient, params);
985
+ callsResult = yield (0, calls_1.computeCallers)(this.tspClient, params);
968
986
  }
969
987
  return callsResult;
970
988
  });
971
989
  }
990
+ inlayHints(params) {
991
+ var _a, _b, _c, _d, _e, _f;
992
+ return __awaiter(this, void 0, void 0, function* () {
993
+ const file = (0, protocol_translation_1.uriToPath)(params.textDocument.uri);
994
+ this.logger.log('inlayHints', params, file);
995
+ if (!file) {
996
+ return { inlayHints: [] };
997
+ }
998
+ const inlayHintsOptions = this.getInlayHintsOptions(file);
999
+ this.tspClient.request("configure" /* Configure */, {
1000
+ preferences: inlayHintsOptions
1001
+ });
1002
+ const doc = this.documents.get(file);
1003
+ if (!doc) {
1004
+ return { inlayHints: [] };
1005
+ }
1006
+ const start = doc.offsetAt((_b = (_a = params.range) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : {
1007
+ line: 0,
1008
+ character: 0
1009
+ });
1010
+ const end = doc.offsetAt((_d = (_c = params.range) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : {
1011
+ line: doc.lineCount + 1,
1012
+ character: 0
1013
+ });
1014
+ try {
1015
+ const result = yield this.tspClient.request("provideInlayHints" /* ProvideInlayHints */, {
1016
+ file,
1017
+ start: start,
1018
+ length: end - start
1019
+ });
1020
+ return {
1021
+ inlayHints: (_f = (_e = result.body) === null || _e === void 0 ? void 0 : _e.map((item) => ({
1022
+ text: item.text,
1023
+ position: (0, protocol_translation_1.toPosition)(item.position),
1024
+ whitespaceAfter: item.whitespaceAfter,
1025
+ whitespaceBefore: item.whitespaceBefore,
1026
+ kind: item.kind
1027
+ }))) !== null && _f !== void 0 ? _f : []
1028
+ };
1029
+ }
1030
+ catch (_g) {
1031
+ return {
1032
+ inlayHints: []
1033
+ };
1034
+ }
1035
+ });
1036
+ }
1037
+ getInlayHintsOptions(file) {
1038
+ var _a, _b;
1039
+ const workspacePreference = this.getWorkspacePreferencesForDocument(file);
1040
+ const userPreferences = ((_a = this.initializeParams.initializationOptions) === null || _a === void 0 ? void 0 : _a.preferences) || {};
1041
+ return Object.assign(Object.assign({}, userPreferences), (_b = workspacePreference.inlayHints) !== null && _b !== void 0 ? _b : {});
1042
+ }
972
1043
  }
973
1044
  exports.LspServer = LspServer;
974
1045
  //# sourceMappingURL=lsp-server.js.map