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

feat(language-service): Provide ability to rename pipes #40523

Closed
wants to merge 6 commits into from

Conversation

atscott
Copy link
Contributor

@atscott atscott commented Jan 22, 2021

See individual commits:

  • The first few refactor the references and rename code to improve organization of the two capabilities
  • Commit to provide the pipe rename functionality
  • Commit to ensure pipe renaming works even when checkTypeOfPipes is set to false
  • Commit to correctly de-duplicate reference and rename entries which were only partially de-duplicated before.

@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 area: compiler Issues related to `ngc`, Angular's template compiler target: minor This PR is targeted for the next minor release labels Jan 22, 2021
@atscott atscott requested review from alxhub and zarend January 22, 2021 18:00
@ngbot ngbot bot modified the milestone: Backlog Jan 22, 2021
@google-cla google-cla bot added the cla: yes label Jan 22, 2021
@atscott atscott force-pushed the piperename branch 6 times, most recently from 93839c3 to fcf46f5 Compare January 26, 2021 15:40
@atscott atscott requested a review from kyliau January 27, 2021 21:09
Copy link
Contributor

@zarend zarend left a comment

Choose a reason for hiding this comment

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

👍

packages/language-service/ivy/ts_utils.ts Show resolved Hide resolved
@jessicajaniuk
Copy link
Contributor

@atscott Looks like this PR seems to have stalled. Any chance we can get it cleaned up and landed?

This commit renames the files for the references and rename functionality to indicate
that they deal with _both_ references and rename, not just references.
…nd rename

This commit extracts utility functions and separates them from the core logic of the
references and rename builder.
This commit separates the reference and rename functions into separate builders so it's easier
to locate functions specific to each
Copy link
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

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

A+ commit messages

packages/compiler-cli/src/ngtsc/metadata/src/dts.ts Outdated Show resolved Hide resolved
@atscott atscott force-pushed the piperename branch 2 times, most recently from 4bc8c39 to f730abd Compare May 5, 2021 21:35
@atscott
Copy link
Contributor Author

atscott commented May 5, 2021

presubmit

@atscott
Copy link
Contributor Author

atscott commented May 5, 2021

presubmit rerun

@kyliau kyliau removed the action: review The PR is still awaiting reviews from at least one requested reviewer label May 6, 2021
This commit updates the logic in the LS renaming to handle renaming of
pipes, both from the name expression in the pipe metadata as well as
from the template.

The approach here is to introduce a new concept for renaming: an
"indirect" rename. In this type of rename, we find rename locations
in with the native TS Language Service using a different node than the
one we are renaming. Using pipes as an example, if we want to rename the
pipe name from the string literal expression, we use the transform
method to find rename locations rather than the string literal itself
(which will not return any results because it's just a string).

So the general approach is:
* Determine the details about the requested rename location, i.e. the
  targeted template node and symbol for a template rename, or the TS
  node for a rename outside a template.
* Using the details of the location, determine if the node is attempting
  to rename something that is an indirect rename (pipes, selectors,
  bindings). Other renames are considered "direct" and we use whatever
  results the native TSLS returns for the rename locations.
* In the case of indirect renames, we throw out results that do not
  appear in the templates (in this case, the shim files). These results will be
  for the "indirect" rename that we don't want to touch, but are only
  using to find template results.
* Create an additional rename result for the string literal expression
  that is used for the input/output alias, the pipe name, or the
  selector.

 Note that renaming is moving towards being much more accurate in its
 results than "find references". When the approach for renaming
 stabilizes, we may want to then port the changes back to being shared
 with the approach for retrieving references.
… false

When `checkTypeOfPipes` is set to `false`, our TCB currently generates
the a statement like the following when pipes appear in the template:
`(_pipe1 as any).transform(args)`

This did enable us to get _some_ information from the Language Service
about pipes in this case because we still had access to the pipe
instance. However, because it is immediately cast to `any`, we cannot
get type information about the transform access. That means actions like "go to
definition", "find references", "quick info", etc. will return
incomplete information or fail altogether.

Instead, this commit changes the TCB to generate `(_pipe1.transform as any)(args)`.
This gives us the ability to get complete information for the LS
operations listed above.
Rather than de-duplicating results as we build them, a final de-duplication can be done at the end.
This way, there's no forgetting to de-duplicate results at some level.

Prior to this commit, results from template locations that mapped to
multiple different typescript locations would not be de-duplicated (e.g.
an input binding that is bound to two separate directives).
@atscott atscott added the action: merge The PR is ready for merge by the caretaker label May 6, 2021
@alxhub alxhub closed this in b8bd3c3 May 6, 2021
alxhub pushed a commit that referenced this pull request May 6, 2021
…nd rename (#40523)

This commit extracts utility functions and separates them from the core logic of the
references and rename builder.

PR Close #40523
alxhub pushed a commit that referenced this pull request May 6, 2021
#40523)

This commit separates the reference and rename functions into separate builders so it's easier
to locate functions specific to each

PR Close #40523
alxhub pushed a commit that referenced this pull request May 6, 2021
This commit updates the logic in the LS renaming to handle renaming of
pipes, both from the name expression in the pipe metadata as well as
from the template.

The approach here is to introduce a new concept for renaming: an
"indirect" rename. In this type of rename, we find rename locations
in with the native TS Language Service using a different node than the
one we are renaming. Using pipes as an example, if we want to rename the
pipe name from the string literal expression, we use the transform
method to find rename locations rather than the string literal itself
(which will not return any results because it's just a string).

So the general approach is:
* Determine the details about the requested rename location, i.e. the
  targeted template node and symbol for a template rename, or the TS
  node for a rename outside a template.
* Using the details of the location, determine if the node is attempting
  to rename something that is an indirect rename (pipes, selectors,
  bindings). Other renames are considered "direct" and we use whatever
  results the native TSLS returns for the rename locations.
* In the case of indirect renames, we throw out results that do not
  appear in the templates (in this case, the shim files). These results will be
  for the "indirect" rename that we don't want to touch, but are only
  using to find template results.
* Create an additional rename result for the string literal expression
  that is used for the input/output alias, the pipe name, or the
  selector.

 Note that renaming is moving towards being much more accurate in its
 results than "find references". When the approach for renaming
 stabilizes, we may want to then port the changes back to being shared
 with the approach for retrieving references.

PR Close #40523
alxhub pushed a commit that referenced this pull request May 6, 2021
… false (#40523)

When `checkTypeOfPipes` is set to `false`, our TCB currently generates
the a statement like the following when pipes appear in the template:
`(_pipe1 as any).transform(args)`

This did enable us to get _some_ information from the Language Service
about pipes in this case because we still had access to the pipe
instance. However, because it is immediately cast to `any`, we cannot
get type information about the transform access. That means actions like "go to
definition", "find references", "quick info", etc. will return
incomplete information or fail altogether.

Instead, this commit changes the TCB to generate `(_pipe1.transform as any)(args)`.
This gives us the ability to get complete information for the LS
operations listed above.

PR Close #40523
alxhub pushed a commit that referenced this pull request May 6, 2021
#40523)

Rather than de-duplicating results as we build them, a final de-duplication can be done at the end.
This way, there's no forgetting to de-duplicate results at some level.

Prior to this commit, results from template locations that mapped to
multiple different typescript locations would not be de-duplicated (e.g.
an input binding that is bound to two separate directives).

PR Close #40523
@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 Jun 6, 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: compiler Issues related to `ngc`, Angular's template compiler area: language-service Issues related to Angular's VS Code language service cla: yes target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants