fix(vscode-extension): handle template literals when detecting supported decorator fields by aparzi · Pull Request #70571 · angular/angular · GitHub
Skip to content

fix(vscode-extension): handle template literals when detecting supported decorator fields - #70571

Open
aparzi wants to merge 1 commit into
angular:mainfrom
aparzi:fix-vscode-embedded-support-template-literals
Open

fix(vscode-extension): handle template literals when detecting supported decorator fields#70571
aparzi wants to merge 1 commit into
angular:mainfrom
aparzi:fix-vscode-embedded-support-template-literals

Conversation

@aparzi

@aparzi aparzi commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

The client decides whether a position in a TypeScript file belongs to a supported @Component field (template, styles, ...) with a lightweight ts.Scanner loop before forwarding requests to the language server and the HTML/CSS providers. ts.Scanner#scan doesn't handle template substitutions on its own: the } closing a ${...} substitution is reported as a plain CloseBraceToken and the rest of the template literal is scanned as the start of a new one, swallowing everything up to the next backtick. As a result, once a template literal with substitutions appears in a file, every position after it is considered to be inside a template string, and TypeScript completions get polluted with HTML completions.

The scanner is now driven the same way the TypeScript parser does it, re-scanning the brace that closes a substitution as a TemplateMiddle/TemplateTail token.

In addition, the property assignment context previously only ended at a terminator found at the top level of the file, so it leaked from template: to every string literal that followed it inside the same decorator and class body. The context now ends at the first terminator found at the nesting depth where it was entered. Two kinds of strings were only recognized thanks to that leak, and only when declared after template: inline styles and the arguments of @HostBinding/@HostListener decorators, both of which the language service supports. They are now recognized explicitly, regardless of where they appear.

Fixes #65494

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

Issue Number: #65494

What is the new behavior?

Screenshot 2026-09-04 alle 11 53 22

Does this PR introduce a breaking change?

  • Yes
  • No

…ted decorator fields

The client decides whether a position in a TypeScript file belongs to a supported `@Component` field (`template`, `styles`, ...) with a lightweight `ts.Scanner` loop before forwarding requests to the language server and the HTML/CSS providers. `ts.Scanner#scan` doesn't handle template substitutions on its own: the `}` closing a `${...}` substitution is reported as a plain `CloseBraceToken` and the rest of the template literal is scanned as the start of a new one, swallowing everything up to the next backtick. As a result, once a template literal with substitutions appears in a file, every position after it is considered to be inside a template string, and TypeScript completions get polluted with HTML completions.

The scanner is now driven the same way the TypeScript parser does it, re-scanning the brace that closes a substitution as a `TemplateMiddle`/`TemplateTail` token.

In addition, the property assignment context previously only ended at a terminator found at the top level of the file, so it leaked from `template:` to every string literal that followed it inside the same decorator and class body. The context now ends at the first terminator found at the nesting depth where it was entered. Two kinds of strings were only recognized thanks to that leak, and only when declared after `template`: inline `styles` and the arguments of `@HostBinding`/`@HostListener` decorators, both of which the language service supports. They are now recognized explicitly, regardless of where they appear.

Fixes angular#65494
@pullapprove
pullapprove Bot requested a review from kirjs September 4, 2026 10:01
@angular-robot angular-robot Bot added the area: vscode-extension Issues related to the Angular Language Service VsCode extension label Sep 4, 2026
@ngbot ngbot Bot added this to the Backlog milestone Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: vscode-extension Issues related to the Angular Language Service VsCode extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Template literals cause malfunction to quick suggestions

1 participant