-
Notifications
You must be signed in to change notification settings - Fork 793
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
How can a server implement "extract method" (how can it trigger rename?) #764
Comments
Could we imagine codeAction result having a |
That feels very specific, I think having something more general would be better (for ex. supporting snippet syntax in the returned edits?). |
Yes, snippet syntax on all edits would help a lot. |
I don't think extracting a method would affect multiple files. This sounds like the sort of refactoring that's local in scope by nature, in which case, snippets would make sense (that was also the mechanism I was thinking of). But I might be wrong. |
Right, my previous comment doesn't apply to "extract method", and usage of snippets in CodeActions/TextEdit still seems the best and simplest approach for this specific refactoring. |
@dbaeumer do you have any thoughts on this? I'd like to be able to migrate to LSP but I have a few remaining features that seem stuck on this. I'm unsure whether to a) implement this using my own custom commands (which means each editor will need custom code, and have to work around #642) or hold off in the hope that there might be a better solution available (or available soon). |
I have the exact same issue as you (renaming an extracted method). Adding snippet support to edits would solve this and many other problems. |
For a lengthy discussion about supporting snippets in code actions see #724. Even if we have this it would be something the client needs to opt in (e.g. it would be a capability). IMO the best way to push this forward would be to allow snippets in code actions since it resolves in the nicest user experience. |
any progress on this? |
There is work under way to add snippets to workspace edits. |
Snippers made it into code actions and workspace edits for 3.18 |
#662 suggests we can implement "extract method" using existing code actions, however I can't see any mechanism for how the user would be prompted for a name, or the server could tell the client to invoke rename after the edit.
For example, let's say I have this code:
I highlight the calls to
b()
andc()
and invoke Extract Method. I end up with this:We really want to to either have prompted the user for
newMethod
, or automatically invoked rename onnewMethod
(which is what TypeScript does today), or - provide edits including snippet syntax.I can't find any way to currently do this. If the solution is to use a custom command, then I think this comes back to #642, where we can't tell if the client has it implemented.
@dbaeumer is there something I've overlooked - can we already do this today?
The text was updated successfully, but these errors were encountered: