Skip to content

Comments

refactor(language-server): add support for style binding completion.#66986

Open
JeanMeche wants to merge 1 commit intoangular:mainfrom
JeanMeche:vscode-style-binding
Open

refactor(language-server): add support for style binding completion.#66986
JeanMeche wants to merge 1 commit intoangular:mainfrom
JeanMeche:vscode-style-binding

Conversation

@JeanMeche
Copy link
Member

Inline style bindings <div [style]="{}"> will now suggest css properties, their value and components props.

fixes #58127

@JeanMeche JeanMeche force-pushed the vscode-style-binding branch from 91b19cc to f6030aa Compare February 10, 2026 02:46
@JeanMeche JeanMeche requested a review from atscott February 10, 2026 02:46
Inline style bindings `<div [style]="{}">` will now suggest css properties, their value and components props.

fixes angular#58127
@JeanMeche JeanMeche force-pushed the vscode-style-binding branch from f6030aa to 35b587f Compare February 10, 2026 03:22
Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty complicated for what I would consider a relatively low impact change. Can we maybe re-evaluate at a later time?

if (!ts.isStringLiteralLike(node)) {
return false;
}
return isAssignmentToPropertyWithName(node, 'template');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to make this better? This is currently returning true for any inline template at any cursor position

return content;
}

function extractComponentStyleBindings(templateContent: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An expression like [style]="{ content: '}' }" will prematurely hit braceCount === 0, truncating the virtual document and failing silently.

let objContent = templateContent.substring(startObj, endObj);

// Transform content to be more CSS-like:
// 1. Replace quotes with spaces (so keys become identifiers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parser replaces all ' and " with spaces. While this turns 'background-color' into an identifier, it destroys values that actually require strings (e.g., font-family: 'Open Sans' or content: '...')

// 1. Replace quotes with spaces (so keys become identifiers)
// 2. Replace top-level commas with semicolons (so key-values become declarations)
let transformedContent = '';
let parenDepth = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replaces , with ; when parenDepth === 0 to fake CSS declarations. However, it doesn't track object depth. If the user calls a macro/function foo({ a: 1, b: 2 }), the comma becomes a semicolon, feeding syntax errors to the CSS LS.

position: lsp.Position,
completions: ts.WithMetadata<ts.CompletionInfo> | undefined,
): lsp.CompletionItem[] | null {
const virtualCssDocContents = getCSSVirtualContent(sf);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-building the virtual CSS document using character-by-character string concatenation (transformedContent += char) for every inline template in the file on every single completion request (every keypress) is an unnecessary performance hit (I know we do this with inline styles already...).

@kbrilla
Copy link
Contributor

kbrilla commented Feb 11, 2026

hi @JeanMeche and @atscott I already have more complex version of features on this pr coming also with many other features - coming soon (will post draft pr today - but they are still in work) - please have a look at demo with some of those features please! I would much appreaciate it !! https://kbrilla.github.io/nativeoptional_chaning_and_template_features_upgrade/ as for LSP - I will post VSIX with all of those features combined and some tarballs of anngular that those features work with. Demo app was quickly prepared so it's not showing all features and can sometimes have some bug - didnt have time to fully review it yet as I focused now on adding all features tabs to it (there should be more tabs in and hour or two hopefully). Sorry for bothering You! bdw.

@mattrbeck mattrbeck added the area: language-service Issues related to Angular's VS Code language service label Feb 11, 2026
@ngbot ngbot bot added this to the Backlog milestone Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: language-service Issues related to Angular's VS Code language service

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Css Intellisense for inline styles ([style] binding)

4 participants