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

Feature request: Add "move" symbol refactoring action #426

Open
maciejzj opened this issue Nov 13, 2023 · 2 comments
Open

Feature request: Add "move" symbol refactoring action #426

maciejzj opened this issue Nov 13, 2023 · 2 comments

Comments

@maciejzj
Copy link

maciejzj commented Nov 13, 2023

Hi!
It would be great to be able to move existing symbol (variable, function, class) to an existing file. Right now we can only "extract function" to a new file. A feature like this is present in IntelliJ products and VSCode refactoring tools.

I image that this would open a file picker (telescope/enhanced selection popup from nvim dressing would be great, I am not so sure about native nvim selection UI) and let the user choose the file where the symbol should be moved to.

This would be especially helpful if the refactoring tool was able to move code with necessary dependencies (e.g. Python import statements with modules used inside the function that is to be moved). This behaviour has been mentioned in slightly different context in #331. This would also require other modules to change how they import the symbol that is being moved (so they import it from the new location).

This could be expanded even more to enhance existing "extract function to file", which could then be split into "extract function to new file" (would work as it does now), and "extract function to existing file" which would combine extracting function with moving it to one of existing files via file picker. Moving modules would also be great (effectively this would be renaming files with updating other modules that depend on it to update they imports to the new name/location).

@TheLeoP
Copy link
Collaborator

TheLeoP commented Nov 13, 2023

Right now we can only "extract function" to a new file

Maybe it isn't really clear on the README, but currently it is possible to extract function to either a new file or an already existing file.

It would be great to be able to move existing symbol (variable, function, class).

This is different from the "extract function" functionality. Extract function extracts some code into a new function.

This would be especially helpful if the refactoring tool was able to move code with necessary dependencies

This would mean entering LSP territory. Currently, the plugin only uses treesitter to get all of the information for the refactorings. Any PR adding this functionality is welcome :3.

Moving modules would also be great (effectively this would be renaming files with updating other modules that depend on it to update they imports to the new name/location).

Some LSPs already support this, you can check plugins like nvim-lsp-file-operations that integrate this into Neovim.

@maciejzj
Copy link
Author

Maybe it isn't really clear on the README, but currently it is possible to extract function to either a new file or an already existing file.

Thanks, I didn't think of that. Indeed, this works. I've also found out that CTRL-X CTRL-F works for path completion when specifying the file to extract the function to, which is quite convenient.

I don't know Lua enough to work on the features I've requested. For me, this issue can be closed (or left open if you want to keep it as a feature request for the future).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants