From d8bf621d89adeb3ef3ef7560bd59a5b648f63817 Mon Sep 17 00:00:00 2001 From: Colton Donnelly Date: Mon, 4 Dec 2023 16:15:58 -0500 Subject: [PATCH 1/2] add tsserver.fallbackPath to init options --- src/lsp-server.ts | 14 ++++++++++++-- src/ts-protocol.ts | 6 ++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lsp-server.ts b/src/lsp-server.ts index 7b43094d..e3ac78b2 100644 --- a/src/lsp-server.ts +++ b/src/lsp-server.ts @@ -107,7 +107,7 @@ export class LspServer { pluginProbeLocations.push(plugin.location); } - const typescriptVersion = this.findTypescriptVersion(tsserver?.path); + const typescriptVersion = this.findTypescriptVersion(tsserver?.path, tsserver?.fallbackPath); if (typescriptVersion) { this.options.lspClient.logMessage({ type: lsp.MessageType.Info, message: `Using Typescript version (${typescriptVersion.source}) ${typescriptVersion.versionString} from path "${typescriptVersion.tsServerPath}"` }); } else { @@ -315,7 +315,7 @@ export class LspServer { }); } - private findTypescriptVersion(userTsserverPath: string | undefined): TypeScriptVersion | null { + private findTypescriptVersion(userTsserverPath: string | undefined, fallbackTsserverPath: string | undefined): TypeScriptVersion | null { const typescriptVersionProvider = new TypeScriptVersionProvider(userTsserverPath, this.logger); // User-provided tsserver path. const userSettingVersion = typescriptVersionProvider.getUserSettingVersion(); @@ -332,6 +332,16 @@ export class LspServer { return workspaceVersion; } } + + const fallbackVersionProvider = new TypeScriptVersionProvider(fallbackTsserverPath, this.logger); + const fallbackSettingVersion = fallbackVersionProvider.getUserSettingVersion(); + if (fallbackSettingVersion) { + if (fallbackSettingVersion.isValid) { + return fallbackSettingVersion; + } + this.logger.logIgnoringVerbosity(LogLevel.Warning, `Typescript specified through fallback setting ignored due to invalid path "${fallbackSettingVersion.path}"`); + } + // Bundled version const bundledVersion = typescriptVersionProvider.bundledVersion(); if (bundledVersion?.isValid) { diff --git a/src/ts-protocol.ts b/src/ts-protocol.ts index 07b780eb..a2a86e47 100644 --- a/src/ts-protocol.ts +++ b/src/ts-protocol.ts @@ -374,6 +374,12 @@ interface TsserverOptions { * The path to the `tsserver.js` file or the typescript lib directory. For example: `/Users/me/typescript/lib/tsserver.js`. */ path?: string; + /** + * The fallback path to the `tsserver.js` file or the typescript lib directory. For example: `/Users/me/typescript/lib/tsserver.js`. + * + * This path gets used when `.path` isn't set or valid, and detecting the file from the current active workspace fails. + */ + fallbackPath?: string; /** * The verbosity of logging the tsserver communication through the LSP messages. * This doesn't affect the file logging. From 0345eaea176ee072b6da2ce04c83946c0e90e598 Mon Sep 17 00:00:00 2001 From: Colton Donnelly Date: Mon, 4 Dec 2023 18:21:37 -0500 Subject: [PATCH 2/2] update docs --- docs/configuration.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index 69085025..04024323 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -34,6 +34,8 @@ Specifies additional options related to the internal `tsserver` process, like tr **path** [string] The path to the `tsserver.js` file or the typescript lib directory. For example: `/Users/me/typescript/lib/tsserver.js`. Note: The path should point at the `[...]/typescript/lib/tssserver.js` file or the `[...]/typescript/lib/` directory and not the shell script (`[...]/node_modules/.bin/tsserver`) but for backward-compatibility reasons, the server will try to do the right thing even when passed a path to the shell script. **Default**: `undefined` +**fallbackPath** [string] The path to the `tsserver.js` file or the typescript lib directory to use when `tsserver.path` is unspecified/invalid and the `tsserver` isn't available via the current workspace. For example: `/Users/me/typescript/lib/tsserver.js`. Note: The path should point at the `[...]/typescript/lib/tssserver.js` file or the `[...]/typescript/lib/` directory and not the shell script (`[...]/node_modules/.bin/tsserver`) but for backward-compatibility reasons, the server will try to do the right thing even when passed a path to the shell script. **Default**: `undefined` + **trace** [string] The verbosity of logging of the tsserver communication. Delivered through the LSP messages and not related to file logging. Allowed values are: `'off'`, `'messages'`, `'verbose'`. **Default**: `'off'` **useSyntaxServer** [string] Whether a dedicated server is launched to more quickly handle syntax related operations, such as computing diagnostics or code folding. **Default**: `'auto'`. Allowed values: @@ -216,4 +218,4 @@ implicitProjectConfiguration.strictNullChecks: boolean; * @default 'ES2020' */ implicitProjectConfiguration.target: string; -``` +``` \ No newline at end of file