-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
TSServer: Refactor trigger reason #35096
Comments
I think the hierarchal refactorings for tsserver is something we should add for the reasons mentioned here. @minestarks |
Can we close this since we added the refactor trigger reason, or does this item track the hierarchical refactoring as well? |
From discussions, the TS team did seem interested in the hierarchical part of this proposal, so let's make sure we still track that, either with this issue or by opening a new one |
Follow up on #34930
Problem
VS Code lets user create keybindings for specific refactorings like extract constant. At present, TS Server does not know if refactorings are requested explicitly by the user using a keyboard shortcut or if they are requested automatically when the user simply makes a selection in the current document.
This distinction is important for a few reasons brought up in #34930:
extract constant
with no selection, TS Server could assume that I want to extract the nearest expression.Protocol Proposal
In the
getApplicableRefactors
request, add a newtriggerReason
field:The trigger reason would capture why the refactoring was requested:
At the moment, I think we only need a single trigger reason:
invoked
. I have based this design around the existing server API for parameter hints.How TS Server could use
triggerReason
As a first step, when refactorings are explicitly invoked by the user, if the current selection is not extractable, we should automatically expand the selection for
extract constant
andextract function
to nearest extractable expression.Possible extension: hierarchal refactorings
VS Code uses a hierarchal system to assign the class of code actions / refactorings. For example,
extract constant
has aCodeActionKind
ofrefactor.extract.constant
. Users can setup keybindings forrefactor.extract
(show allextract
refactorings) or forrefactor.extract.constant
(show only theextract constant
refactorings).We should consider putting some form of hierarchical refactorings into the TS Server api as well. A few reasons this may be helpful:
extract constant
refactorings for TS Server, we could show more than one expression around the current selection that can be extracted.To support this in the server api, we would need to add a new another field on
RefactorInvokedReason
:VS Code uses dotted string to represent a hierarchy of refactoring types (e.g.
"refactor.extract.constant"
). TS could also use this scheme. Or we could hardcode the hierarchy:The text was updated successfully, but these errors were encountered: