Skip to content

add tsserver.fallbackPath to initialization options #831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -216,4 +218,4 @@ implicitProjectConfiguration.strictNullChecks: boolean;
* @default 'ES2020'
*/
implicitProjectConfiguration.target: string;
```
```
14 changes: 12 additions & 2 deletions src/lsp-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/ts-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down