erlang_ls icon indicating copy to clipboard operation
erlang_ls copied to clipboard

[Wrangler] Extract function does not work in Sublime LSP

Open eproxus opened this issue 3 years ago • 3 comments

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 avatar Aug 22 '22 14:08 eproxus

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?)

eproxus avatar Aug 22 '22 14:08 eproxus

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.

robertoaloi avatar Aug 23 '22 13:08 robertoaloi

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

eproxus avatar Aug 25 '22 09:08 eproxus