From 010d34ac20fe44b7a84ff6f9ba6d2245061d925a Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Thu, 30 Jan 2025 08:22:31 +0100 Subject: [PATCH] docs: code lens command for Neovim 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) ``` --- gopls/doc/codelenses.md | 1 + 1 file changed, 1 insertion(+) diff --git a/gopls/doc/codelenses.md b/gopls/doc/codelenses.md index d8aa8e1f479..2a54c691f59 100644 --- a/gopls/doc/codelenses.md +++ b/gopls/doc/codelenses.md @@ -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.