Skip to content

Commit

Permalink
Align with neovim diagnostic setup and deprecate settings. Update rea…
Browse files Browse the repository at this point in the history
…dme.
  • Loading branch information
ray-x committed Sep 22, 2023
1 parent 5e9e083 commit 0b04e4b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 27 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# go.nvim
#a go.nvim

A modern go neovim plugin based on treesitter, nvim-lsp and dap debugger. It is written in Lua and async as much as possible.
PR & Suggestions welcome.
Expand Down Expand Up @@ -772,12 +772,14 @@ require('go').setup({
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "<space>F", "<cmd>lua vim.lsp.buf.formatting()<CR>", {noremap=true, silent=true})
-- end
-- to setup a table of codelens
lsp_diag_hdlr = true, -- hook lsp diag handler
lsp_diag_underline = true,
-- virtual text setup
lsp_diag_virtual_text = { space = 0, prefix = '' },
lsp_diag_signs = true,
lsp_diag_update_in_insert = false,
diagnostic = { -- set diagnostic to false to disable vim.diagnostic setup
hdlr = true, -- hook lsp diag handler
underline = true,
-- virtual text setup
virtual_text = { space = 0, prefix = '' },
signs = true,
update_in_insert = false,
},
lsp_document_formatting = true,
-- set to true: use gopls to format
-- false if you want to use other formatter tool(e.g. efm, nulls)
Expand Down
44 changes: 36 additions & 8 deletions lua/go.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,19 @@ _GO_NVIM_CFG = {
-- it can be a nulls source name e.g. `golines` or a nulls query table
lsp_keymaps = true, -- true: use default keymaps defined in go/lsp.lua
lsp_codelens = true,
lsp_diag_hdlr = true, -- hook lsp diag handler
lsp_diag_underline = true,
-- virtual text setup
lsp_diag_virtual_text = { space = 0, prefix = '' },
lsp_diag_signs = true,
diagnostic = { -- set diagnostic to false to disable diagnostic
hdlr = true, -- hook diagnostic handler
underline = true,
-- virtual text setup
virtual_text = { space = 0, prefix = '' },
signs = true,
},
-- deprecated setups
-- lsp_diag_hdlr = true, -- hook lsp diag handler
-- lsp_diag_underline = true,
-- -- virtual text setup
-- lsp_diag_virtual_text = { space = 0, prefix = '■' },
-- lsp_diag_signs = true,
lsp_inlay_hints = {
enable = true,

Expand Down Expand Up @@ -141,6 +149,18 @@ function go.setup(cfg)
if cfg.max_len then
vim.notify('go.nvim max_len renamed to max_line_len', vim.log.levels.WARN)
end
if cfg.lsp_diag_hdlr ~= nil then
vim.notify('go.nvim lsp_diag_hdlr deprecated, use diagnostic.hdlr', vim.log.levels.WARN)
end
if cfg.lsp_diag_underline ~= nil then
vim.notify('go.nvim lsp_diag_underline deprecated, use diagnostic.underline', vim.log.levels.WARN)
end
if cfg.lsp_diag_virtual_text ~= nil then
vim.notify('go.nvim lsp_diag_virtual_text deprecated, use diagnostic.virtual_text', vim.log.levels.WARN)
end
if cfg.lsp_diag_signs ~= nil then
vim.notify('go.nvim lsp_diag_signs deprecated, use diagnostic.signs', vim.log.levels.WARN)
end
if cfg.disable_defaults then
for k, _ in pairs(_GO_NVIM_CFG) do
if type(cfg[k]) == 'boolean' then
Expand All @@ -165,13 +185,21 @@ function go.setup(cfg)

if _GO_NVIM_CFG.lsp_cfg then
require('go.lsp').setup()
if _GO_NVIM_CFG.lsp_diag_hdlr then
require('go.lsp_diag')
end
elseif not _GO_NVIM_CFG.lsp_cfg and _GO_NVIM_CFG.lsp_on_attach then
vim.notify('lsp_on_attach ignored, because lsp_cfg is false', vim.log.levels.WARN)
end

if _GO_NVIM_CFG.diagnostic then
vim.diagnostic.config({
underline = _GO_NVIM_CFG.diagnostic.underline,
virtual_text = _GO_NVIM_CFG.diagnostic.virtual_text,
signs = _GO_NVIM_CFG.diagnostic.signs,
update_in_insert = _GO_NVIM_CFG.diagnostic.update_in_insert,
})
if _GO_NVIM_CFG.diagnostic.hdlr then
require('go.lsp_diag')
end
end
vim.defer_fn(function()
require('go.coverage').setup()
if _GO_NVIM_CFG.lsp_codelens then
Expand Down
20 changes: 8 additions & 12 deletions lua/go/lsp_diag.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
-- New signature on_publish_diagnostics({_}, {result}, {ctx}, {config})
debug = debug or nil
local vfn = vim.fn

local function hdlr(result)
if result and result.diagnostics then
local item_list = {}
Expand Down Expand Up @@ -38,14 +37,11 @@ local diag_hdlr_0_6 = function(err, result, ctx, config)
hdlr(result)
end

vim.lsp.handlers['textDocument/publishDiagnostics'] = vim.lsp.with(diag_hdlr_0_6, {
-- Enable underline, use default values
underline = _GO_NVIM_CFG.lsp_diag_underline,
-- Enable virtual text, override spacing to 0
virtual_text = _GO_NVIM_CFG.lsp_diag_virtual_text,
-- Use a function to dynamically turn signs off
-- and on, using buffer local variables
signs = _GO_NVIM_CFG.lsp_diag_signs,
-- Disable a feature
update_in_insert = _GO_NVIM_CFG.lsp_diag_update_in_insert,
})
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
diag_hdlr_0_6, {
underline = _GO_NVIM_CFG.diagnostic.underline,
virtual_text = _GO_NVIM_CFG.diagnostic.virtual_text,
signs = _GO_NVIM_CFG.diagnostic.signs,
update_in_insert = _GO_NVIM_CFG.diagnostic.update_in_insert,
}
)

0 comments on commit 0b04e4b

Please sign in to comment.