gopls notification and doc updates

pull/429/merge
ray-x 2 months ago
parent 9dfc750472
commit c7b4b1ae10

@ -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:

@ -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

@ -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" }
},
]]
--

Loading…
Cancel
Save