-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Cases for refactor discoverability #37895
Comments
This list and the expected behavior look good to me. Thanks for putting it together! |
Hello 👋 I was curious about this feature because I tried looking around the documentation here and only through these issues did I figure out how this stuff works on the tsserver side (One has to select a chunk of text to be sent to tsserver to get the refactoring candidates available in that position) Is there a list of the available refactorings somewhere or some documentation on them? I'm interested in improving the UX for this stuff on the Btw, thanks a lot for the work on all of this. It seems almost magical 😍 (sorry if this isn't the right place to ask this but it seemed related to "refactor discoverability 🙈 ) |
Refactors live here: There has not been great documentation for available refactors and code fixes in the past, but we're working on changing that. I think the best we have at the moment is https://github.com/microsoft/JSTSdocs/blob/master/articles/editor/refactoring.md. To get an idea of how they work, I found it helpful to set a breakpoint in the function that gets the available refactors for a given span, for example An editor should first send |
Thank you for the quick reply @jessetrinity ! That is useful 👍 I was wondering because as it currently stands the UX of these refactorings seem a bit hard to discover naturally while coding. Right now, you just select a bunch of code randomly and see what comes up as a reply from |
Yeah, having to select the exact span does make them hard to discover. VS and VSCode have an icon that pops up when a span is selected to indicate that a refactor is available. The effort associated with this issue is returning the refactors if the span is not exactly selected, or if the cursor is simply within a valid span when I'm only vaguely familiar with how this looks in emacs. Is requesting available refactors at a cursor location something that would fit into the workflow for emacs users (is there a default key command to send the request)? The idea is that, in VSCode for example, using the refactor shortcut function foo(){
return 1/**/00 + 200;
} |
Closing following #38378 which added the refactor trigger reason and expanding the spans for some refactors. If we want to tweak any of the spans further we can open items for those refactors. |
Refactoring cases for which we can improve discoverability
This is the list of our refactors TSServer offers and the proposed changes to make them more discoverable. See #34930 for the broader discussion.
Here I have listed the current behavior as well as proposed changes to make the refactors more discoverable. Some of these ideas may offer refactors too frequently/infrequently, so more input is desired. The explicit refactoring request cases mentioned depend on #35096.
This issue does not list any code fixes.
addOrRemoveBracesToArrowFunction
Case - remove braces:
Current:
(n: number)
. selection end can be anywhere else.Proposed:
convertExport
Case - Convert default export to named export:
Case - Convert named export to default:
Current:
Proposed:
f()
ordefault
.return
statement, so we aren't in danger of offering up this refactor too much. We may even be fine offering it as often as in the explicit case.convertImport
Case - Convert namespace import to named imports:
Case - Convert named import to namespace import:
Current:
Proposed:
* as a
or{ f }
.extractSymbol
Case - extract const
Current:
2
offers to extract20
. This is not the case for other valid extraction candidates such as Identifiers or functions.20 + 1
is selected, no refactor is offered.Proposed:
Case - extract method
Current
Proposed:
function
keyword (or both).function bar
.extractType
Case - extract to type alias
Current:
string
selected.Proposed:
string
as the selecting whole type.string
Case - extract to interface
Current:
{ a?: number, b?: string }
selected.Proposed:
generateGetAccessorAndSetAccessor
Case - Generate 'get' and 'set' accessors
Current:
convertMe
.Proposed:
Refactors that are probably okay
Included for completeness. These cases are probably fine as is.
convertParamsToDestructuredObject
Current:
function f(a: number, b: number
. Selection end can be anywhere else.convertStringOrTemplateLiteral
Current:
a + "so below
. Selection end can be anywhere else.moveToNewFile
Current:
The text was updated successfully, but these errors were encountered: