Skip to content
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

fix(language-service): bound attributes should not break directive matching #41597

Closed
wants to merge 1 commit into from

Conversation

atscott
Copy link
Contributor

@atscott atscott commented Apr 13, 2021

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 BoundAttributes to
match directives (

/**
* Extract a map of properties to values for a given element or template node, which can be used
* by the directive matching machinery.
*
* @param elOrTpl the element or template in question
* @return an object set up for directive matching. For attributes on the element/template, this
* object maps a property name to its (static) value. For any bindings, this map simply maps the
* property name to an empty string.
*/
export function getAttrsForDirectiveMatching(elOrTpl: t.Element|
t.Template): {[name: string]: string} {
const attributesMap: {[name: string]: string} = {};
if (elOrTpl instanceof t.Template && elOrTpl.tagName !== 'ng-template') {
elOrTpl.templateAttrs.forEach(a => attributesMap[a.name] = '');
} else {
elOrTpl.attributes.forEach(a => {
if (!isI18nAttribute(a.name)) {
attributesMap[a.name] = a.value;
}
});
elOrTpl.inputs.forEach(i => {
attributesMap[i.name] = '';
});
elOrTpl.outputs.forEach(o => {
attributesMap[o.name] = '';
});
}
return attributesMap;
}
). This commit changes the language
service to also ignore bound attribute values for directive matching.

@atscott atscott added action: review The PR is still awaiting reviews from at least one requested reviewer area: language-service Issues related to Angular's VS Code language service target: patch This PR is targeted for the next patch release labels Apr 13, 2021
@ngbot ngbot bot added this to the Backlog milestone Apr 13, 2021
@google-cla google-cla bot added the cla: yes label Apr 13, 2021
@ngbot ngbot bot modified the milestone: Backlog Apr 13, 2021
packages/language-service/ivy/utils.ts Outdated Show resolved Hide resolved
packages/language-service/ivy/utils.ts Outdated Show resolved Hide resolved
@kyliau kyliau added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 13, 2021
packages/language-service/ivy/utils.ts Outdated Show resolved Hide resolved
packages/language-service/ivy/utils.ts Outdated Show resolved Hide resolved
packages/language-service/ivy/utils.ts Outdated Show resolved Hide resolved
packages/language-service/ivy/test/quick_info_spec.ts Outdated Show resolved Hide resolved
@atscott atscott removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Apr 13, 2021
…tching

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
@atscott atscott changed the title fix(language-service): expression bindings should not break directive… fix(language-service): bound attributes should not break directive matching Apr 13, 2021
@atscott atscott added the action: merge The PR is ready for merge by the caretaker label Apr 13, 2021
@zarend zarend closed this in bd34bc9 Apr 14, 2021
zarend pushed a commit that referenced this pull request Apr 14, 2021
…tching (#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
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: language-service Issues related to Angular's VS Code language service cla: yes target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants