gopls extract function not working in neovim lsp

574 Views Asked by At

I am using Neovim v0.8.3 on Ubuntu 22.04.2 LTS. I have configured neovim LSP using mason plugin to use the Go language server gopls v0.13.1.

I can confirm that the language server works for some functions. For example with my LSP config (see below), I can rename a variable in a Go file.

Also when I print the capabilities of the language server using the nvim ex command :lua print(vim.inspect(vim.lsp.buf_get_clients()[1].server_capabilities)), I get the following included in the output:

  callHierarchyProvider = true,                                                                                                                                                                                                                                                                             
  codeActionProvider = {
    codeActionKinds = { "quickfix", "refactor.extract", "refactor.rewrite", "source.fixAll", "source.organizeImports" }
  },
  codeLensProvider = vim.empty_dict(),
  completionProvider = {
    triggerCharacters = { "." }
  },

However, I cannot get any of the other refactor code actions to work. I would like to select a range and then extract a function or similar.

In my LSP config, I have the following mappings:

map('n', '<leader>ca', vim.lsp.buf.code_action)
map('v', '<leader>ca', vim.lsp.buf.range_code_action)
map('n', '<leader>rn', vim.lsp.buf.rename)

My leader is space, so if I select a range and then press <space>ca, I get the message:

No code actions available
0

There are 0 best solutions below