Skip to content

Commit

Permalink
fix: Prevent legacy VE from being used with v13 projects (#1575)
Browse files Browse the repository at this point in the history
Angular v13+ projects do not support VE. If the client detects a v13+ project in the workspace,
it now sets legacy VE to false, regardless of the extension options or incompatible legacy projects
in the workspace.
  • Loading branch information
atscott authored Jan 10, 2022
1 parent 9cdba35 commit 2deee18
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
26 changes: 25 additions & 1 deletion client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,20 @@ function getServerOptions(ctx: vscode.ExtensionContext, debug: boolean): lsp.Nod
// will return false even when the value is not set. If value is false, then
// we need to check if all projects support Ivy language service.
const config = vscode.workspace.getConfiguration();
const viewEngine: boolean = config.get('angular.view-engine') || !allProjectsSupportIvy();
let viewEngine: boolean = config.get('angular.view-engine') || !allProjectsSupportIvy();
if (viewEngine && !allProjectsSupportVE()) {
viewEngine = false;
if (config.get('angular.view-engine')) {
vscode.window.showErrorMessage(
`The legacy View Engine option is enabled but the workspace contains a version 13 Angular project.` +
` Legacy View Engine will be disabled since support for it was dropped in v13.`,
);
} else if (!allProjectsSupportIvy() && !allProjectsSupportVE()) {
vscode.window.showErrorMessage(
`The workspace contains a project that does not support legacy View Engine (Angular v13+) and a project that does not support the new current runtime (v8 and below).` +
`The extension will not work for the legacy project in this workspace.`);
}
}

// Node module for the language server
const args = constructArgs(ctx, viewEngine);
Expand Down Expand Up @@ -521,4 +534,15 @@ function allProjectsSupportIvy() {
}
}
return true;
}

function allProjectsSupportVE() {
const workspaceFolders = vscode.workspace.workspaceFolders || [];
for (const workspaceFolder of workspaceFolders) {
const angularCore = resolve('@angular/core', workspaceFolder.uri.fsPath);
if (angularCore?.version.greaterThanOrEqual(new Version('13')) === true) {
return false;
}
}
return true;
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"angular.view-engine": {
"type": "boolean",
"default": false,
"description": "Use legacy View Engine language service."
"description": "Use legacy View Engine language service. This option is incompatible with projects using Angular v13 and above."
},
"angular.enable-strict-mode-prompt": {
"type": "boolean",
Expand Down Expand Up @@ -216,4 +216,4 @@
"type": "git",
"url": "https://github.com/angular/vscode-ng-language-service"
}
}
}

0 comments on commit 2deee18

Please sign in to comment.