gopls version check issue #114

pull/119/head
ray-x 2 years ago
parent 88a846b3e1
commit 08b36ea9e6

@ -107,6 +107,11 @@ function M.version()
local cache_dir = vim.fn.stdpath("cache")
local path = string.format("%s%sversion.txt", cache_dir, utils.sep())
local gopls = _GO_NVIM_CFG.gopls_cmd or { "gopls" }
if vim.fn.executable(gopls) == 0 then
vim.notify("gopls not found", vim.log.levels.WARN)
return
end
vim.fn.jobstart({ gopls[1], "version" }, {
on_stdout = function(c, data, name)
local msg = ""
@ -213,6 +218,9 @@ local setups = {
M.setups = function()
local v = M.version()
if v == nil then
return
end
if v > "0.7" then
setups.settings = vim.tbl_deep_extend("force", setups.settings, {
experimentalPostfixCompletions = true,

@ -24,9 +24,11 @@ local on_attach = function(client, bufnr)
client.resolved_capabilities.document_formatting = false
end
codelens_enabled = client.resolved_capabilities["code_lens"]
if not codelens_enabled and _GO_NVIM_CFG.lsp_codelens then
vim.notify("please enable codelens in your gopls setup", vim.lsp.log_levels.WARN)
if _GO_NVIM_CFG.lsp_codelens then
codelens_enabled = client.resolved_capabilities["code_lens"]
if not codelens_enabled then
vim.notify("codelens not support by your gopls", vim.lsp.log_levels.WARN)
end
end
if _GO_NVIM_CFG.lsp_keymaps == true then
buf_set_keymap("n", "gD", ":lua vim.lsp.buf.formatting()<CR>", opts)
@ -59,8 +61,8 @@ local gopls = require("go.gopls").setups()
local extend_config = function(opts)
opts = opts or {}
if next(opts) == nil then
return
if next(opts) == nil or gopls == nil then
return gopls
end
for key, value in pairs(opts) do
if type(gopls[key]) == "table" then
@ -85,6 +87,9 @@ function M.client()
end
function M.config()
if gopls == nil then
return
end
gopls.on_attach = on_attach
if type(_GO_NVIM_CFG.lsp_on_attach) == "function" then
gopls.on_attach = _GO_NVIM_CFG.lsp_on_attach

Loading…
Cancel
Save