Skip to content

Commit

Permalink
docs: code lens command for Neovim
Browse files Browse the repository at this point in the history
This adds a lead on how to render code lenses inline, for gopls, in
Neovim.

A full example for Neovim v0.11.0:

```lua
local config = {
  cmd = { "gopls" },
  filetypes = { "go", "gomod", "gowork", "gosum" },
  root_markers = { "go.work", "go.mod", ".git" },
  on_attach = function(client, bufnr)
    if client.supports_method("textDocument/codeLens") then
        vim.lsp.codelens.refresh()
        vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold",
"InsertLeave" }, {
          buffer = bufnr,
          callback = vim.lsp.codelens.refresh,
        })
    end
  end,
  settings = {
    gopls = {
      -- https://github.com/golang/tools/blob/master/gopls
      buildFlags = { "-tags=wireinject,integration" },
      gofumpt = false,
    },
  },
}
vim.lsp.config["gopls"] = config
vim.lsp.enable("gopls", true)
```
  • Loading branch information
fredrikaverpil committed Jan 30, 2025
1 parent e426616 commit 2bf0b41
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions gopls/doc/codelenses.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Client support:
- **VS Code**: Code Lenses appear as small text links above a line of source code.
- **Emacs + eglot**: Not supported, but prototype exists at https://github.com/joaotavora/eglot/pull/71.
- **Vim + coc.nvim**: ??
- **Neovim**: Run `vim.lsp.codelens.refresh({ bufnr = 0 })` to refresh code lenses for current buffer. Run `vim.lsp.codelens.run()` to pick a lens. See `:h vim.lsp.codelens` for more details.
- **CLI**: `gopls codelens`. For example, `gopls codelens -exec file.go:123 "run test"` runs the test at the specified line.


Expand Down

0 comments on commit 2bf0b41

Please sign in to comment.