Skip to content

Commit db35205

Browse files
committed
Fixing a few cases for missing tsserver
1 parent d1d30da commit db35205

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

extensions/typescript/src/typescriptServiceClient.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,11 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
328328
}
329329

330330
private get bundledTypeScriptPath(): string {
331-
return require.resolve('typescript/lib/tsserver.js');
331+
try {
332+
return require.resolve('typescript/lib/tsserver.js');
333+
} catch (e) {
334+
return '';
335+
}
332336
}
333337

334338
private get localTypeScriptPath(): string | null {
@@ -392,12 +396,12 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
392396

393397
this.info(`Using tsserver from location: ${modulePath}`);
394398
if (!fs.existsSync(modulePath)) {
395-
window.showWarningMessage(localize('noServerFound', 'The path {0} doesn\'t point to a valid tsserver install. Falling back to bundled TypeScript version.', path.dirname(modulePath)));
396-
modulePath = this.bundledTypeScriptPath;
397-
if (!fs.existsSync(modulePath)) {
398-
window.showErrorMessage(localize('noBundledServerFound', 'VSCode\'s tsserver was deleted by a another application such as a misbehaving virus detection tool. Please reinstall VS Code.'));
399+
window.showWarningMessage(localize('noServerFound', 'The path {0} doesn\'t point to a valid tsserver install. Falling back to bundled TypeScript version.', modulePath ? path.dirname(modulePath) : ''));
400+
if (!this.bundledTypeScriptPath) {
401+
window.showErrorMessage(localize('noBundledServerFound', 'VSCode\'s tsserver was deleted by another application such as a misbehaving virus detection tool. Please reinstall VS Code.'));
399402
return reject(new Error('Could not find bundled tsserver.js'));
400403
}
404+
modulePath = this.bundledTypeScriptPath;
401405
}
402406

403407
let version = this.getTypeScriptVersion(modulePath);
@@ -485,9 +489,9 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
485489
return this.showVersionPicker(false);
486490
}
487491

488-
private showVersionPicker(firstRun: boolean) {
492+
private showVersionPicker(firstRun: boolean): Thenable<string> {
489493
const modulePath = this.modulePath || this.globalTypescriptPath;
490-
if (!workspace.rootPath) {
494+
if (!workspace.rootPath || !modulePath) {
491495
return Promise.resolve(modulePath);
492496
}
493497

0 commit comments

Comments
 (0)