typescript-language-server 4.3.1 → 4.3.2

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 CHANGED
@@ -1,6 +1,13 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [4.3.2](https://github.com/typescript-language-server/typescript-language-server/compare/v4.3.1...v4.3.2) (2024-02-02)
5
+
6
+
7
+ ### Bug Fixes
8
+
9
+ * restore handling of zipfile: schema for neovim + yarn berry ([#862](https://github.com/typescript-language-server/typescript-language-server/issues/862)) ([caca007](https://github.com/typescript-language-server/typescript-language-server/commit/caca0071095557ecc43d8695d922a4cf5e38a2ad))
10
+
4
11
  ## [4.3.1](https://github.com/typescript-language-server/typescript-language-server/compare/v4.3.0...v4.3.1) (2024-01-12)
5
12
 
6
13
 
package/lib/cli.mjs CHANGED
@@ -17645,14 +17645,24 @@ class LspDocuments {
17645
17645
 
17646
17646
  const file = 'file';
17647
17647
 
17648
+ const untitled = 'untitled';
17649
+
17648
17650
  const git = 'git';
17649
17651
 
17650
17652
  const github = 'github';
17651
17653
 
17652
17654
  const azurerepos = 'azurerepos';
17653
17655
 
17656
+ const buffer = 'buffer';
17657
+
17658
+ const zipfile = 'zipfile';
17659
+
17654
17660
  const vsls = 'vsls';
17655
17661
 
17662
+ function getSemanticSupportedSchemes() {
17663
+ return [ file, untitled, buffer, zipfile ];
17664
+ }
17665
+
17656
17666
  const disabledSchemes = new Set([ git, vsls, github, azurerepos ]);
17657
17667
 
17658
17668
  var TypeScriptServerPlugin;
@@ -18866,6 +18876,20 @@ class Tracer {
18866
18876
  }
18867
18877
  }
18868
18878
 
18879
+ class ZipfileURI extends URI {
18880
+ constructor(uri, components) {
18881
+ super(components);
18882
+ this._originalUri = uri;
18883
+ }
18884
+ toString(_skipEncoding = false) {
18885
+ return this._originalUri;
18886
+ }
18887
+ static parse(value, _strict = false) {
18888
+ const uri = URI.parse(value, _strict);
18889
+ return new ZipfileURI(value, uri);
18890
+ }
18891
+ }
18892
+
18869
18893
  var ServerState;
18870
18894
 
18871
18895
  (function(ServerState) {
@@ -18937,11 +18961,18 @@ class ServerInitializingIndicator {
18937
18961
  }
18938
18962
  }
18939
18963
 
18964
+ const emptyAuthority = 'ts-nul-authority';
18965
+
18966
+ const inMemoryResourcePrefix = '^';
18967
+
18968
+ const RE_IN_MEMORY_FILEPATH = /^\^\/([^/]+)\/([^/]*)\/(.+)$/;
18969
+
18940
18970
  class TsClient {
18941
18971
  constructor(onCaseInsensitiveFileSystem, logger, lspClient) {
18942
18972
  this.apiVersion = API.defaultVersion;
18943
18973
  this.typescriptVersionSource = 'bundled';
18944
18974
  this.serverState = ServerState.None;
18975
+ this.isNeovimHost = false;
18945
18976
  this.workspaceFolders = [];
18946
18977
  this.useSyntaxServer = 2;
18947
18978
  this.pluginManager = new PluginManager;
@@ -18967,7 +18998,7 @@ class TsClient {
18967
18998
  return this.documents.files[0] || this.workspaceFolders[0]?.uri.fsPath;
18968
18999
  }
18969
19000
  toTsFilePath(stringUri) {
18970
- if (stringUri.startsWith('zipfile:')) {
19001
+ if (this.isNeovimHost && stringUri.startsWith('zipfile:')) {
18971
19002
  return stringUri;
18972
19003
  }
18973
19004
  const resource = URI.parse(stringUri);
@@ -18977,7 +19008,7 @@ class TsClient {
18977
19008
  if (resource.scheme === file) {
18978
19009
  return resource.fsPath;
18979
19010
  }
18980
- return undefined;
19011
+ return inMemoryResourcePrefix + '/' + resource.scheme + '/' + (resource.authority || emptyAuthority) + (resource.path.startsWith('/') ? resource.path : '/' + resource.path) + (resource.fragment ? '#' + resource.fragment : '');
18981
19012
  }
18982
19013
  toOpenDocument(textDocumentUri, options = {}) {
18983
19014
  const filepath = this.toTsFilePath(textDocumentUri);
@@ -18998,13 +19029,25 @@ class TsClient {
18998
19029
  return this.documents.hasPendingDiagnostics(resource);
18999
19030
  }
19000
19031
  toResource(filepath) {
19001
- if (filepath.startsWith('zipfile:')) {
19002
- return URI.parse(filepath);
19032
+ if (this.isNeovimHost && filepath.startsWith('zipfile:')) {
19033
+ return ZipfileURI.parse(filepath);
19034
+ }
19035
+ if (filepath.startsWith(inMemoryResourcePrefix)) {
19036
+ const parts = filepath.match(RE_IN_MEMORY_FILEPATH);
19037
+ if (parts) {
19038
+ const resource = URI.parse(parts[1] + '://' + (parts[2] === emptyAuthority ? '' : parts[2]) + '/' + parts[3]);
19039
+ const tsFilepath = this.toTsFilePath(resource.toString());
19040
+ const document = tsFilepath && this.documents.get(tsFilepath);
19041
+ return document ? document.uri : resource;
19042
+ }
19003
19043
  }
19004
19044
  const fileUri = URI.file(filepath);
19005
19045
  const document = this.documents.get(fileUri.fsPath);
19006
19046
  return document ? document.uri : fileUri;
19007
19047
  }
19048
+ toResourceUri(filepath) {
19049
+ return this.toResource(filepath).toString();
19050
+ }
19008
19051
  getWorkspaceRootForResource(resource) {
19009
19052
  for (const root of this.workspaceFolders.sort(((a, b) => a.uri.fsPath.length - b.uri.fsPath.length))) {
19010
19053
  if (root.uri.scheme === resource.scheme && root.uri.authority === resource.authority) {
@@ -19031,7 +19074,7 @@ class TsClient {
19031
19074
  switch (capability) {
19032
19075
  case ClientCapability.Semantic:
19033
19076
  {
19034
- return [ 'file', 'untitled' ].includes(resource.scheme);
19077
+ return getSemanticSupportedSchemes().includes(resource.scheme);
19035
19078
  }
19036
19079
 
19037
19080
  case ClientCapability.Syntax:
@@ -19052,6 +19095,7 @@ class TsClient {
19052
19095
  start(workspaceRoot, options) {
19053
19096
  this.apiVersion = options.typescriptVersion.version || API.defaultVersion;
19054
19097
  this.typescriptVersionSource = options.typescriptVersion.source;
19098
+ this.isNeovimHost = options.hostInfo === 'neovim';
19055
19099
  this.tracer = new Tracer(this.tsserverLogger, options.trace);
19056
19100
  this.workspaceFolders = workspaceRoot ? [ {
19057
19101
  uri: URI.file(workspaceRoot)
@@ -19391,9 +19435,9 @@ var Location;
19391
19435
  })(Location || (Location = {}));
19392
19436
 
19393
19437
  function toLocation(fileSpan, client) {
19394
- const uri = client.toResource(fileSpan.file);
19438
+ const uri = client.toResourceUri(fileSpan.file);
19395
19439
  return {
19396
- uri: uri.toString(),
19440
+ uri: uri,
19397
19441
  range: {
19398
19442
  start: Position.fromLocation(fileSpan.start),
19399
19443
  end: Position.fromLocation(fileSpan.end)
@@ -19505,11 +19549,11 @@ function toTextEdit(edit) {
19505
19549
  }
19506
19550
 
19507
19551
  function toTextDocumentEdit(change, client) {
19508
- const uri = client.toResource(change.fileName);
19509
- const document = client.toOpenDocument(uri.toString());
19552
+ const uri = client.toResourceUri(change.fileName);
19553
+ const document = client.toOpenDocument(uri);
19510
19554
  return {
19511
19555
  textDocument: {
19512
- uri: uri.toString(),
19556
+ uri: uri,
19513
19557
  version: document?.version ?? null
19514
19558
  },
19515
19559
  edits: change.textChanges.map((c => toTextEdit(c)))
@@ -19607,7 +19651,7 @@ class DiagnosticEventQueue {
19607
19651
  if (this.ignoredDiagnosticCodes.size) {
19608
19652
  diagnostics = diagnostics.filter((diagnostic => !this.isDiagnosticIgnored(diagnostic)));
19609
19653
  }
19610
- const uri = this.client.toResource(file).toString();
19654
+ const uri = this.client.toResourceUri(file);
19611
19655
  const diagnosticsForFile = this.diagnostics.get(uri) || new FileDiagnostics(uri, this.publishDiagnostics, this.client, this.features);
19612
19656
  diagnosticsForFile.update(kind, diagnostics);
19613
19657
  this.diagnostics.set(uri, diagnosticsForFile);
@@ -19616,17 +19660,17 @@ class DiagnosticEventQueue {
19616
19660
  this.ignoredDiagnosticCodes = new Set(ignoredCodes);
19617
19661
  }
19618
19662
  getDiagnosticsForFile(file) {
19619
- const uri = this.client.toResource(file).toString();
19663
+ const uri = this.client.toResourceUri(file);
19620
19664
  return this.diagnostics.get(uri)?.getDiagnostics() || [];
19621
19665
  }
19622
19666
  onDidCloseFile(file) {
19623
- const uri = this.client.toResource(file).toString();
19667
+ const uri = this.client.toResourceUri(file);
19624
19668
  const diagnosticsForFile = this.diagnostics.get(uri);
19625
19669
  diagnosticsForFile?.onDidClose();
19626
19670
  this.diagnostics.delete(uri);
19627
19671
  }
19628
19672
  async waitForDiagnosticsForTesting(file) {
19629
- const uri = this.client.toResource(file).toString();
19673
+ const uri = this.client.toResourceUri(file);
19630
19674
  let diagnosticsForFile = this.diagnostics.get(uri);
19631
19675
  if (diagnosticsForFile) {
19632
19676
  diagnosticsForFile.onDidClose();
@@ -19656,7 +19700,7 @@ class SourceDefinitionCommand {
19656
19700
  lspClient.showErrorMessage('Go to Source Definition failed. No resource provided.');
19657
19701
  return;
19658
19702
  }
19659
- const document = client.toOpenDocument(client.toResource(file).toString());
19703
+ const document = client.toOpenDocument(client.toResourceUri(file));
19660
19704
  if (!document) {
19661
19705
  lspClient.showErrorMessage('Go to Source Definition failed. File not opened in the editor.');
19662
19706
  return;
@@ -20741,7 +20785,7 @@ function fromProtocolCallHierarchyItem(item, client, workspaceRoot) {
20741
20785
  kind: fromProtocolScriptElementKind(item.kind),
20742
20786
  name: name,
20743
20787
  detail: detail,
20744
- uri: client.toResource(item.file).toString(),
20788
+ uri: client.toResourceUri(item.file),
20745
20789
  range: Range.fromTextSpan(item.span),
20746
20790
  selectionRange: Range.fromTextSpan(item.selectionSpan)
20747
20791
  };
@@ -21510,7 +21554,7 @@ class TypeScriptImplementationsCodeLensProvider extends TypeScriptBaseCodeLensPr
21510
21554
  codeLens.command = response.type === 'cancelled' ? TypeScriptBaseCodeLensProvider.cancelledCommand : TypeScriptBaseCodeLensProvider.errorCommand;
21511
21555
  return codeLens;
21512
21556
  }
21513
- const locations = response.body.map((reference => main$2.Location.create(this.client.toResource(reference.file).toString(), reference.start.line === reference.end.line ? Range.fromTextSpan(reference) : main$2.Range.create(Position.fromLocation(reference.start), main$2.Position.create(reference.start.line, 0))))).filter((location => !(location.uri.toString() === codeLens.data.uri && location.range.start.line === codeLens.range.start.line && location.range.start.character === codeLens.range.start.character)));
21557
+ const locations = response.body.map((reference => main$2.Location.create(this.client.toResourceUri(reference.file), reference.start.line === reference.end.line ? Range.fromTextSpan(reference) : main$2.Range.create(Position.fromLocation(reference.start), main$2.Position.create(reference.start.line, 0))))).filter((location => !(location.uri.toString() === codeLens.data.uri && location.range.start.line === codeLens.range.start.line && location.range.start.character === codeLens.range.start.character)));
21514
21558
  codeLens.command = this.getCommand(locations, codeLens);
21515
21559
  return codeLens;
21516
21560
  }
@@ -21565,7 +21609,7 @@ class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLensProvide
21565
21609
  codeLens.command = response.type === 'cancelled' ? TypeScriptBaseCodeLensProvider.cancelledCommand : TypeScriptBaseCodeLensProvider.errorCommand;
21566
21610
  return codeLens;
21567
21611
  }
21568
- const locations = response.body.refs.filter((reference => !reference.isDefinition)).map((reference => Location.fromTextSpan(this.client.toResource(reference.file).toString(), reference)));
21612
+ const locations = response.body.refs.filter((reference => !reference.isDefinition)).map((reference => Location.fromTextSpan(this.client.toResourceUri(reference.file), reference)));
21569
21613
  codeLens.command = {
21570
21614
  title: this.getCodeLensLabel(locations),
21571
21615
  command: locations.length ? 'editor.action.showReferences' : '',
@@ -22387,6 +22431,7 @@ class LspServer {
22387
22431
  disableAutomaticTypingAcquisition: disableAutomaticTypingAcquisition,
22388
22432
  maxTsServerMemory: maxTsServerMemory,
22389
22433
  npmLocation: npmLocation,
22434
+ hostInfo: hostInfo,
22390
22435
  locale: locale,
22391
22436
  plugins: plugins || [],
22392
22437
  onEvent: this.onTsEvent.bind(this),
@@ -22708,7 +22753,7 @@ class LspServer {
22708
22753
  }
22709
22754
  async completionResolve(item, token) {
22710
22755
  item.data = item.data?.cacheId !== undefined ? this.completionDataCache.get(item.data.cacheId) : item.data;
22711
- const uri = this.tsClient.toResource(item.data.file).toString();
22756
+ const uri = this.tsClient.toResourceUri(item.data.file);
22712
22757
  const document = item.data?.file ? this.tsClient.toOpenDocument(uri) : undefined;
22713
22758
  if (!document) {
22714
22759
  return item;
@@ -22781,7 +22826,7 @@ class LspServer {
22781
22826
  }
22782
22827
  const changes = {};
22783
22828
  result.locs.forEach((spanGroup => {
22784
- const uri = this.tsClient.toResource(spanGroup.file).toString();
22829
+ const uri = this.tsClient.toResourceUri(spanGroup.file);
22785
22830
  const textEdits = changes[uri] || (changes[uri] = []);
22786
22831
  spanGroup.locs.forEach((textSpan => {
22787
22832
  textEdits.push({
@@ -22977,7 +23022,7 @@ class LspServer {
22977
23022
  if (renameLocation) {
22978
23023
  await this.options.lspClient.rename({
22979
23024
  textDocument: {
22980
- uri: this.tsClient.toResource(args.file).toString()
23025
+ uri: this.tsClient.toResourceUri(args.file)
22981
23026
  },
22982
23027
  position: Position.fromLocation(renameLocation)
22983
23028
  });
@@ -22987,7 +23032,7 @@ class LspServer {
22987
23032
  this.tsClient.configurePlugin(pluginName, configuration);
22988
23033
  } else if (params.command === Commands.ORGANIZE_IMPORTS && params.arguments) {
22989
23034
  const file = params.arguments[0];
22990
- const uri = this.tsClient.toResource(file).toString();
23035
+ const uri = this.tsClient.toResourceUri(file);
22991
23036
  const document = this.tsClient.toOpenDocument(uri);
22992
23037
  if (!document) {
22993
23038
  return;
@@ -23044,7 +23089,7 @@ class LspServer {
23044
23089
  }
23045
23090
  const changes = {};
23046
23091
  for (const edit of edits) {
23047
- changes[this.tsClient.toResource(edit.fileName).toString()] = edit.textChanges.map(toTextEdit);
23092
+ changes[this.tsClient.toResourceUri(edit.fileName)] = edit.textChanges.map(toTextEdit);
23048
23093
  }
23049
23094
  const {applied: applied} = await this.options.lspClient.applyWorkspaceEdit({
23050
23095
  edit: {
@@ -23058,7 +23103,7 @@ class LspServer {
23058
23103
  for (const rename of params.files) {
23059
23104
  const codeEdits = await this.getEditsForFileRename(rename.oldUri, rename.newUri, token);
23060
23105
  for (const codeEdit of codeEdits) {
23061
- const uri = this.tsClient.toResource(codeEdit.fileName).toString();
23106
+ const uri = this.tsClient.toResourceUri(codeEdit.fileName);
23062
23107
  const textEdits = changes[uri] || (changes[uri] = []);
23063
23108
  textEdits.push(...codeEdit.textChanges.map(toTextEdit));
23064
23109
  }
@@ -23134,7 +23179,7 @@ class LspServer {
23134
23179
  }
23135
23180
  return response.body.map((item => ({
23136
23181
  location: {
23137
- uri: this.tsClient.toResource(item.file).toString(),
23182
+ uri: this.tsClient.toResourceUri(item.file),
23138
23183
  range: {
23139
23184
  start: Position.fromLocation(item.start),
23140
23185
  end: Position.fromLocation(item.end)