Skip to content

fix: Disable block syntax parsing when no project in workspace suppor… #1964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=-788183804
yarn.lock=1782215124
package.json=-1597267529
pnpm-lock.yaml=-1149894156
yarn.lock=1254518305
package.json=-2138089801
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
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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