Skip to content

Commit 3dbcc7f

Browse files
atscottzarend
authored andcommitted
fix(language-service): bound attributes should not break directive matching (#41597)
The language service uses an elements attributes to determine if it matches a directive in the component scope. We do this by accumulating all attribute bindings and matching against the selectors for the available directives. The compiler itself does a similar thing. In addition, the compiler does not use the value of `BoundAttribute`s to match directives (https://github.com/angular/angular/blob/cdf1ea1951fb7187b1f6c9bb8a847c859c41e0b8/packages/compiler/src/render3/view/util.ts#L174-L206). This commit changes the language service to also ignore bound attribute values for directive matching. Fixes angular/vscode-ng-language-service#1278 PR Close #41597
1 parent df04b9b commit 3dbcc7f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/language-service/ivy/test/quick_info_spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ describe('quick info', () => {
151151
expect(toText(documentation)).toBe('This Component provides the `test-comp` selector.');
152152
});
153153

154+
it('should work for components with bound attributes', () => {
155+
const {documentation} = expectQuickInfo({
156+
templateOverride: `<t¦est-comp [attr.id]="'1' + '2'" [attr.name]="'myName'"></test-comp>`,
157+
expectedSpanText: `<test-comp [attr.id]="'1' + '2'" [attr.name]="'myName'"></test-comp>`,
158+
expectedDisplayString: '(component) AppModule.TestComponent'
159+
});
160+
expect(toText(documentation)).toBe('This Component provides the `test-comp` selector.');
161+
});
162+
154163
it('should work for structural directives', () => {
155164
const {documentation} = expectQuickInfo({
156165
templateOverride: `<div *¦ngFor="let item of heroes"></div>`,

packages/language-service/ivy/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function getFirstComponentForTemplateFile(fileName: string, compiler: NgCompiler
171171
* Given an attribute node, converts it to string form.
172172
*/
173173
function toAttributeString(attribute: t.TextAttribute|t.BoundAttribute|t.BoundEvent): string {
174-
if (attribute instanceof t.BoundEvent) {
174+
if (attribute instanceof t.BoundEvent || attribute instanceof t.BoundAttribute) {
175175
return `[${attribute.name}]`;
176176
} else {
177177
return `[${attribute.name}=${attribute.valueSpan?.toString() ?? ''}]`;

0 commit comments

Comments
 (0)