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

Move symbol/definition to other module #551

Closed
jonathanmoregard opened this issue Oct 29, 2020 · 13 comments
Closed

Move symbol/definition to other module #551

jonathanmoregard opened this issue Oct 29, 2020 · 13 comments

Comments

@jonathanmoregard
Copy link

jonathanmoregard commented Oct 29, 2020

When I want to move a Thing (= type, class, function, pattern etc) to another module, I have to:

  1. Select the declaration
  2. Cut to clipboard
  3. Open the destination module
  4. Paste from clipboard
  5. Remove the Thing from the origin module's "module export list"
  6. Add the Thing to the destination module's "module export list"
  7. Go through all places where it has been imported and update the import statements to reflect the move.

I propose adding a code action called "Move.." which works like this:

  1. Initiate the "Move.." action on a Thing
  2. Open up a drop down (or equivalent) where you can filter/select a destination module from a list of all modules in the project.

Then Automatically:

  1. Move the Thing you initiated the "Move"-action on to that module.
  2. If it was exposed: remove it from the origin module's "module export list", add it to the destination module's "module export list"
  3. Rewrite import statements pointing to the Thing in the origin module so that they point to the new location (destination module).
@ndmitchell
Copy link
Collaborator

I've wanted something similar - but my UI/use-case was slightly different, so adding it here so they can be considered in tandem.

I want to be able to copy a fragment (using standard copy ideally) then paste it into another module and have all the imports be filled in. Things like removing export, deleting imports are either easy, or have automatic cleanups already. Finding the imports that a fragment required is much more work. I imagine a "Paste with imports" button or similar. Not sure what of that is possible within the constraints of LSP.

@jneira
Copy link
Member

jneira commented Oct 29, 2020

It seems the first proposal could be combined with @ndmitchell one to be "complete": if the code being moved is using definitions that are not imported in the destination module, it will not compile so add the needed imports in one go would be really sweet (deleting the no used ones in the original module would be extraordinary)

That said, afaik till the date, we have not added isolate code actions, only quick fixes linked with diagnostics (errors or warnings) or linked to code lenses. I think the reason is we want to avoid define code actions in the extension itself, cause other editors (emacs, vim, etc) will not have them without replicating them. Quick fixes and code lenses are defined in the server and available for all editors for "free".

Maybe @alanz could help to clarifiy/confirm that though.

@alanz
Copy link
Collaborator

alanz commented Oct 29, 2020

These features are in the domain of a refactorer, such as HaRe.

In terms of LSP, it should be possible to do something like select a function and be offered a code action to extract it to another module. The problem is, there is no ability to specify which module it should go to. The only affordance is rename, so possibly giving it a fully qualified name could specify the target module, and create it if it doesn't exist already.

@jonathanmoregard
Copy link
Author

It seems the first proposal could be combined with @ndmitchell one to be "complete": it the code being moved is using definitions that are not imported in the destination module, it will not compile so add the needed imports in one go would be really sweet (deleting the no used ones in the original module would be extraordinary)

That is what I meant by Redirect any references (import statements in other modules) so that they point to the destination module.. I'll try clarifying.

@jneira jneira changed the title [Feature request] Move to other module Move symbol/definition to other module Aug 2, 2021
@jneira
Copy link
Member

jneira commented Aug 2, 2021

The problem is, there is no ability to specify which module it should go to. The only affordance is rename, so possibly giving it a fully qualified name could specify the target module, and create it if it doesn't exist already.

I think we could follow this wise advise although ideally it should have support in the lsp spec and vscode, to being able to select the destination module graphically (or create a new one)

Related lsp spec issues:

But i've not found any issue about move symbols between "modules" or the equivalent in other langs

@jonathanmoregard
Copy link
Author

jonathanmoregard commented Jan 21, 2022

They have something similar in the elm. elm-tooling/elm-language-server#226
Can we use a similar approach to let the user select the module?

Also, @alanz, about HaRe: I like refactoring as I go along. Having to switch to a separate tool is a big hurdle to me. As such, if it's possible to get it in HLS, my life would be much easier.

@jneira
Copy link
Member

jneira commented Jan 21, 2022

The only affordance is rename, so possibly giving it a fully qualified name could specify the target module, and create it if it doesn't exist already.

That could be a way to go forward although having to write the module by hand instead pick it from a menu would be error prone (or simply drag the symbol to another module, like other ides do)

@jneira
Copy link
Member

jneira commented Jan 21, 2022

@jonathanmoregard thanks for the elm pointer, relevant notes from it:

@jonathanmoregard
Copy link
Author

@jneira is the "putting all the logic in the server"-thing still the policy?

Also, is the "putting all the logic in the server" something that would be a blocker if someone submitted a PR to implement this feature in the vscode extension?

@jneira
Copy link
Member

jneira commented Sep 29, 2022

I think so but maybe another active maintainer could confirm it, @michaelpj?

@michaelpj
Copy link
Collaborator

The fact is that HLS's main problem is maintainability and lack of maintainer bandwidth. The LSP model is a huge blessing for us, because it means we can largely ignore clients. Even then, the vscode extension requires significant maintenance. So I think our general position is probably still to avoid doing custom things that take us back into the bad world of per-client support.

@jonathanmoregard
Copy link
Author

@michaelpj I see, thanks for the context

@michaelpj
Copy link
Collaborator

I'm closing this as wontfix since I don't see us doing it any time soon.

@michaelpj michaelpj closed this as not planned Won't fix, can't repro, duplicate, stale Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants