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): autocompletion for the component not imported #55595

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ivanwonder
Copy link
Contributor

@ivanwonder ivanwonder commented Apr 30, 2024

This PR allows the language service to suggest imports for all directives returned from the compiler, and generate the TypeScript module import and the decorator import when the component is selected by the user.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Apr 30, 2024
@thePunderWoman thePunderWoman added the area: language-service Issues related to Angular's VS Code language service label Apr 30, 2024
@ngbot ngbot bot added this to the Backlog milestone Apr 30, 2024
@ivanwonder ivanwonder force-pushed the completion-compoent-not-imported branch 5 times, most recently from 5a9b8ca to fa81eca Compare May 6, 2024 14:29
@ivanwonder
Copy link
Contributor Author

https://github.com/angular/angular/blob/1872fcd8e09fefb52f9b36e8261702cd6fb03f85/packages/compiler-cli/src/ngtsc/typecheck/src/checker.ts#L766_L771

This will be a bug if two components have the same selector name. I think we can fix this later.

This PR allows the language service to suggest imports for all directives returned from the
compiler, and generate the TypeScript module import and the decorator import when the component
is selected by the user.
@ivanwonder ivanwonder force-pushed the completion-compoent-not-imported branch from fa81eca to b3feb56 Compare May 7, 2024 13:02
Copy link
Contributor

@dylhunn dylhunn left a comment

Choose a reason for hiding this comment

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

Really nice work, thank you for making this improvement! I didn't realize you could provide actions alongside completions like this, and good work factoring out the common code.

reviewed-for: fw-compiler, language-service

@dylhunn dylhunn added the target: minor This PR is targeted for the next minor release label May 16, 2024
@ivanwonder
Copy link
Contributor Author

@dylhunn

I find a bug here. I only tested it in the HTML file, It doesn't work for the template in the ts file because the code action breaks the rule of additionalTextEdits, additional text edits should be used to change text unrelated to the current cursor position, but the auto-import code action change range includes the template where the current cursor is.

I think the code action for auto-import should only touch the imports array instead of the whole component decorators. I will try to fix this.

Sorry about this.

@dylhunn dylhunn added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews area: language-service Issues related to Angular's VS Code language service detected: feature PR contains a feature commit 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

3 participants