5

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/Extract 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. Commented Mar 15, 2023 at 14:54
  • @filbranden thnx for the suggestion, but still the same Commented Mar 15, 2023 at 20:05
  • 1
    @filbranden on regressing to nvim 0.8 and implementing your suggestion, it worked Commented Mar 17, 2023 at 18:16

1 Answer 1

0

Try this: vnoremap <leader>la :lua vim.lsp.buf.code_action()<CR>

Reference: https://github.com/neovim/neovim/pull/19551

1
  • You probably meant :xnoremap unless NeoVim removed that Commented Apr 28, 2023 at 21:27

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.