typescript-language-server 4.2.0 → 4.3.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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [4.3.0](https://github.com/typescript-language-server/typescript-language-server/compare/v4.2.0...v4.3.0) (2024-01-08)
5
+
6
+
7
+ ### Features
8
+
9
+ * support specifying language IDs in plugins ([#834](https://github.com/typescript-language-server/typescript-language-server/issues/834)) ([e9c0b11](https://github.com/typescript-language-server/typescript-language-server/commit/e9c0b117a9a5e273eb517dc0d337ecdf973f3dac))
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * avoid sending window/workDoneProgress/create before init ([#846](https://github.com/typescript-language-server/typescript-language-server/issues/846)) ([625048f](https://github.com/typescript-language-server/typescript-language-server/commit/625048fac8533bccdeda82ee140d4f7792d9fb04))
15
+
4
16
  ## [4.2.0](https://github.com/typescript-language-server/typescript-language-server/compare/v4.1.3...v4.2.0) (2023-12-09)
5
17
 
6
18
 
package/README.md CHANGED
@@ -31,8 +31,8 @@ Maintained by a [community of contributors](https://github.com/typescript-langua
31
31
  - [TypeScript Version Notification](#typescript-version-notification)
32
32
  - [Development](#development)
33
33
  - [Build](#build)
34
+ - [Dev](#dev)
34
35
  - [Test](#test)
35
- - [Watch](#watch)
36
36
  - [Publishing](#publishing)
37
37
 
38
38
  <!-- /MarkdownTOC -->
@@ -277,22 +277,24 @@ The `$/typescriptVersion` notification params include two properties:
277
277
  ### Build
278
278
 
279
279
  ```sh
280
- yarn
280
+ yarn build
281
281
  ```
282
282
 
283
- ### Test
284
-
285
- - `yarn test` - run all tests
286
- - `yarn test:watch` - run all tests and enable watch mode for developing
283
+ ### Dev
287
284
 
288
- By default only console logs of level `warning` and higher are printed to the console. You can override the `CONSOLE_LOG_LEVEL` level in `package.json` to either `log`, `info`, `warning` or `error` to log other levels.
289
-
290
- ### Watch
285
+ Build and rebuild on change.
291
286
 
292
287
  ```sh
293
- yarn watch
288
+ yarn dev
294
289
  ```
295
290
 
291
+ ### Test
292
+
293
+ - `yarn test` - run all tests in watch mode for developing
294
+ - `yarn test:commit` - run all tests once
295
+
296
+ By default only console logs of level `warning` and higher are printed to the console. You can override the `CONSOLE_LOG_LEVEL` level in `package.json` to either `log`, `info`, `warning` or `error` to log other levels.
297
+
296
298
  ### Publishing
297
299
 
298
300
  The project uses https://github.com/google-github-actions/release-please-action Github action to automatically release new version on merging a release PR.
package/lib/cli.mjs CHANGED
@@ -17419,17 +17419,20 @@ class LspDocuments {
17419
17419
  constructor(client, lspClient, onCaseInsensitiveFileSystem) {
17420
17420
  this._validateJavaScript = true;
17421
17421
  this._validateTypeScript = true;
17422
+ this.modeIds = new Set;
17422
17423
  this._files = [];
17423
17424
  this.documents = new Map;
17424
17425
  this.client = client;
17425
17426
  this.lspClient = lspClient;
17426
- this.modeIds = new Set(jsTsLanguageModes);
17427
17427
  const pathNormalizer = path => this.client.toTsFilePath(path.toString());
17428
17428
  this.pendingDiagnostics = new PendingDiagnostics(pathNormalizer, {
17429
17429
  onCaseInsensitiveFileSystem: onCaseInsensitiveFileSystem
17430
17430
  });
17431
17431
  this.diagnosticDelayer = new Delayer(300);
17432
17432
  }
17433
+ initialize(allModeIds) {
17434
+ this.modeIds = new Set(allModeIds);
17435
+ }
17433
17436
  get files() {
17434
17437
  return this._files;
17435
17438
  }
@@ -17652,6 +17655,35 @@ const vsls = 'vsls';
17652
17655
 
17653
17656
  const disabledSchemes = new Set([ git, vsls, github, azurerepos ]);
17654
17657
 
17658
+ var TypeScriptServerPlugin;
17659
+
17660
+ (function(TypeScriptServerPlugin) {
17661
+ function equals(a, b) {
17662
+ return a.uri.toString() === b.uri.toString() && a.name === b.name && equals$1(a.languages, b.languages);
17663
+ }
17664
+ TypeScriptServerPlugin.equals = equals;
17665
+ })(TypeScriptServerPlugin || (TypeScriptServerPlugin = {}));
17666
+
17667
+ class PluginManager {
17668
+ setPlugins(plugins) {
17669
+ this._plugins = this.readPlugins(plugins);
17670
+ }
17671
+ get plugins() {
17672
+ return Array.from(this._plugins || []);
17673
+ }
17674
+ readPlugins(plugins) {
17675
+ const newPlugins = [];
17676
+ for (const plugin of plugins) {
17677
+ newPlugins.push({
17678
+ name: plugin.name,
17679
+ uri: URI.file(plugin.location),
17680
+ languages: Array.isArray(plugin.languages) ? plugin.languages : []
17681
+ });
17682
+ }
17683
+ return newPlugins;
17684
+ }
17685
+ }
17686
+
17655
17687
  class TypeScriptServerError extends Error {
17656
17688
  static create(serverId, version, response) {
17657
17689
  const parsedResult = TypeScriptServerError.parseErrorText(response);
@@ -18630,7 +18662,7 @@ class TypeScriptServerSpawner {
18630
18662
  this._logger = _logger;
18631
18663
  this._tracer = _tracer;
18632
18664
  }
18633
- spawn(version, capabilities, configuration, delegate) {
18665
+ spawn(version, capabilities, configuration, pluginManager, delegate) {
18634
18666
  let primaryServer;
18635
18667
  const serverType = this.getCompositeServerType(version, capabilities, configuration);
18636
18668
  switch (serverType) {
@@ -18639,21 +18671,21 @@ class TypeScriptServerSpawner {
18639
18671
  {
18640
18672
  const enableDynamicRouting = serverType === 2;
18641
18673
  primaryServer = new SyntaxRoutingTsServer({
18642
- syntax: this.spawnTsServer('syntax', version, configuration),
18643
- semantic: this.spawnTsServer('semantic', version, configuration)
18674
+ syntax: this.spawnTsServer('syntax', version, configuration, pluginManager),
18675
+ semantic: this.spawnTsServer('semantic', version, configuration, pluginManager)
18644
18676
  }, delegate, enableDynamicRouting);
18645
18677
  break;
18646
18678
  }
18647
18679
 
18648
18680
  case 0:
18649
18681
  {
18650
- primaryServer = this.spawnTsServer('main', version, configuration);
18682
+ primaryServer = this.spawnTsServer('main', version, configuration, pluginManager);
18651
18683
  break;
18652
18684
  }
18653
18685
 
18654
18686
  case 3:
18655
18687
  {
18656
- primaryServer = this.spawnTsServer('syntax', version, configuration);
18688
+ primaryServer = this.spawnTsServer('syntax', version, configuration, pluginManager);
18657
18689
  break;
18658
18690
  }
18659
18691
  }
@@ -18677,10 +18709,10 @@ class TypeScriptServerSpawner {
18677
18709
  return 0;
18678
18710
  }
18679
18711
  }
18680
- spawnTsServer(kind, version, configuration) {
18712
+ spawnTsServer(kind, version, configuration, pluginManager) {
18681
18713
  const processFactory = new NodeTsServerProcessFactory;
18682
18714
  const canceller = nodeRequestCancellerFactory.create(kind, this._tracer);
18683
- const {args: args, tsServerLogFile: tsServerLogFile} = this.getTsServerArgs(kind, configuration, this._apiVersion, canceller.cancellationPipeName);
18715
+ const {args: args, tsServerLogFile: tsServerLogFile} = this.getTsServerArgs(kind, configuration, this._apiVersion, pluginManager, canceller.cancellationPipeName);
18684
18716
  if (this.isLoggingEnabled(configuration)) {
18685
18717
  if (tsServerLogFile) {
18686
18718
  this._logger.logIgnoringVerbosity(LogLevel.Info, `<${kind}> Log file: ${tsServerLogFile}`);
@@ -18704,7 +18736,7 @@ class TypeScriptServerSpawner {
18704
18736
  return ServerType.Semantic;
18705
18737
  }
18706
18738
  }
18707
- getTsServerArgs(kind, configuration, apiVersion, cancellationPipeName) {
18739
+ getTsServerArgs(kind, configuration, apiVersion, pluginManager, cancellationPipeName) {
18708
18740
  const args = [];
18709
18741
  let tsServerLogFile;
18710
18742
  let tsServerTraceDirectory;
@@ -18716,7 +18748,7 @@ class TypeScriptServerSpawner {
18716
18748
  }
18717
18749
  }
18718
18750
  args.push('--useInferredProjectPerProjectRoot');
18719
- const {disableAutomaticTypingAcquisition: disableAutomaticTypingAcquisition, globalPlugins: globalPlugins, locale: locale, npmLocation: npmLocation, pluginProbeLocations: pluginProbeLocations} = configuration;
18751
+ const {disableAutomaticTypingAcquisition: disableAutomaticTypingAcquisition, locale: locale, npmLocation: npmLocation} = configuration;
18720
18752
  if (disableAutomaticTypingAcquisition || kind === 'syntax' || kind === 'diagnostics') {
18721
18753
  args.push('--disableAutomaticTypingAcquisition');
18722
18754
  }
@@ -18731,11 +18763,15 @@ class TypeScriptServerSpawner {
18731
18763
  args.push('--logFile', tsServerLogFile);
18732
18764
  }
18733
18765
  }
18734
- if (globalPlugins?.length) {
18735
- args.push('--globalPlugins', globalPlugins.join(','));
18766
+ const pluginPaths = [];
18767
+ if (pluginManager.plugins.length) {
18768
+ args.push('--globalPlugins', pluginManager.plugins.map((x => x.name)).join(','));
18769
+ for (const plugin of pluginManager.plugins) {
18770
+ pluginPaths.push(plugin.uri.fsPath);
18771
+ }
18736
18772
  }
18737
- if (pluginProbeLocations?.length) {
18738
- args.push('--pluginProbeLocations', pluginProbeLocations.join(','));
18773
+ if (pluginPaths.length !== 0) {
18774
+ args.push('--pluginProbeLocations', pluginPaths.join(','));
18739
18775
  }
18740
18776
  if (npmLocation) {
18741
18777
  this._logger.info(`using npm from ${npmLocation}`);
@@ -18908,6 +18944,7 @@ class TsClient {
18908
18944
  this.serverState = ServerState.None;
18909
18945
  this.workspaceFolders = [];
18910
18946
  this.useSyntaxServer = 2;
18947
+ this.pluginManager = new PluginManager;
18911
18948
  this.documents = new LspDocuments(this, lspClient, onCaseInsensitiveFileSystem);
18912
18949
  this.logger = new PrefixingLogger(logger, '[tsclient]');
18913
18950
  this.tsserverLogger = new PrefixingLogger(this.logger, '[tsserver]');
@@ -19004,6 +19041,14 @@ class TsClient {
19004
19041
  }
19005
19042
  }
19006
19043
  }
19044
+ configurePlugin(pluginName, configuration) {
19045
+ if (this.apiVersion.gte(API.v314)) {
19046
+ this.executeWithoutWaitingForResponse(CommandTypes.ConfigurePlugin, {
19047
+ pluginName: pluginName,
19048
+ configuration: configuration
19049
+ });
19050
+ }
19051
+ }
19007
19052
  start(workspaceRoot, options) {
19008
19053
  this.apiVersion = options.typescriptVersion.version || API.defaultVersion;
19009
19054
  this.typescriptVersionSource = options.typescriptVersion.source;
@@ -19014,8 +19059,11 @@ class TsClient {
19014
19059
  this.useSyntaxServer = options.useSyntaxServer;
19015
19060
  this.onEvent = options.onEvent;
19016
19061
  this.onExit = options.onExit;
19062
+ this.pluginManager.setPlugins(options.plugins);
19063
+ const modeIds = [ ...jsTsLanguageModes, ...this.pluginManager.plugins.flatMap((x => x.languages)) ];
19064
+ this.documents.initialize(modeIds);
19017
19065
  const tsServerSpawner = new TypeScriptServerSpawner(this.apiVersion, options.logDirectoryProvider, this.logger, this.tracer);
19018
- const tsServer = tsServerSpawner.spawn(options.typescriptVersion, this.capabilities, options, {
19066
+ const tsServer = tsServerSpawner.spawn(options.typescriptVersion, this.capabilities, options, this.pluginManager, {
19019
19067
  onFatalError: (command, err) => this.fatalError(command, err)
19020
19068
  });
19021
19069
  this.serverState = new ServerState.Running(tsServer, this.apiVersion, undefined, true);
@@ -19038,9 +19086,6 @@ class TsClient {
19038
19086
  this.serviceExited();
19039
19087
  }));
19040
19088
  tsServer.onEvent((event => this.dispatchEvent(event)));
19041
- if (this.apiVersion.gte(API.v300) && this.capabilities.has(ClientCapability.Semantic)) {
19042
- this.loadingIndicator.startedLoadingProject('');
19043
- }
19044
19089
  return true;
19045
19090
  }
19046
19091
  serviceExited() {
@@ -22295,16 +22340,7 @@ class LspServer {
22295
22340
  const clientCapabilities = this.initializeParams.capabilities;
22296
22341
  this.workspaceRoot = this.initializeParams.rootUri ? URI.parse(this.initializeParams.rootUri).fsPath : this.initializeParams.rootPath || undefined;
22297
22342
  const userInitializationOptions = this.initializeParams.initializationOptions || {};
22298
- const {disableAutomaticTypingAcquisition: disableAutomaticTypingAcquisition, hostInfo: hostInfo, maxTsServerMemory: maxTsServerMemory, npmLocation: npmLocation, locale: locale, tsserver: tsserver} = userInitializationOptions;
22299
- const {plugins: plugins} = {
22300
- plugins: userInitializationOptions.plugins || []
22301
- };
22302
- const globalPlugins = [];
22303
- const pluginProbeLocations = [];
22304
- for (const plugin of plugins) {
22305
- globalPlugins.push(plugin.name);
22306
- pluginProbeLocations.push(plugin.location);
22307
- }
22343
+ const {disableAutomaticTypingAcquisition: disableAutomaticTypingAcquisition, hostInfo: hostInfo, maxTsServerMemory: maxTsServerMemory, npmLocation: npmLocation, locale: locale, plugins: plugins, tsserver: tsserver} = userInitializationOptions;
22308
22344
  const typescriptVersion = this.findTypescriptVersion(tsserver?.path, tsserver?.fallbackPath);
22309
22345
  if (typescriptVersion) {
22310
22346
  this.options.lspClient.logMessage({
@@ -22351,8 +22387,7 @@ class LspServer {
22351
22387
  maxTsServerMemory: maxTsServerMemory,
22352
22388
  npmLocation: npmLocation,
22353
22389
  locale: locale,
22354
- globalPlugins: globalPlugins,
22355
- pluginProbeLocations: pluginProbeLocations,
22390
+ plugins: plugins || [],
22356
22391
  onEvent: this.onTsEvent.bind(this),
22357
22392
  onExit: (exitCode, signal) => {
22358
22393
  this.shutdown();
@@ -22948,12 +22983,7 @@ class LspServer {
22948
22983
  }
22949
22984
  } else if (params.command === Commands.CONFIGURE_PLUGIN && params.arguments) {
22950
22985
  const [pluginName, configuration] = params.arguments;
22951
- if (this.tsClient.apiVersion.gte(API.v314)) {
22952
- this.tsClient.executeWithoutWaitingForResponse(CommandTypes.ConfigurePlugin, {
22953
- configuration: configuration,
22954
- pluginName: pluginName
22955
- });
22956
- }
22986
+ this.tsClient.configurePlugin(pluginName, configuration);
22957
22987
  } else if (params.command === Commands.ORGANIZE_IMPORTS && params.arguments) {
22958
22988
  const file = params.arguments[0];
22959
22989
  const uri = this.tsClient.toResource(file).toString();