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): prune duplicate returned definitions #34995

Closed
wants to merge 2 commits into from

Conversation

ayazhafiz
Copy link
Member

Sometimes, a request for definitions will return multiple of the same
definition. This can happen in at least the cases of

  • two-way bindings (one of the same definition for the property and
    event binding)
  • multiple template binding expressions in the same attribute

This commit prunes duplicate definitions by signing definitions with
their location, and checking if that location signature has been seen in
a previous definition returned to the client.

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 Jan 27, 2020
@ayazhafiz ayazhafiz requested a review from a team as a code owner January 27, 2020 16:20
@ngbot ngbot bot modified the milestone: needsTriage Jan 27, 2020
@ayazhafiz ayazhafiz requested review from aikithoughts and kyliau and removed request for aikithoughts January 27, 2020 18:11
Comment on lines +66 to +67
const signature = `${textSpan.start}:${textSpan.length}@${fileName}`;
if (seen.has(signature)) continue;
Copy link
Member Author

Choose a reason for hiding this comment

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

@kyliau I don't think we'll be able to use uniqueBySpan because we need to sign the filename as well. I can make a util function extending uniqueBySpan in either this or a future PR.

Sometimes, a request for definitions will return multiple of the same
definition. This can happen in at least the cases of

- two-way bindings (one of the same definition for the property and
  event binding)
- multiple template binding expressions in the same attribute
  - something like "*ngFor="let i of items; trackBy: test" has two
    template bindings, resulting in two template binding ASTs at the
    same location (the attribute span). The language service then parses
    both of these bindings individually, resulting in two independent
    but identical definitions. For more context, see angular#34847 (comment).

This commit prunes duplicate definitions by signing definitions with
their location, and checking if that location signature has been seen in
a previous definition returned to the client.
@kyliau kyliau added the action: merge The PR is ready for merge by the caretaker label Jan 29, 2020
AndrewKushnir pushed a commit that referenced this pull request Jan 29, 2020
Sometimes, a request for definitions will return multiple of the same
definition. This can happen in at least the cases of

- two-way bindings (one of the same definition for the property and
  event binding)
- multiple template binding expressions in the same attribute
  - something like "*ngFor="let i of items; trackBy: test" has two
    template bindings, resulting in two template binding ASTs at the
    same location (the attribute span). The language service then parses
    both of these bindings individually, resulting in two independent
    but identical definitions. For more context, see #34847 (comment).

This commit prunes duplicate definitions by signing definitions with
their location, and checking if that location signature has been seen in
a previous definition returned to the client.

PR Close #34995
sonukapoor pushed a commit to sonukapoor/angular that referenced this pull request Feb 13, 2020
…34995)

Sometimes, a request for definitions will return multiple of the same
definition. This can happen in at least the cases of

- two-way bindings (one of the same definition for the property and
  event binding)
- multiple template binding expressions in the same attribute
  - something like "*ngFor="let i of items; trackBy: test" has two
    template bindings, resulting in two template binding ASTs at the
    same location (the attribute span). The language service then parses
    both of these bindings individually, resulting in two independent
    but identical definitions. For more context, see angular#34847 (comment).

This commit prunes duplicate definitions by signing definitions with
their location, and checking if that location signature has been seen in
a previous definition returned to the client.

PR Close angular#34995
@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 29, 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.

None yet

3 participants