Visitar URL original
feat(language-service): Provide plugin to delegate rename requests to Angular by ivanwonder · Pull Request #44696 · angular/angular · GitHub
The Wayback Machine - https://web.archive.org/web/20220305034748/https://github.com/angular/angular/pull/44696
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 plugin to delegate rename requests to Angular #44696

Closed

Conversation

ivanwonder
Copy link
Contributor

@ivanwonder ivanwonder commented Jan 12, 2022 •

When the user wants to rename a symbol in the ts file VSCode
will ask the rename providers for the answer in turn. If the
first extension returns the result, the VSCode will break the
loop and apply the result. If the first extension cannot rename
the symbol, VSCode will ask the second extension in the
list (built-in TS/JS extension, Angular LS extension, etc.).
In other words, VSCode takes the result from only one rename provider
and the order depends on registration timing, scoring.

Because the built-in ts extension and Angular extension have the
same high score, if the built-in ts extension is the
first(depends on the time the extension was registered), the result
will be provided by the built-in extension. We want Angular to
provide it, so this plugin will delegate rename requests and reject
the request for the built-in ts server.

The Angular LS only provides the rename info when working within
an Angular project. If we cannot locate Angular sources in the
project files, the built-in extension should provide the rename info.

This plugin will apply to the built-in TS/JS extension and delegate
rename requests to the Angular LS. It provides the rename info only
when it is an Angular project. Otherwise, it will return info by the
default built-in ts server rename provider.

See here for more info.

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

Copy link
Contributor

@atscott atscott left a comment

Really cool solution to the problem. I also like that you made this plugin available in the @angular/language-service so it could theoretically be used by extensions other than VSCode. Thanks for the investigation!

Given the complicated nature of the solution, I think it's a good idea to add more documentation and comments than is usually necessary. Here are a few changes I would propose:

  • Add the contents of the README as a comment at the top of the factory
  • Potentially add a README file here as well
  • I would consider renaming the built_in_ts_plugin to be more self-documenting in its name. Something like override_rename_ts_plugin.ts or disable_native_ts_rename_plugin
  • Update the commit message header to describe the goal rather than the solution. i.e. feat(language-service): Provide plugin to delegate rename requests to Angular and then add the implementation details to commit message body

I think it would also be good to get another reviewer's perspective. @clydin and @devversion - I've added you two as reviewers based on your knowledge of the general tooling/js/ts ecosystem. Feel free to un-assign yourselves if you don't have any input here.

@atscott atscott requested review from clydin and devversion Jan 13, 2022
@ivanwonder ivanwonder force-pushed the disable-built-in-rename-provide branch from 5700f99 to 0e26959 Jan 15, 2022
@ivanwonder ivanwonder requested a review from atscott Jan 15, 2022
@ivanwonder ivanwonder force-pushed the disable-built-in-rename-provide branch from 0e26959 to 7e2f843 Jan 17, 2022
@atscott atscott changed the title feat(language-service): Disable the rename provide in the built-in ex… feat(language-service): Provide plugin to delegate rename requests to Angular Jan 19, 2022
Copy link
Contributor

@atscott atscott left a comment

👍 LGTM with edits to the documentation text.

packages/language-service/README.md Outdated Show resolved Hide resolved
packages/language-service/README.md Outdated Show resolved Hide resolved
packages/language-service/README.md Outdated Show resolved Hide resolved
packages/language-service/README.md Outdated Show resolved Hide resolved
packages/language-service/README.md Outdated Show resolved Hide resolved
packages/language-service/override_rename_ts_plugin.ts Outdated Show resolved Hide resolved
… Angular

When the user wants to rename a symbol in the ts file VSCode
will ask the rename providers for the answer in turn. If the
first extension returns the result, the VSCode will break the
loop and apply the result. If the first extension cannot rename
the symbol, VSCode will ask the second extension in the
list (built-in TS/JS extension, Angular LS extension, etc.).
In other words, VSCode takes the result from only one rename provider
and the order depends on registration timing, scoring.

Because the built-in ts extension and Angular extension have the
same high score, if the built-in ts extension is the
first(depends on the time the extension was registered), the result
will be provided by the built-in extension. We want Angular to
provide it, so this plugin will delegate rename requests and reject
the request for the built-in ts server.

The Angular LS only provides the rename info when working within
an Angular project. If we cannot locate Angular sources in the
project files, the built-in extension should provide the rename info.

This plugin will apply to the built-in TS/JS extension and delegate
rename requests to the Angular LS. It provides the rename info only
when it is an Angular project. Otherwise, it will return info by the
default built-in ts server rename provider.

See [here][1] for more info.

[1]: microsoft/vscode#115354
@ivanwonder ivanwonder force-pushed the disable-built-in-rename-provide branch from 7e2f843 to 1998da9 Jan 20, 2022
@ivanwonder
Copy link
Contributor Author

@ivanwonder ivanwonder commented Jan 20, 2022

I am not good at writing. Thanks for the suggestion.

You can review it again now.

Copy link
Member

@devversion devversion left a comment

LGTM for dev-infra.

@devversion
Copy link
Member

@devversion devversion commented Jan 21, 2022

@atscott I just saw that you pinged Charles and myself on this directly. Sorry for the late response. I think this conceptually makes a lot of sense to me. I unfortunately do not have low-level understanding of the language service yet, but as said, conceptually that seems very reasonable until the root cause/scoring is modified.

It would be cool if the doc would show an example of how this additional plugin can be wired up? or is that planned as a follow-up?

@ivanwonder
Copy link
Contributor Author

@ivanwonder ivanwonder commented Jan 21, 2022

It would be cool if the doc would show an example of how this additional plugin can be wired up? or is that planned as a follow-up?

The follow-up PR is here

@atscott
Copy link
Contributor

@atscott atscott commented Jan 21, 2022

@atscott I just saw that you pinged Charles and myself on this directly. Sorry for the late response. I think this conceptually makes a lot of sense to me. I unfortunately do not have low-level understanding of the language service yet, but as said, conceptually that seems very reasonable until the root cause/scoring is modified.

👍 Sounds good, thanks for taking a look! I think that's pretty much all I was looking for :)

It would be cool if the doc would show an example of how this additional plugin can be wired up? or is that planned as a follow-up?

As @ivanwonder mentioned, the follow-up PR for the extension is angular/vscode-ng-language-service#1589.

@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Jan 21, 2022

This PR was merged into the repository by commit 9d4af65.

@ivanwonder ivanwonder deleted the disable-built-in-rename-provide branch Jan 22, 2022
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Feb 22, 2022

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 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants