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): correctly parse expressions in an attribute #34517

Closed

Conversation

ayazhafiz
Copy link
Member

@ayazhafiz ayazhafiz commented Dec 20, 2019

Currently, the language service provides completions in a template node
attribute by first checking if the attribute contains template bindings
to provide completions for, and then providing completions for the
expression in the attribute.

In the latter case, the expression AST was being constructed
"synthetically" inside the language service, in particular declaring the
expression to be a PropertyRead with an implicit receiver.
Unfortunately, this AST can be incorrect if the expression is actually a
property read on a component property receiver (e.g. when reading
key in the expression obj.key, obj is the receiver).

The fix is pretty simple - rather than a synthetic construction of the
AST, ask the expression parser to parse the expression in the attribute.

Fixes angular/vscode-ng-language-service#523

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix

Does this PR introduce a breaking change?

  • Yes
  • No

@ayazhafiz ayazhafiz added type: bug/fix area: language-service Issues related to Angular's VS Code language service target: patch This PR is targeted for the next patch release labels Dec 20, 2019
@ayazhafiz ayazhafiz requested a review from a team as a code owner December 20, 2019 20:40
@ayazhafiz ayazhafiz self-assigned this Dec 20, 2019
@ayazhafiz ayazhafiz force-pushed the fix/expression-in-template-binding branch from cc10625 to 4d88597 Compare December 20, 2019 20:40
@ngbot ngbot bot added this to the needsTriage milestone Dec 20, 2019
@ayazhafiz ayazhafiz force-pushed the fix/expression-in-template-binding branch from 4d88597 to abb3d57 Compare December 20, 2019 20:55
Currently, the language service provides completions in a template node
attribute by first checking if the attribute contains template bindings
to provide completions for, and then providing completions for the
expression in the attribute.

In the latter case, the expression AST was being constructed
"synthetically" inside the language service, in particular declaring the
expression to be a `PropertyRead` with an implicit receiver.
Unfortunately, this AST can be incorrect if the expression is actually a
property read on a component property receiver (e.g. when reading
`key` in the expression `obj.key`, `obj` is the receiver).

The fix is pretty simple - rather than a synthetic construction of the
AST, ask the expression parser to parse the expression in the attribute.

Fixes angular/vscode-ng-language-service#523
@ayazhafiz ayazhafiz force-pushed the fix/expression-in-template-binding branch from abb3d57 to 0b366e2 Compare December 20, 2019 20:58
@ayazhafiz ayazhafiz removed their assignment Dec 20, 2019
Copy link
Contributor

@kyliau kyliau left a comment

Choose a reason for hiding this comment

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

thank you, this is really clean.

@kyliau kyliau added the action: merge The PR is ready for merge by the caretaker label Dec 21, 2019
@alxhub alxhub closed this in ee46b9b Jan 6, 2020
alxhub pushed a commit that referenced this pull request Jan 6, 2020
…34517)

Currently, the language service provides completions in a template node
attribute by first checking if the attribute contains template bindings
to provide completions for, and then providing completions for the
expression in the attribute.

In the latter case, the expression AST was being constructed
"synthetically" inside the language service, in particular declaring the
expression to be a `PropertyRead` with an implicit receiver.
Unfortunately, this AST can be incorrect if the expression is actually a
property read on a component property receiver (e.g. when reading
`key` in the expression `obj.key`, `obj` is the receiver).

The fix is pretty simple - rather than a synthetic construction of the
AST, ask the expression parser to parse the expression in the attribute.

Fixes angular/vscode-ng-language-service#523

PR Close #34517
@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 Feb 6, 2020
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 type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

incorrect autocomplete entries
3 participants