Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default gopls settings prevents diagnostics from being refreshed on InsertLeave #515

Open
antoineco opened this issue Oct 14, 2024 · 3 comments

Comments

@antoineco
Copy link
Contributor

Without go.nvim and using gopls defaults, LSP diagnostics are refreshed on InsertLeave (ref. :h vim.diagnostic.Opts).

When using go.nvim with either lsp_cfg = true or lsp_cfg = { settigns = { gopls = { ... } } }, LSP diagnostics disappear upon entering Insert mode, and are only shown again upon saving the buffer.

@antoineco
Copy link
Contributor Author

I found the culprit.

When update_in_insert is false (the default in both Neovim and go.nvim), diagTrigger defaults to Save:

go.nvim/lua/go/gopls.lua

Lines 312 to 315 in fb612d1

local update_in_insert = _GO_NVIM_CFG.diagnostic and _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'

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

antoineco added a commit to antoineco/dotfiles that referenced this issue Oct 14, 2024
go.nvim sets the trigger to 'Save' by default due to some seemingly
broken logic[1]. This prevents diagnostics from being refreshed on
InsertLeave as intended by Neovim (:h vim.diagnostic.Opts).

[1]: ray-x/go.nvim#515
@ray-x
Copy link
Owner

ray-x commented Oct 16, 2024

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.

@antoineco
Copy link
Contributor Author

antoineco commented Oct 17, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants