From b866d6db15fb9153dd43b7f982f18266ad945fa3 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Mon, 10 Jan 2022 11:43:39 -0800 Subject: [PATCH] fix: Prevent legacy VE from being used with v13 projects (#1575) 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. (cherry picked from commit 2deee1829a386f2f0981116378508b71ae974f3a) --- client/src/client.ts | 26 +++++++++++++++++++++++++- package.json | 4 ++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/client/src/client.ts b/client/src/client.ts index d39c7af666..2f9e2b2167 100644 --- a/client/src/client.ts +++ b/client/src/client.ts @@ -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); @@ -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; } \ No newline at end of file diff --git a/package.json b/package.json index 0456a43293..1bec017811 100644 --- a/package.json +++ b/package.json @@ -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", @@ -216,4 +216,4 @@ "type": "git", "url": "https://github.com/angular/vscode-ng-language-service" } -} +} \ No newline at end of file