Skip to content

Commit a5ee17d

Browse files
kyliauayazhafiz
authored andcommitted
fix: @angular/language-service gets loaded from wrong location (#448)
This commit works around the bug in microsoft/TypeScript#34616 and partially fixes #437.
1 parent 06e3ced commit a5ee17d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

client/src/extension.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function getProbeLocations(configValue: string|null, bundled: string): string[]
115115
const locations = [];
116116
// Always use config value if it's specified
117117
if (configValue) {
118-
locations.push(configValue as string);
118+
locations.push(configValue);
119119
}
120120
// If not, look in workspaces currently open
121121
const workspaceFolders = vscode.workspace.workspaceFolders || [];
@@ -144,13 +144,30 @@ function constructArgs(ctx: vscode.ExtensionContext, debug: boolean): string[] {
144144
args.push('--logVerbosity', debug ? 'verbose' : ngLog);
145145
}
146146

147+
// Due to a bug in tsserver, ngProbeLocation is not honored when tsserver
148+
// loads the plugin. tsserver would look for @angular/language-service in its
149+
// peer node_modules directory, and use that if it finds one. To work around
150+
// this bug, always load typescript from the bundled location for now, so that
151+
// the bundled @angular/language-service is always chosen.
152+
// See the following links:
153+
// 1. https://github.com/angular/vscode-ng-language-service/issues/437
154+
// 2. https://github.com/microsoft/TypeScript/issues/34616
155+
// 3. https://github.com/microsoft/TypeScript/pull/34656
156+
// TODO: Remove workaround once
157+
// https://github.com/microsoft/TypeScript/commit/f689982c9f2081bc90d2192eee96b404f75c4705
158+
// is released and Angular is switched over to the new TypeScript version.
159+
args.push('--ngProbeLocations', ctx.asAbsolutePath('server'));
160+
args.push('--tsProbeLocations', ctx.extensionPath);
161+
162+
/*
147163
const ngdk: string|null = config.get('angular.ngdk', null);
148164
const ngProbeLocations = getProbeLocations(ngdk, ctx.asAbsolutePath('server'));
149165
args.push('--ngProbeLocations', ngProbeLocations.join(','));
150166
151167
const tsdk: string|null = config.get('typescript.tsdk', null);
152168
const tsProbeLocations = getProbeLocations(tsdk, ctx.extensionPath);
153169
args.push('--tsProbeLocations', tsProbeLocations.join(','));
170+
*/
154171

155172
return args;
156173
}

0 commit comments

Comments
 (0)