Skip to content

Commit 1f4e2a2

Browse files
committed
Add support for loading contributed TS version
Fixes #75222 Fixes microsoft/TypeScript#31623
1 parent 18b659d commit 1f4e2a2

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

extensions/typescript-language-features/src/utils/versionProvider.ts

+22-9
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import * as nls from 'vscode-nls';
99
import API from './api';
1010
import { TypeScriptServiceConfiguration } from './configuration';
1111
import { RelativeWorkspacePathResolver } from './relativePathResolver';
12-
const localize = nls.loadMessageBundle();
1312

13+
const localize = nls.loadMessageBundle();
1414

1515
export class TypeScriptVersion {
1616
constructor(
@@ -109,7 +109,7 @@ export class TypeScriptVersionProvider {
109109
return globals[0];
110110
}
111111
}
112-
return undefined;
112+
return this.contributedTsNextVersion;
113113
}
114114

115115
public get localVersion(): TypeScriptVersion | undefined {
@@ -138,20 +138,33 @@ export class TypeScriptVersionProvider {
138138
}
139139

140140
public get bundledVersion(): TypeScriptVersion {
141+
const version = this.getContributedVersion('vscode.typescript-language-features', ['..', 'node_modules']);
142+
if (version) {
143+
return version;
144+
}
145+
146+
vscode.window.showErrorMessage(localize(
147+
'noBundledServerFound',
148+
'VS Code\'s tsserver was deleted by another application such as a misbehaving virus detection tool. Please reinstall VS Code.'));
149+
throw new Error('Could not find bundled tsserver.js');
150+
}
151+
152+
private get contributedTsNextVersion(): TypeScriptVersion | undefined {
153+
return this.getContributedVersion('ms-vscode.vscode-typescript-next', ['node_modules']);
154+
}
155+
156+
private getContributedVersion(extensionId: string, pathToTs: readonly string[]): TypeScriptVersion | undefined {
141157
try {
142-
const { extensionPath } = vscode.extensions.getExtension('vscode.typescript-language-features')!;
143-
const typescriptPath = path.join(extensionPath, '../node_modules/typescript/lib');
158+
const { extensionPath } = vscode.extensions.getExtension(extensionId)!;
159+
const typescriptPath = path.join(extensionPath, ...pathToTs, 'typescript', 'lib');
144160
const bundledVersion = new TypeScriptVersion(typescriptPath, '');
145161
if (bundledVersion.isValid) {
146162
return bundledVersion;
147163
}
148-
} catch (e) {
164+
} catch {
149165
// noop
150166
}
151-
vscode.window.showErrorMessage(localize(
152-
'noBundledServerFound',
153-
'VS Code\'s tsserver was deleted by another application such as a misbehaving virus detection tool. Please reinstall VS Code.'));
154-
throw new Error('Could not find bundled tsserver.js');
167+
return undefined;
155168
}
156169

157170
private get localTsdkVersions(): TypeScriptVersion[] {

0 commit comments

Comments
 (0)