Skip to content

Commit

Permalink
fix: Disable block syntax parsing when no project in workspace suppor…
Browse files Browse the repository at this point in the history
…ts it (#1962)

This commit adds a check to ensure a root in the workspace supports
block syntax. If not, the block syntax parsing in the compiler is
disabled. Note that the language server is shared for all roots and all projects
in the workspace. If on supports block syntax, we have to enable it.

In the future, it would be better to find a way to make this a
per-project configuration based on the version of Angular used in that
project.

fixes #1958
  • Loading branch information
atscott authored Nov 8, 2023
1 parent 78964a3 commit 0189dc8
Show file tree
Hide file tree
Showing 9 changed files with 4,207 additions and 6,439 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Input hashes for repository rule npm_translate_lock(name = "npm", pnpm_lock = "//:pnpm-lock.yaml").
# This file should be checked into version control along with the pnpm-lock.yaml file.
.npmrc=974837034
pnpm-lock.yaml=1812059618
yarn.lock=1782215124
package.json=836962010
pnpm-lock.yaml=-1149894156
yarn.lock=1254518305
package.json=-299890764
pnpm-workspace.yaml=1711114604
25 changes: 24 additions & 1 deletion client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as lsp from 'vscode-languageclient/node';

import {OpenOutputChannel, ProjectLoadingFinish, ProjectLoadingStart, SuggestStrictMode, SuggestStrictModeParams} from '../../common/notifications';
import {GetComponentsWithTemplateFile, GetTcbRequest, GetTemplateLocationForComponent, IsInAngularProject} from '../../common/requests';
import {resolve} from '../../common/resolver';
import {NodeModule, resolve} from '../../common/resolver';

import {isInsideComponentDecorator, isInsideInlineTemplateRegion, isInsideStringLiteral} from './embedded_support';

Expand Down Expand Up @@ -432,6 +432,13 @@ function constructArgs(ctx: vscode.ExtensionContext): string[] {
args.push('--includeCompletionsWithSnippetText');
}

const angularVersions = getAngularVersionsInWorkspace();
// Only disable block syntax if we find angular/core and every one we find does not support block
// syntax
if (angularVersions.size > 0 && Array.from(angularVersions).every(v => v.version.major < 17)) {
args.push('--disableBlockSyntax');
}

const forceStrictTemplates = config.get<boolean>('angular.forceStrictTemplates');
if (forceStrictTemplates) {
args.push('--forceStrictTemplates');
Expand Down Expand Up @@ -505,3 +512,19 @@ function extensionVersionCompatibleWithAllProjects(serverModuleLocation: string)
}
return true;
}

/**
* Returns true if any project in the workspace supports block syntax (v17+).
*/
function getAngularVersionsInWorkspace(): Set<NodeModule> {
const angularCoreModules = new Set<NodeModule>();
const workspaceFolders = vscode.workspace.workspaceFolders || [];
for (const workspaceFolder of workspaceFolders) {
const angularCore = resolve('@angular/core', workspaceFolder.uri.fsPath);
if (angularCore === undefined) {
continue;
}
angularCoreModules.add(angularCore);
}
return angularCoreModules;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
"test:legacy-syntaxes": "yarn compile:syntaxes-test && yarn build:syntaxes && jasmine dist/syntaxes/test/driver.js"
},
"dependencies": {
"@angular/language-service": "17.0.0-rc.3",
"@angular/language-service": "17.0.1",
"typescript": "5.2.2",
"vscode-html-languageservice": "^4.2.5",
"vscode-jsonrpc": "6.0.0",
Expand Down
10,596 changes: 4,167 additions & 6,429 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"ngserver": "./bin/ngserver"
},
"dependencies": {
"@angular/language-service": "17.0.0-rc.3",
"@angular/language-service": "17.0.1",
"vscode-html-languageservice": "^4.2.5",
"vscode-jsonrpc": "6.0.0",
"vscode-languageserver": "7.0.0",
Expand Down
2 changes: 2 additions & 0 deletions server/src/cmdline_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface CommandLineOptions {
includeAutomaticOptionalChainCompletions: boolean;
includeCompletionsWithSnippetText: boolean;
forceStrictTemplates: boolean;
disableBlockSyntax: boolean;
}

export function parseCommandLine(argv: string[]): CommandLineOptions {
Expand All @@ -50,6 +51,7 @@ export function parseCommandLine(argv: string[]): CommandLineOptions {
hasArgument(argv, '--includeAutomaticOptionalChainCompletions'),
includeCompletionsWithSnippetText: hasArgument(argv, '--includeCompletionsWithSnippetText'),
forceStrictTemplates: hasArgument(argv, '--forceStrictTemplates'),
disableBlockSyntax: hasArgument(argv, '--disableBlockSyntax'),
};
}

Expand Down
1 change: 1 addition & 0 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function main() {
includeAutomaticOptionalChainCompletions: options.includeAutomaticOptionalChainCompletions,
includeCompletionsWithSnippetText: options.includeCompletionsWithSnippetText,
forceStrictTemplates: isG3 || options.forceStrictTemplates,
disableBlockSyntax: options.disableBlockSyntax,
});

// Log initialization info
Expand Down
4 changes: 4 additions & 0 deletions server/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface SessionOptions {
includeAutomaticOptionalChainCompletions: boolean;
includeCompletionsWithSnippetText: boolean;
forceStrictTemplates: boolean;
disableBlockSyntax: boolean;
}

enum LanguageId {
Expand Down Expand Up @@ -156,6 +157,9 @@ export class Session {
if (options.forceStrictTemplates) {
pluginConfig.forceStrictTemplates = true;
}
if (options.disableBlockSyntax) {
pluginConfig.enableBlockSyntax = false;
}
projSvc.configurePlugin({
pluginName: options.ngPlugin,
configuration: pluginConfig,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@
uuid "^8.3.2"
yargs "^17.0.0"

"@angular/[email protected].0-rc.3":
version "17.0.0-rc.3"
resolved "https://registry.yarnpkg.com/@angular/language-service/-/language-service-17.0.0-rc.3.tgz#1594166701ab88ac45a9f67a2b5a9129e04694d5"
integrity sha512-F2LZUr9Kpeuz8Lqnm/KHxJMWX51+f2DzIPBNOVkNdgcTyQGXlQdJJBznpQ2QwaRaNP30Oz6/hOyAy95SKaVKSg==
"@angular/[email protected].1":
version "17.0.1"
resolved "https://registry.yarnpkg.com/@angular/language-service/-/language-service-17.0.1.tgz#3e08a65a1f02f5fe39e454819729f5ec20259d35"
integrity sha512-kDKmtMj410We8Rbph4e2xSuIs+MlzE7+QvIR07tofcoAR6Qpe2hr6WdsfExGBNIk5LNMYI3zdbEkAofG/JuRDA==

"@assemblyscript/loader@^0.10.1":
version "0.10.1"
Expand Down

0 comments on commit 0189dc8

Please sign in to comment.