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

[Wrangler] Extract function does not work in Sublime LSP #1367

Open
eproxus opened this issue Aug 22, 2022 · 3 comments
Open

[Wrangler] Extract function does not work in Sublime LSP #1367

eproxus opened this issue Aug 22, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@eproxus
Copy link

eproxus commented Aug 22, 2022

Describe the bug
The code action "Wrangler: Extract function" does not work in Sublime Text with Sublime LSP.

To Reproduce

  1. Select some code.
  2. Run the code action "Wrangler: Extract function"

Expected behavior
Some UI to choose function name or a new function with a placeholder name.

Actual behavior
Nothing.

Log shows:

:: --> erlang-ls workspace/executeCommand(408): {'arguments': [{'user_input': {'text': 'The new function`s name', 'type': 'atom'}, 'uri': 'file:///path/to/foo.erl', 'range': {'end': {'line': 21, 'character': 7}, 'start': {'line': 17, 'character': 4}}}], 'command': '83683:wrangler-new-fun'}
erlang-ls: [2022-08-22T14:27:35.086885+02:00] [info] Executing command: new-fun [wls_execute_command_provider:execute_command/2 L24] <0.148.0>

erlang-ls: [2022-08-22T14:27:35.087288+02:00] [info] Using default variable name: NewFun [wls_code_action_new_fun:execute_command/1 L48] <0.148.0>

:: <<< erlang-ls 408: []
:: <-  erlang-ls window/logMessage: {'message': '[2022-08-22T14:27:35.086885+02:00] [info] Executing command: new-fun [wls_execute_command_provider:execute_command/2 L24] <0.148.0>\n', 'type': 4}
:: <-  erlang-ls window/logMessage: {'message': '[2022-08-22T14:27:35.087288+02:00] [info] Using default variable name: NewFun [wls_code_action_new_fun:execute_command/1 L48] <0.148.0>\n', 'type': 4}
:: <-  erlang-ls window/showMessage: {'message': 'Invalid function name! (Wrangler)', 'type': 2}

Context

  • erlang_ls version (tag/sha): 0.41.1
  • Editor used: Sublime Text 4 (build 4134)
  • LSP client used: Sublime LSP v1.17.0

Additional Notes

It could be that Sublime LSP doesn't support these kinds of interactions, but the log output indicates that the LS or the Wrangler integration somehow decided to to run the refactoring. Not sure where to start debug this, hence the opening of this issue 🙂

@eproxus eproxus added the bug Something isn't working label Aug 22, 2022
@eproxus
Copy link
Author

eproxus commented Aug 22, 2022

After some digging it seems the Wrangler code expects arguments of the form {'user_input': {'value': <TargetFilename>, ...}, ...} which it obviously doesn't get. How is this handled in other LSP implementations, e.g. VSCode? (I assume it works there?)

@robertoaloi
Copy link
Member

Hi @eproxus ! The LSP protocol (currently) only includes a UI component for the simple rename operation. In VS Code additional UI components are achieved by an extra "middleware". In other IDEs, Wrangler should default to a default name.
In this case, my wild guess is that these two lines have been copy-pasted from the Variable extraction:

https://github.com/RefactoringTools/wrangler/blob/d41835b64292ebb8371933d9302108c0a092927a/src/wls/wls_code_action_new_fun.erl#L48-L49

And the new name should start with a lowercase to be a valid function name.

@eproxus
Copy link
Author

eproxus commented Aug 25, 2022

I'm currently looking into making a Sublime LSP plugin for Erlang that would provide this middleware. I'll keep you posted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants