Open antoineco opened 3 weeks ago
I found the culprit.
When update_in_insert
is false
(the default in both Neovim and go.nvim), diagTrigger
defaults to Save
:
This differs from gopls
defaults, which have this set to Edit
: https://github.com/golang/tools/blob/v0.26.0/gopls/doc/settings.md#diagnosticstrigger-enum
There is a gap between nvim and gopls setup.
Edit
means update_in_insert=true
Save
does not mean LeaveInsert
/update_in_insert=false
, it should map to BufWritePost
So If you want to update the diagnostic in normal without save, you will need to set update_in_insert=true
, which will be very annoying.
I am open to suggestions.
I agree that update_in_insert
is annoying and not something I want to enable.
The reason why I think 'Save'
isn't great as a default trigger is that I often want to tackle multiple diagnostics inside a file (e.g. after a refactoring which broke multiple things). In that case, I'll typically jump to the next diagnostic, address it, and return to Normal mode. At that point, all my other diagnostics have now disappeared and I have to save the buffer to make them come back.
The alternative is to send diagnostics to the location list with vim.diagnostic.setloclist()
prior to performing the first edit, but this has the disadvantage of not carrying the context of a true LSP diagnostic at the marked location.
I got the behavior I wanted by setting diagnosticsTrigger
and diagnosticsDelay
to their default values (Edit, 1s) in lsp_cfg
.
Without
go.nvim
and usinggopls
defaults, LSP diagnostics are refreshed onInsertLeave
(ref.:h vim.diagnostic.Opts
).When using
go.nvim
with eitherlsp_cfg = true
orlsp_cfg = { settigns = { gopls = { ... } } }
, LSP diagnostics disappear upon entering Insert mode, and are only shown again upon saving the buffer.