-
Notifications
You must be signed in to change notification settings - Fork 28.7k
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
Explore improving UX / API for refactorings #33555
Comments
Not sure about that last part. If "extract method" was implemented as a command (explicitly selected by the user from the command palette), all of the mentioned issues would be resolved:
On the flip side, you might end up with different languages all using different commands, unlike the "Rename Symbol" refactoring, which has explicit VSCode / language server support and uses the same command for all languages. Edit: the Python extension already seems to follow this pattern: |
Wait, everything here is a command. The
Now, it depends on your extension. You can either reference you "xyzRefactor"-command exclusively from
Yeah, rename is a special case. With our provider-pattern we try to generalise and align things such that the editor owns the UI and that extensions just provide data. Finding the smallest common denominator isn't always easy and for more complex refactorings we haven't been brave enough to try. |
Yes, "command" is indeed a confusing term here - I meant "implemented as a menu item", hence the added "selected by the user from the command palette". |
While commands work and have some advantages, I think using regular commands for refactoring leaves something to be desired:
|
Could there maybe be 2 types of code actions -- ones that are in @mjbvz terms "Tell" and ones that are "Ask". Meaning some code actions will cause the lightbulb to show up automagically, but refactoring and other similar code actions will only show if asked for (i.e. |
Yeah, it is a fine line. Generally, things that don't require UI, like "invert if-else", "insert semi-colon", or "inline variable" are good candidates for being a code action. However, it's not always that easy and when more complex interactions and user-input is required we usually carve out a provider-api including a data model, think of rename, completions etc. I don't want this issue to be the kitchen sink for all possible refactoring UIs, but would look at them case by case. We did try this in the past with "Extract Method/Function" but weren't confident enough that we cover all cases for all languages. We are also trying to keep our UI light and free from dialogs/pop-overs etc. /cc @stevencl |
A multi select would be nice for rename where you can choose to apply the rename to selected elements. It's not uncommon to have name collisions in PHP. |
Closing out this investigation. Outcome:
|
Refactoring like
extract method
don't seem like a great fit for the code actions or any other API that VSCode offers. This issue tracks an investigation of what a better ux/api for refactorings could look likeProblems / Background Info
@Gama11 makes some very good points about why refactorings don't seem to fit well with the current code action model: Annoying "lightbulb" whenever placing cursor into constant js/ts expression #33241 (comment)
No way to configure a keybinding for specific code actions / refactoring: Keybinding for applying a specific code action #33049
No feedback on why a refactoring is not available: Extract method / functiom must give feedback when a selection is not extractable and why #33501
Any other problems you've noticed or thoughts on refactoring support?
The text was updated successfully, but these errors were encountered: