From 294d65c93514f14fbbe8af0545ab8918d939acdb Mon Sep 17 00:00:00 2001 From: ray-x Date: Wed, 22 May 2024 11:27:16 +1000 Subject: [PATCH] house clean, and use a deep reset of config; diagnostic trigger will be depends on diagnostic.update_in_insert --- README.md | 17 ++++++++--------- lua/go.lua | 33 +++++++++++++++++++++++---------- lua/go/gopls.lua | 10 +++++++--- lua/go/lsp.lua | 9 ++++----- lua/go/null_ls.lua | 14 ++++++++------ playground/sampleApp/main.go | 24 ++++++++++++++++++++++-- 6 files changed, 72 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 2cc6b87..029f018 100644 --- a/README.md +++ b/README.md @@ -753,8 +753,8 @@ Configure from lua suggested, The default setup: ```lua require('go').setup({ - disable_defaults = false, -- true|false when true set false to all boolean settings and replace all table - -- settings with {} + disable_defaults = false, -- true|false when true set false to all boolean settings and replace all tables + -- settings with {}; user need to setup ALL the settings go='go', -- go command, can be go[default] or go1.18beta1 goimports ='gopls', -- goimports command, can be gopls[default] or either goimports or golines if need to split long lines gofmt = 'gopls', -- gofmt through gopls: alternative is gofumpt, goimports, golines, gofmt, etc @@ -782,12 +782,12 @@ require('go').setup({ -- vim.api.nvim_buf_set_keymap(bufnr, "n", "F", "lua vim.lsp.buf.formatting()", {noremap=true, silent=true}) -- end -- to setup a table of codelens - diagnostic = { -- set diagnostic to false to disable vim.diagnostic setup + diagnostic = { -- set diagnostic to false to disable vim.diagnostic.config setup, + -- true: default nvim setup hdlr = false, -- hook lsp diag handler and send diag to quickfix underline = true, - -- virtual text setup - virtual_text = { spacing = 0, prefix = '■' }, - signs = true, + virtual_text = { spacing = 2, prefix = '' }, -- virtual text setup + signs = {'', '', '', ''}, -- set to true to use default signs, an array of 4 to specify custom signs update_in_insert = false, }, -- if you need to setup your ui for input and select, you can do it here @@ -799,7 +799,7 @@ require('go').setup({ lsp_inlay_hints = { enable = true, -- hint style, set to 'eol' for end-of-line hints, 'inlay' for inline hints - -- inlay only avalible for 0.10.x + -- inlay only available for 0.10.x style = 'inlay', -- Note: following setup only works for style = 'eol', you do not need to set it for 'inlay' -- Only show inlay hints for the current line @@ -818,7 +818,7 @@ require('go').setup({ show_parameter_hints = true, -- prefix for all the other hints (type, chaining) other_hints_prefix = "=> ", - -- whether to align to the lenght of the longest line in the file + -- whether to align to the length of the longest line in the file max_len_align = false, -- padding from the left if max_len_align is true max_len_align_padding = 1, @@ -885,7 +885,6 @@ setup. You can check the [youtube video here](https://www.youtube.com/watch?v=Xr ```lua -- .gonvim/init.lua project config -vim.g.null_ls_disable = true return { go = "go", -- set to go1.18beta1 if necessary diff --git a/lua/go.lua b/lua/go.lua index 2c00803..73fbcc0 100644 --- a/lua/go.lua +++ b/lua/go.lua @@ -5,7 +5,7 @@ local vfn = vim.fn -- Keep this in sync with README.md -- Keep this in sync with doc/go.txt _GO_NVIM_CFG = { - disable_defaults = false, -- either true when true disable all default settings + disable_defaults = false, -- true|false when true disable all default settings, user need to set all settings go = 'go', -- set to go1.18beta1 if necessary goimports = 'gopls', -- if set to 'gopls' will use gopls format, also goimports fillstruct = 'gopls', @@ -54,7 +54,7 @@ _GO_NVIM_CFG = { -- virtual text setup virtual_text = { spacing = 0, prefix = '■' }, update_in_insert = false, - signs = true, + signs = true, -- use a table to configure the signs }, go_input = function() if require('go.utils').load_plugin('guihua.lua', 'guihua.gui') then @@ -171,6 +171,26 @@ _GO_NVIM_CFG = { -- TODO: nvim_{add,del}_user_command https://github.com/neovim/neovim/pull/16752 +local function reset_tbl(tbl) + for k, _ in pairs(tbl) do + if type(tbl[k]) == 'table' then + if vim.islist(tbl[k]) then + tbl[k] = {} + else + reset_tbl(tbl[k]) + end + elseif type(tbl[k]) == 'string' then + tbl[k] = '' + elseif type(tbl[k]) == 'number' then + tbl[k] = 0 + elseif type(tbl[k]) == 'boolean' then + tbl[k] = false + else + tbl[k] = nil + end + end +end + function go.setup(cfg) if vim.fn.has('nvim-0.9') == 0 then vim.notify('go.nvim master branch requires nvim 0.9', vim.log.levels.WARN) @@ -199,14 +219,7 @@ function go.setup(cfg) 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 - cfg[k] = false - end - if type(_GO_NVIM_CFG[k]) == 'table' then - _GO_NVIM_CFG[k] = {} - end - end + reset_tbl(_GO_NVIM_CFG) end _GO_NVIM_CFG = vim.tbl_deep_extend('force', _GO_NVIM_CFG, cfg) diff --git a/lua/go/gopls.lua b/lua/go/gopls.lua index 316a100..4bdf23a 100644 --- a/lua/go/gopls.lua +++ b/lua/go/gopls.lua @@ -68,7 +68,7 @@ end local function apply_changes(cmd, args) local bufnr = vim.api.nvim_get_current_buf() - local clients = vim.lsp.buf_get_clients() + local clients = vim.lsp.get_clients({ bufnr = bufnr }) local gopls for _, c in ipairs(clients) do if c.name == 'gopls' then @@ -288,6 +288,9 @@ end local range_format = 'textDocument/rangeFormatting' local formatting = 'textDocument/formatting' M.setups = function() + local update_in_insert = _GO_NVIM_CFG.diagnostic.update_in_insert or false + local diagTrigger = update_in_insert and 'Edit' or 'Save' + local diagDelay = update_in_insert and '1s' or '250ms' local setups = { capabilities = { textDocument = { @@ -380,8 +383,9 @@ M.setups = function() completeUnimported = true, staticcheck = true, matcher = 'Fuzzy', - diagnosticsDelay = '500ms', - diagnosticsTrigger = 'Save', + -- check if diagnostic update_in_insert is set + diagnosticsDelay = diagDelay, + diagnosticsTrigger = diagTrigger, symbolMatcher = 'FastFuzzy', semanticTokens = true, noSemanticString = true, -- disable semantic string tokens so we can use treesitter highlight injection diff --git a/lua/go/lsp.lua b/lua/go/lsp.lua index 7c9032c..cf66bef 100644 --- a/lua/go/lsp.lua +++ b/lua/go/lsp.lua @@ -184,13 +184,12 @@ function M.client() name = 'gopls', } - local has0_11 = vim.fn.has('nvim-0.11') == 1 + local has0_10 = vim.fn.has('nvim-0.10') == 1 local clients - if has0_11 then - clients = vim.lsp.get_clients(f) or {} - else - clients = vim.lsp.get_active_clients(f) or {} + if not has0_10 then + vim.lsp.get_clients = vim.lsp.get_active_clients end + clients = vim.lsp.get_clients(f) or {} return clients[1] end diff --git a/lua/go/null_ls.lua b/lua/go/null_ls.lua index e91e927..7cc48b4 100644 --- a/lua/go/null_ls.lua +++ b/lua/go/null_ls.lua @@ -186,7 +186,7 @@ return { command = 'golangci-lint', to_stdin = true, from_stderr = false, - ignore_stderr = true, + -- ignore_stderr = true, async = true, format = 'raw', args = function() @@ -198,11 +198,13 @@ return { '--fix=false', '--out-format=json', } - for _, linter in ipairs(_GO_NVIM_CFG.null_ls.golangci_lint.disable or {}) do - table.insert(args, '--disable=' .. linter) - end - for _, linter in ipairs(_GO_NVIM_CFG.null_ls.golangci_lint.enable or {}) do - table.insert(args, '--enable=' .. linter) + if _GO_NVIM_CFG.null_ls.golangci_lint and vim.fn.empty(_GO_NVIM_CFG.null_ls.golangci_lint) == 0 then + for _, linter in ipairs(_GO_NVIM_CFG.null_ls.golangci_lint.disable or {}) do + table.insert(args, '--disable=' .. linter) + end + for _, linter in ipairs(_GO_NVIM_CFG.null_ls.golangci_lint.enable or {}) do + table.insert(args, '--enable=' .. linter) + end end args = vim.list_extend(args, { '--path-prefix', '$ROOT', '$FILENAME' }) return args diff --git a/playground/sampleApp/main.go b/playground/sampleApp/main.go index cfa39f1..a870f45 100644 --- a/playground/sampleApp/main.go +++ b/playground/sampleApp/main.go @@ -2,13 +2,33 @@ package main import ( "fmt" + "sampleApp/pkg" ) +type ioRImpl struct{} + +func (iorimpl *ioRImpl) Read(p []byte) (n int, err error) { + panic("not implemented") // TODO: Implement +} + func main() { i := 32 - j := 33 - result := pkg.FindAllSubStr("Find niddle in stack", "niddle") + j := 34 + result := pkg.FindAllSubStr("Find niddle in stack ssssssssssssssssss", "niddle") fmt.Println("result for find ninddle in stack: ") fmt.Println(result, i+j) + if err != nil { + log.Printf("error creating drawer: %v", err) + return nil + } + := drawer1.MeasureString("a").Ceil() + m, l := width/drawer + + // if the first text field is too long, wrap it int TWO lines + lines := WrapStringMultiLimits(txt1.Spans[0].Value, 2, []int{width, width - suffixLen}) + wrapped := slices.Clone(texts) + for i, w := range wrapped { + wrapped[i].Spans = slices.Clone(w.Spans) + } }