Skip to content

Conversation

@crisbeto
Copy link
Member

Includes the following fixes for the language service:

fix(language-service): allow fixes to run without template info

Currently the code fixes won't run if the template information can't be resolved on the diagnostic node. This is incorrect for diagnostics that are reported within .ts files. These changes make the templateInfo nullable and leave the early exit up to the individual fixes.

fix(language-service): add fix for individual unused imports

Fixes that getCodeActions wasn't implemented for the unused imports fixer which meant that it wouldn't show up in the most common cases.

Currently the code fixes won't run if the template information can't be resolved on the diagnostic node. This is incorrect for diagnostics that are reported within `.ts` files. These changes make the `templateInfo` nullable and leave the early exit up to the individual fixes.
Fixes that `getCodeActions` wasn't implemented for the unused imports fixer which meant that it wouldn't show up in the most common cases.
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: rc This PR is targeted for the next release-candidate labels Nov 18, 2024
@crisbeto crisbeto requested a review from devversion November 18, 2024 16:21
@pullapprove pullapprove bot requested a review from alxhub November 18, 2024 16:21
@angular-robot angular-robot bot added the area: language-service Issues related to Angular's VS Code language service label Nov 18, 2024
@ngbot ngbot bot added this to the Backlog milestone Nov 18, 2024
for (const action of codeActions) {
const actionChanges = action.changes.flatMap((change) => {
return change.textChanges.map((tc) => {
const oldText = collapse(fileContents.slice(tc.span.start, tc.span.start + spawn.length));
Copy link
Member Author

Choose a reason for hiding this comment

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

Note the typo here was spawn.length instead of tc.span.length which meant that the assertion was always incorrect. I've fixed it plus a handful of tests that weren't asserting properly.

@crisbeto crisbeto requested review from clydin and removed request for alxhub November 18, 2024 16:25
Copy link
Member

@clydin clydin left a comment

Choose a reason for hiding this comment

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

LGTM.

As followup, would it be useful to have some sort of requiresTemplateInfo boolean on the code fix action definition? As we increase the amount of code fixes, this would allow bypassing the getCodeActions call completely instead of adding null checks to each action. And it avoids the empty array creation plus spread/push for each.

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Nov 18, 2024
@devversion devversion added target: patch This PR is targeted for the next patch release and removed target: rc This PR is targeted for the next release-candidate labels Nov 19, 2024
@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository by commit dcd27d7.

The changes were merged into the following branches: main, 19.0.x

AndrewKushnir pushed a commit that referenced this pull request Nov 19, 2024
Fixes that `getCodeActions` wasn't implemented for the unused imports fixer which meant that it wouldn't show up in the most common cases.

PR Close #58719
AndrewKushnir pushed a commit that referenced this pull request Nov 19, 2024
Currently the code fixes won't run if the template information can't be resolved on the diagnostic node. This is incorrect for diagnostics that are reported within `.ts` files. These changes make the `templateInfo` nullable and leave the early exit up to the individual fixes.

PR Close #58719
AndrewKushnir pushed a commit that referenced this pull request Nov 19, 2024
Fixes that `getCodeActions` wasn't implemented for the unused imports fixer which meant that it wouldn't show up in the most common cases.

PR Close #58719
@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 Dec 20, 2024
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 target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants