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): Allow auto-imports of a pipe via quick fix when its selector is used. #48354

Closed
wants to merge 4 commits into from

Conversation

dylhunn
Copy link
Contributor

@dylhunn dylhunn commented Dec 5, 2022

Four commits, as below:

refactor(language-service): Improve the quick fix auto-import tests.

Currently, the auto-import tests are very difficult to debug, because the expectations are buried several function calls deep, and also because the multi-line replacements are hard to deal with. The auto-import tests now use a different approach, which can be easily debugged from the failure message. In addition, several new tests have been added to cover more cases.

refactor(compiler-cli): Make getKnown return an array of nodes.

MetadataReaderWithIndex.getKnown currently returns an iterator. It will be easier to work with for upcoming usages if it returns an array instead.

feat(language-service): Introduce a new NgModuleIndex, and use it to suggest re-exports.

NgModules can re-export other NgModules, which transitively includes all traits exported by the re-exported NgModule. We want to be able to suggest all re-exports of a component when trying to auto-import it.

Previously, we used an approximation when importing from NgModules: we looked at a Component's metadata, and just imported the declaring NgModule. However, this is not technically correct -- the declaring NgModule it is not necessarily the same one that exports it for the current scope. (Indeed, there could be multiple re-exports!) As a replacement, I have implemented a more general solution.

This PR introduces a new class on the template type checker, called NgModuleIndex. When queried, it conducts a depth-first-search over the NgModule import/export graph, in order to find all NgModules anywhere in the current dependency graph, as well as all exports of those NgModules. This allows the language service to suggest all of the re-exports, in addition to the original export.

feat(language-service): Allow auto-imports of a pipe via quick fix when its selector is used, both directly and via reexports.

A previous PR introduced a new compiler abstraction that tracks all known exports and re-exports of Angular traits. This PR harnesses that abstraction in the language service, in order to allow automatic imports of pipes.

@dylhunn dylhunn added the area: language-service Issues related to Angular's VS Code language service label Dec 5, 2022
@ngbot ngbot bot added this to the Backlog milestone Dec 5, 2022
@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Dec 5, 2022
@dylhunn dylhunn force-pushed the ls-pipes branch 2 times, most recently from de4e81e to e5fc833 Compare December 5, 2022 02:27
@dylhunn dylhunn marked this pull request as ready for review December 5, 2022 02:27
@dylhunn dylhunn added action: review The PR is still awaiting reviews from at least one requested reviewer target: minor This PR is targeted for the next minor release labels Dec 5, 2022
@dylhunn dylhunn requested review from atscott and removed request for AndrewKushnir December 5, 2022 02:29
@dylhunn dylhunn force-pushed the ls-pipes branch 3 times, most recently from ad8fb05 to 49787c1 Compare December 5, 2022 03:07
@dylhunn dylhunn added the action: presubmit The PR is in need of a google3 presubmit label Dec 5, 2022
@dylhunn
Copy link
Contributor Author

dylhunn commented Dec 7, 2022

@atscott Just want to keep this on your radar -- no rush though.

Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

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

reviewed-for: fw-language-service

Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

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

reviewed-for: language-service

@dylhunn
Copy link
Contributor Author

dylhunn commented Jan 9, 2023

Back to @alxhub with a new design for NgModuleIndex -- we should be in the home stretch now!

Currently, the auto-import tests are very difficult to debug, because the `expect`ations are buried several function calls deep, and also because the multi-line replacements are hard to deal with. The auto-import tests now use a different approach, which can be easily debugged from the failure message. In addition, several new tests have been added to cover more cases.
`MetadataReaderWithIndex.getKnown` currently returns an iterator. It will be easier to work with for upcoming usages if it returns an array instead.
…suggest re-exports.

NgModules can re-export other NgModules, which transitively includes all traits exported by the re-exported NgModule. We want to be able to suggest *all* re-exports of a component when trying to auto-import it.

Previously, we used an approximation when importing from NgModules: we looked at a Component's metadata, and just imported the declaring NgModule. However, this is not technically correct -- the declaring NgModule it is not necessarily the same one that exports it for the current scope. (Indeed, there could be multiple re-exports!) As a replacement, I have implemented a more general solution.

This PR introduces a new class on the template type checker, called `NgModuleIndex`. When queried, it conducts a depth-first-search over the NgModule import/export graph, in order to find all NgModules anywhere in the current dependency graph, as well as all exports of those NgModules. This allows the language service to suggest all of the re-exports, in addition to the original export.
…en its selector is used, both directly and via reexports.

A previous PR introduced a new compiler abstraction that tracks *all* known exports and re-exports of Angular traits. This PR harnesses that abstraction in the language service, in order to allow automatic imports of pipes.
@dylhunn dylhunn added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jan 12, 2023
@dylhunn
Copy link
Contributor Author

dylhunn commented Jan 12, 2023

caretaker: the failing windows CI job appears to be unrelated.

@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository by commit 4ae384f.

AndrewKushnir pushed a commit that referenced this pull request Jan 12, 2023
…8354)

`MetadataReaderWithIndex.getKnown` currently returns an iterator. It will be easier to work with for upcoming usages if it returns an array instead.

PR Close #48354
AndrewKushnir pushed a commit that referenced this pull request Jan 12, 2023
…suggest re-exports. (#48354)

NgModules can re-export other NgModules, which transitively includes all traits exported by the re-exported NgModule. We want to be able to suggest *all* re-exports of a component when trying to auto-import it.

Previously, we used an approximation when importing from NgModules: we looked at a Component's metadata, and just imported the declaring NgModule. However, this is not technically correct -- the declaring NgModule it is not necessarily the same one that exports it for the current scope. (Indeed, there could be multiple re-exports!) As a replacement, I have implemented a more general solution.

This PR introduces a new class on the template type checker, called `NgModuleIndex`. When queried, it conducts a depth-first-search over the NgModule import/export graph, in order to find all NgModules anywhere in the current dependency graph, as well as all exports of those NgModules. This allows the language service to suggest all of the re-exports, in addition to the original export.

PR Close #48354
AndrewKushnir pushed a commit that referenced this pull request Jan 12, 2023
…en its selector is used, both directly and via reexports. (#48354)

A previous PR introduced a new compiler abstraction that tracks *all* known exports and re-exports of Angular traits. This PR harnesses that abstraction in the language service, in order to allow automatic imports of pipes.

PR Close #48354
trekladyone pushed a commit to trekladyone/angular that referenced this pull request Feb 1, 2023
…ngular#48354)

Currently, the auto-import tests are very difficult to debug, because the `expect`ations are buried several function calls deep, and also because the multi-line replacements are hard to deal with. The auto-import tests now use a different approach, which can be easily debugged from the failure message. In addition, several new tests have been added to cover more cases.

PR Close angular#48354
trekladyone pushed a commit to trekladyone/angular that referenced this pull request Feb 1, 2023
…gular#48354)

`MetadataReaderWithIndex.getKnown` currently returns an iterator. It will be easier to work with for upcoming usages if it returns an array instead.

PR Close angular#48354
trekladyone pushed a commit to trekladyone/angular that referenced this pull request Feb 1, 2023
…suggest re-exports. (angular#48354)

NgModules can re-export other NgModules, which transitively includes all traits exported by the re-exported NgModule. We want to be able to suggest *all* re-exports of a component when trying to auto-import it.

Previously, we used an approximation when importing from NgModules: we looked at a Component's metadata, and just imported the declaring NgModule. However, this is not technically correct -- the declaring NgModule it is not necessarily the same one that exports it for the current scope. (Indeed, there could be multiple re-exports!) As a replacement, I have implemented a more general solution.

This PR introduces a new class on the template type checker, called `NgModuleIndex`. When queried, it conducts a depth-first-search over the NgModule import/export graph, in order to find all NgModules anywhere in the current dependency graph, as well as all exports of those NgModules. This allows the language service to suggest all of the re-exports, in addition to the original export.

PR Close angular#48354
trekladyone pushed a commit to trekladyone/angular that referenced this pull request Feb 1, 2023
…en its selector is used, both directly and via reexports. (angular#48354)

A previous PR introduced a new compiler abstraction that tracks *all* known exports and re-exports of Angular traits. This PR harnesses that abstraction in the language service, in order to allow automatic imports of pipes.

PR Close angular#48354
@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 12, 2023
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 detected: feature PR contains a feature commit merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note 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