From c7b4b1ae106659cacde40e02569a78d63c7e6e54 Mon Sep 17 00:00:00 2001 From: ray-x Date: Wed, 13 Mar 2024 12:10:08 +1100 Subject: [PATCH] gopls notification and doc updates --- README.md | 15 ++++++++++++++- lua/go/gopls.lua | 5 +++-- lua/go/lsp.lua | 15 --------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 437d8e7..9cafb44 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ The plugin covers most features required for a gopher. [aurora](https://github.com/ray-x/aurora), [starry.nvim](https://github.com/ray-x/starry.nvim). Also, there are quite a few listed in [awesome-neovim](https://github.com/rockerBOO/awesome-neovim) - All the GoToXxx (E.g reference, implementation, definition, goto doc, peek code/doc etc) You need lspconfig setup. There are lots of posts on how to set it up. You can also check my [navigator](https://github.com/ray-x/navigator.lua) gopls setup [lspconfig.lua](https://github.com/ray-x/navigator.lua/blob/master/lua/navigator/lspclient/clients.lua) -- gopls commands: e.g. fillstruct, organize imports, list modules, list packages, gc_details, generate, etc. +- gopls commands: e.g. fillstruct, organize imports, list modules, list packages, gc_details, generate, change +signature, etc. - Runtime lint/vet/compile: Supported by LSP (once you set up your LSP client), GoLint with golangci-lint also supported - Build/Make/Test: Go.nvim provides support for these by an async job wrapper. - Test coverage: run test coverage and show coverage sign and function metrics @@ -755,6 +756,18 @@ Sample vimrc for DAP Check [commands.lua](https://github.com/ray-x/go.nvim/blob/master/lua/go/commands.lua) on all the commands provided +## Gopls commands + +Check [gopls.lua](https://github.com/ray-x/go.nvim/blob/master/lua/go/gopls.lua) on all the gopls commands provided, +some of them are not exposed to user, but you can still use it in your lua setup. + +- list_imports +- add_import +- list_packages +- tidy +- change_signature +- ... + ## configuration Configure from lua suggested, The default setup: diff --git a/lua/go/gopls.lua b/lua/go/gopls.lua index 306e31c..6a48cbe 100644 --- a/lua/go/gopls.lua +++ b/lua/go/gopls.lua @@ -5,7 +5,6 @@ local vfn = vim.fn local M = {} local cmds = {} -- https://go.googlesource.com/tools/+/refs/heads/master/gopls/doc/commands.md --- "executeCommandProvider":{"commands":["gopls.add_dependency","gopls.add_import","gopls.apply_fix","gopls.check_upgrades","gopls.gc_details","gopls.generate","gopls.generate_gopls_mod","gopls.go_get_package","gopls.list_known_packages","gopls.regenerate_cgo","gopls.remove_dependency","gopls.run_tests","gopls.start_debugging","gopls.test","gopls.tidy","gopls.toggle_gc_details","gopls.update_go_sum","gopls.upgrade_dependency","gopls.vendor","gopls.workspace_metadata"]} local gopls_cmds = { 'gopls.add_dependency', @@ -60,6 +59,7 @@ local function check_for_error(msg) for k, v in pairs(msg[1]) do if k == 'error' then log('LSP error:', v.message) + vim.notify(vim.inspect(v.message), vim.log.levels.INFO) break end end @@ -86,6 +86,7 @@ local function apply_changes(cmd, args) arguments = args, }, function(_err, changes) if _err then + vim.notify(vim.inspect(_err), vim.log.levels.INFO) log('error', _err) end if not changes or not changes.documentChanges then @@ -105,7 +106,7 @@ for _, gopls_cmd in ipairs(gopls_cmds) do local arguments = { { URI = uri } } local ft = vim.bo.filetype - if ft == 'gomod' or ft == 'gosum' then + if ft == 'gomod' or ft == 'gosum' or gopls_cmd_name == 'tidy' or gopls_cmd_name == 'update_go_sum' then arguments[1].URIs = { uri } arguments[1].URI = nil end diff --git a/lua/go/lsp.lua b/lua/go/lsp.lua index a94b68a..8bdb663 100644 --- a/lua/go/lsp.lua +++ b/lua/go/lsp.lua @@ -571,18 +571,3 @@ function M.watchFileChanged(fname, params) end return M - ---[[ -as of 2024-03-01 - codeActionProvider = { - codeActionKinds = { "quickfix", "refactor.extract", "refactor.inline", "refactor.rewrite", "source.fixAll", "source.organizeImports" }, - resolveProvider = true - }, - executeCommandProvider = { - commands = { "gopls.add_dependency", "gopls.add_import", "gopls.add_telemetry_counters", "gopls.apply_fix", "gopls.change_signature", "gopls.check_upgrades", "gopls.diagnose_files", "gopls.edit_go_directive", "gopls.fetch_vulncheck_result", "gopls. -gc_details", "gopls.generate", "gopls.go_get_package", "gopls.list_imports", "gopls.list_known_packages", "gopls.maybe_prompt_for_telemetry", "gopls.mem_stats", "gopls.regenerate_cgo", "gopls.remove_dependency", "gopls.reset_go_mod_diagnostics", "gopls.run -_go_work_command", "gopls.run_govulncheck", "gopls.run_tests", "gopls.start_debugging", "gopls.start_profile", "gopls.stop_profile", "gopls.test", "gopls.tidy", "gopls.toggle_gc_details", "gopls.update_go_sum", "gopls.upgrade_dependency", "gopls.vendor", " -gopls.views", "gopls.workspace_stats" } - }, -]] ---