Skip to content

Commit e276a57

Browse files
authored
fix: Disable block syntax parsing when no project in workspace supports it (#1962) (#1964)
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
1 parent d7dab52 commit e276a57

File tree

9 files changed

+44
-14
lines changed

9 files changed

+44
-14
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Input hashes for repository rule npm_translate_lock(name = "npm", pnpm_lock = "//:pnpm-lock.yaml").
22
# This file should be checked into version control along with the pnpm-lock.yaml file.
33
.npmrc=974837034
4-
pnpm-lock.yaml=-788183804
5-
yarn.lock=1782215124
6-
package.json=-1597267529
4+
pnpm-lock.yaml=-1149894156
5+
yarn.lock=1254518305
6+
package.json=-2138089801
77
pnpm-workspace.yaml=1711114604

client/src/client.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as lsp from 'vscode-languageclient/node';
1313

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

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

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

435+
const angularVersions = getAngularVersionsInWorkspace();
436+
// Only disable block syntax if we find angular/core and every one we find does not support block
437+
// syntax
438+
if (angularVersions.size > 0 && Array.from(angularVersions).every(v => v.version.major < 17)) {
439+
args.push('--disableBlockSyntax');
440+
}
441+
435442
const forceStrictTemplates = config.get<boolean>('angular.forceStrictTemplates');
436443
if (forceStrictTemplates) {
437444
args.push('--forceStrictTemplates');
@@ -505,3 +512,19 @@ function extensionVersionCompatibleWithAllProjects(serverModuleLocation: string)
505512
}
506513
return true;
507514
}
515+
516+
/**
517+
* Returns true if any project in the workspace supports block syntax (v17+).
518+
*/
519+
function getAngularVersionsInWorkspace(): Set<NodeModule> {
520+
const angularCoreModules = new Set<NodeModule>();
521+
const workspaceFolders = vscode.workspace.workspaceFolders || [];
522+
for (const workspaceFolder of workspaceFolders) {
523+
const angularCore = resolve('@angular/core', workspaceFolder.uri.fsPath);
524+
if (angularCore === undefined) {
525+
continue;
526+
}
527+
angularCoreModules.add(angularCore);
528+
}
529+
return angularCoreModules;
530+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@
222222
"test:legacy-syntaxes": "yarn compile:syntaxes-test && yarn build:syntaxes && jasmine dist/syntaxes/test/driver.js"
223223
},
224224
"dependencies": {
225-
"@angular/language-service": "17.0.0-rc.3",
225+
"@angular/language-service": "17.0.1",
226226
"typescript": "5.2.2",
227227
"vscode-html-languageservice": "^4.2.5",
228228
"vscode-jsonrpc": "6.0.0",

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"ngserver": "./bin/ngserver"
1616
},
1717
"dependencies": {
18-
"@angular/language-service": "17.0.0-rc.3",
18+
"@angular/language-service": "17.0.1",
1919
"vscode-html-languageservice": "^4.2.5",
2020
"vscode-jsonrpc": "6.0.0",
2121
"vscode-languageserver": "7.0.0",

server/src/cmdline_utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interface CommandLineOptions {
3636
includeAutomaticOptionalChainCompletions: boolean;
3737
includeCompletionsWithSnippetText: boolean;
3838
forceStrictTemplates: boolean;
39+
disableBlockSyntax: boolean;
3940
}
4041

4142
export function parseCommandLine(argv: string[]): CommandLineOptions {
@@ -50,6 +51,7 @@ export function parseCommandLine(argv: string[]): CommandLineOptions {
5051
hasArgument(argv, '--includeAutomaticOptionalChainCompletions'),
5152
includeCompletionsWithSnippetText: hasArgument(argv, '--includeCompletionsWithSnippetText'),
5253
forceStrictTemplates: hasArgument(argv, '--forceStrictTemplates'),
54+
disableBlockSyntax: hasArgument(argv, '--disableBlockSyntax'),
5355
};
5456
}
5557

server/src/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function main() {
4646
includeAutomaticOptionalChainCompletions: options.includeAutomaticOptionalChainCompletions,
4747
includeCompletionsWithSnippetText: options.includeCompletionsWithSnippetText,
4848
forceStrictTemplates: isG3 || options.forceStrictTemplates,
49+
disableBlockSyntax: options.disableBlockSyntax,
4950
});
5051

5152
// Log initialization info

server/src/session.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface SessionOptions {
3333
includeAutomaticOptionalChainCompletions: boolean;
3434
includeCompletionsWithSnippetText: boolean;
3535
forceStrictTemplates: boolean;
36+
disableBlockSyntax: boolean;
3637
}
3738

3839
enum LanguageId {
@@ -156,6 +157,9 @@ export class Session {
156157
if (options.forceStrictTemplates) {
157158
pluginConfig.forceStrictTemplates = true;
158159
}
160+
if (options.disableBlockSyntax) {
161+
pluginConfig.enableBlockSyntax = false;
162+
}
159163
projSvc.configurePlugin({
160164
pluginName: options.ngPlugin,
161165
configuration: pluginConfig,

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@
158158
uuid "^8.3.2"
159159
yargs "^17.0.0"
160160

161-
"@angular/language-service@17.0.0-rc.3":
162-
version "17.0.0-rc.3"
163-
resolved "https://registry.yarnpkg.com/@angular/language-service/-/language-service-17.0.0-rc.3.tgz#1594166701ab88ac45a9f67a2b5a9129e04694d5"
164-
integrity sha512-F2LZUr9Kpeuz8Lqnm/KHxJMWX51+f2DzIPBNOVkNdgcTyQGXlQdJJBznpQ2QwaRaNP30Oz6/hOyAy95SKaVKSg==
161+
"@angular/language-service@17.0.1":
162+
version "17.0.1"
163+
resolved "https://registry.yarnpkg.com/@angular/language-service/-/language-service-17.0.1.tgz#3e08a65a1f02f5fe39e454819729f5ec20259d35"
164+
integrity sha512-kDKmtMj410We8Rbph4e2xSuIs+MlzE7+QvIR07tofcoAR6Qpe2hr6WdsfExGBNIk5LNMYI3zdbEkAofG/JuRDA==
165165

166166
"@assemblyscript/loader@^0.10.1":
167167
version "0.10.1"

0 commit comments

Comments
 (0)