setup option to disable gopls doc format

pull/77/head
ray-x 2 years ago
parent 22fe0379de
commit cd395e96fb

@ -443,6 +443,9 @@ require('go').setup({
-- if lsp_on_attach is a function: use this function as on_attach function for gopls
lsp_codelens = true, -- set to false to disable codelens, true by default
lsp_diag_hdlr = true, -- hook lsp diag handler
lsp_document_formatting = true,
-- set to true: use gopls to format
-- false if you want to use other formatter tool(e.g. efm, nulls)
gopls_cmd = nil, -- if you need to specify gopls path and cmd, e.g {"/home/user/lsp/gopls", "-logfile","/var/log/gopls.log" }
gopls_remote_auto = true, -- add -remote=auto to gopls
dap_debug = true, -- set to false to disable dap

@ -23,6 +23,12 @@ _GO_NVIM_CFG = {
-- when lsp_cfg is true
-- if lsp_on_attach is a function: use this function as on_attach function for gopls,
-- when lsp_cfg is true
lsp_format_on_save = 1,
lsp_document_formatting = true,
-- set to true: use gopls to format
-- false if you want to use other formatter tool(e.g. efm, nulls)
lsp_codelens = true,
lsp_diag_hdlr = true, -- hook lsp diag handler
gopls_cmd = nil, --- you can provide gopls path and cmd if it not in PATH, e.g. cmd = { "/home/ray/.local/nvim/data/lspinstall/go/gopls" }

@ -1,4 +1,4 @@
local utils = require 'go.utils'
local utils = require("go.utils")
local log = utils.log
local M = {}
@ -6,18 +6,33 @@ local M = {}
-- "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", "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"
"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 function check_for_error(msg)
if msg ~= nil and type(msg[1]) == 'table' then
if msg ~= nil and type(msg[1]) == "table" then
for k, v in pairs(msg[1]) do
if k == 'error' then
log.error('LSP', v.message)
if k == "error" then
log.error("LSP", v.message)
break
end
end
@ -25,17 +40,17 @@ local function check_for_error(msg)
end
for _, value in ipairs(gopls_cmds) do
local fname = string.sub(value, #'gopls.' + 1)
local fname = string.sub(value, #"gopls." + 1)
M[fname] = function(arg)
log(fname)
local b = vim.api.nvim_get_current_buf()
local uri = vim.uri_from_bufnr(b)
local arguments = {{URI = uri, URIs = {uri}}}
arguments = vim.tbl_extend('keep', arguments, arg or {})
local arguments = { { URI = uri, URIs = { uri } } }
arguments = vim.tbl_extend("keep", arguments, arg or {})
local resp = vim.lsp.buf_request_sync(b, 'workspace/executeCommand', {
local resp = vim.lsp.buf_request_sync(b, "workspace/executeCommand", {
command = value,
arguments = arguments
arguments = arguments,
})
check_for_error(resp)
log(resp)
@ -57,5 +72,63 @@ M.list_pkgs = function()
end
-- check_for_upgrades({Modules = {'package'}})
function M.version()
return vim.fn.system("gopls version"):match("%s+v([%d%.]+)%s+")
end
local setups = {
-- capabilities = cap,
filetypes = { "go", "gomod", "gohtmltmpl", "gotexttmpl" },
message_level = vim.lsp.protocol.MessageType.Error,
cmd = {
"gopls", -- share the gopls instance if there is one already
"-remote.debug=:0",
},
root_dir = function(fname)
local has_lsp, lspconfig = pcall(require, "lspconfig")
if has_lsp then
local util = lspconfig.util
return util.root_pattern("go.mod", ".git")(fname) or util.path.dirname(fname)
end
end,
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
settings = {
gopls = {
-- more settings: https://github.com/golang/tools/blob/master/gopls/doc/settings.md
-- flags = {allow_incremental_sync = true, debounce_text_changes = 500},
-- not supported
analyses = { unusedparams = true, unreachable = false },
codelenses = {
generate = true, -- show the `go generate` lens.
gc_details = true, -- // Show a code lens toggling the display of gc's choices.
test = true,
tidy = true,
},
usePlaceholders = true,
completeUnimported = true,
staticcheck = true,
matcher = "Fuzzy",
diagnosticsDelay = "500ms",
experimentalWatchedFileDelay = "100ms",
symbolMatcher = "fuzzy",
["local"] = "",
gofumpt = false, -- true, -- turn on for new repos, gofmpt is good but also create code turmoils
buildFlags = { "-tags", "integration" },
-- buildFlags = {"-tags", "functional"}
},
},
}
M.setups = function()
local v = M.version()
if v > "0.7" then
setups.settings = vim.tbl_deep_extend("force", setups.settings, {
experimentalPostfixCompletions = true,
experimentalUseInvalidMetadata = true,
hoverKind = "Structured",
})
end
return setups
end
return M

@ -23,6 +23,9 @@ local on_attach = function(client, bufnr)
api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
local opts = { noremap = true, silent = true }
if _GO_NVIM_CFG.lsp_document_formatting == false then
client.resolved_capabilities.document_formatting = false
end
buf_set_keymap("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts)
buf_set_keymap("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)
@ -45,49 +48,7 @@ local on_attach = function(client, bufnr)
buf_set_keymap("n", "<space>ff", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
end
local gopls = {
-- capabilities = cap,
filetypes = { "go", "gomod", "gohtmltmpl", "gotexttmpl" },
message_level = vim.lsp.protocol.MessageType.Error,
cmd = {
"gopls", -- share the gopls instance if there is one already
"-remote.debug=:0",
},
root_dir = function(fname)
local has_lsp, lspconfig = pcall(require, "lspconfig")
if has_lsp then
local util = lspconfig.util
return util.root_pattern("go.mod", ".git")(fname) or util.path.dirname(fname)
end
end,
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
settings = {
gopls = {
-- more settings: https://github.com/golang/tools/blob/master/gopls/doc/settings.md
-- flags = {allow_incremental_sync = true, debounce_text_changes = 500},
-- not supported
analyses = { unusedparams = true, unreachable = false },
codelenses = {
generate = true, -- show the `go generate` lens.
gc_details = true, -- // Show a code lens toggling the display of gc's choices.
test = true,
tidy = true,
},
usePlaceholders = true,
completeUnimported = true,
staticcheck = true,
matcher = "Fuzzy",
-- experimentalDiagnosticsDelay = "500ms",
diagnosticsDelay = "500ms",
experimentalWatchedFileDelay = "100ms",
symbolMatcher = "fuzzy",
["local"] = "",
gofumpt = false, -- true, -- turn on for new repos, gofmpt is good but also create code turmoils
buildFlags = { "-tags", "integration" },
-- buildFlags = {"-tags", "functional"}
},
},
}
local gopls = require("go.gopls").setups()
local extend_config = function(opts)
opts = opts or {}
@ -145,7 +106,12 @@ end
function M.setup()
local gopls = M.config()
require("lspconfig").gopls.setup(gopls)
local lspconfig = utils.load_plugin("nvim-lspconfig", "lspconfig")
if lspconfig == nil then
vim.notify("failed to load lspconfig", vim.lsp.log_levels.WARN)
return
end
lspconfig.gopls.setup(gopls)
end
--[[

Loading…
Cancel
Save