2

In neovim 0.8, I had the following command mapped

vnoremap <leader>a :lua vim.lsp.buf.range_code_action()<cr>

which in visual mode, gave me options such as Wrap In Try-Catch/Extract Method etc.

Now in 0.9 range_code_action no longer exists and https://neovim.io/doc/user/lsp.html#vim.lsp.buf.code_action() says "range: (table|nil) Range for which code actions should be requested. If in visual mode this defaults to the active selection."

I've tried simply changing the mapping to lua vim.lsp.buf.range_code_action() but I'm just getting the basic code actions, not the various Wrap/Exract method etc.

I'm coding Dart.

Any ideas how I a get my range code actions back?

3
  • 1
    It's possible that it's not triggering the automatic handling of a range from Visual mode because when you use : you're actually switching to command-line mode. Try using <Cmd> to run the :lua command without switching to command-line mode from your mapping, such as vnoremap <leader>a <Cmd>lua vim.lsp.buf.code_action()<cr>. See :help <Cmd> for more details.
    – filbranden
    Mar 15 at 14:54
  • @filbranden thnx for the suggestion, but still the same
    – pinoyyid
    Mar 15 at 20:05
  • 1
    @filbranden on regressing to nvim 0.8 and implementing your suggestion, it worked
    – pinoyyid
    Mar 17 at 18:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.