Skip to content

Commit

Permalink
house clean, and use a deep reset of config; diagnostic trigger will …
Browse files Browse the repository at this point in the history
…be depends on diagnostic.update_in_insert
  • Loading branch information
ray-x committed May 22, 2024
1 parent e80846d commit 294d65c
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 35 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -782,12 +782,12 @@ 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
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
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
33 changes: 23 additions & 10 deletions lua/go.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
10 changes: 7 additions & 3 deletions lua/go/gopls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions lua/go/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 8 additions & 6 deletions lua/go/null_ls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
24 changes: 22 additions & 2 deletions playground/sampleApp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 294d65c

Please sign in to comment.