-
Notifications
You must be signed in to change notification settings - Fork 1.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
Prompt for name when using extract refactoring assists #17579
Comments
It seems that the Typescript language server is sending a command to the client (in this case, VSCode) to trigger a rename dialog, as the dialog that shows up for renaming a symbol is shown by the client, which then sends the new name as part of a rust-analyzer does have custom commands (see rust-analyzer/editors/code/src/main.ts Line 113 in 5577e4e
|
Thanks for the guidance on where to look. Looking at tsserver, it seems that every refactoring method returns (possibly empty) information on the file and location to use in presenting the rename command after the refactor finishes. In RA, currently there's a trigger_signature_help bool, which controls whether a command is returned from the code action to the vscode client (and I assume is then run by the client). I think this can possibly be implemented by replacing the trigger_signature_help bool with an enum that specifies what command will run after the refactoring. I'll experiment a bit more soon. |
When the user applies the "Extract Variable" assist, the cursor is positioned at the newly inserted variable. This commit adds a command to the assist that triggers the rename action in VSCode. This way, the user can quickly rename the variable after applying the assist. Fixes part of: rust-lang#17579
Added #17587 which triggers editor.action.rename after performing variable extraction. I'd also add function and module extraction. Are there any other assists I might have missed that would also need this behavior? |
Trigger VSCode to rename after extract variable assist is applied When the user applies the "Extract Variable" assist, the cursor is positioned at the newly inserted variable. This commit adds a command to the assist that triggers the rename action in VSCode. This way, the user can quickly rename the variable after applying the assist. Fixes part of: #17579 https://github.com/user-attachments/assets/4cf38740-ab22-4b94-b0f1-eddd51c26c29 I haven't yet looked at the module or function extraction assists yet.
From looking at Note that not all of the generate assists use the correct snippet APIs (see #17332), and to do so would require migrating them to use both mutable AST and the appropriate |
Thanks. I took a brief look at the folder and also saw
I wondered about that - good to know that these don't implement the right methods. With 1.5K issues, it seems like it would be difficult to build up the context of what's a problem and what's intended easily. |
I'd also classify this one as a maybe as you'd typically want the extracted struct to have the same name as the variant name.
Guess you're in luck for this domain, since I was the one who moved the assists to using the |
makes sense.
Neat - it's good to be lucky :) |
In typescript, extracting a variable / function / etc. allows you to enter a name for the just created extraction. It would be nice to do the same in RA for functions, modules, variables, etc.
Playing with the extract_variable:
SourceChangeBuilder::add_placeholder_snippet_token doesn't seem quite right for this. Instead of a single edit location which applies to both places when the edit is confirmed, this method makes two edit locations that are edited simultaneously.
I'm not quite sure what the right terminology to use to find the functionality here, so seeking some guidance on what to do to make this work.
Edit: this UX is provided by the rename symbol function, but I'm not sure how that would fit in to the extract refactoring.
The text was updated successfully, but these errors were encountered: