-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[gopls] delay diagnostics or not run them in insert mode #127
Comments
sorry about the bug label, this is more of a question/documentation issue |
Ideally I would like an option to suspend all It's possible to mess around with a custom |
@urandom Would you show me a sample codes or project? |
@h-michael I've noticed it mostly happening when I start writing struct literals, like: the cursor position would be at: though it also sometimes occurs when i write if statements. |
@lithammer I would ignore the cost of the processing on the keypress if you're using an LSP at all on a battery and just disable it if that is a concern. There's no way to use an LSP without sending the textDocument updates, which, currently, send the whole text document due to a bug preventing incremental updates in the core LSP (but to be fair, a lot of LSP servers don't support incremental as well). So I'd say the cost of parsing the json is pretty insignificant compared to the cost of displaying virtual text and updating it etc, so a custom callback which returns early if you're in insert mode for the LSP server of your choice (or all of them) is a solid idea. If you want help with that, let me know and I can show an example, but it should be relatively easy (if you're not familiar with Lua, then it's still a pretty basic Lua task). |
This is not diagnostic information but gopls internal error message. |
@norcalli other lsp plugins for nvim supports it and the experience overall is so much better. Specially if you prefer to run your own diagnostic tools with neomake |
@dbarrosop |
You may disagree and it may or may not be feasible to disable diagnostics client side but it's certainly not nonsense. I'd rather run diagnostics/notify the server when I know I am done typing than having it tell me my syntax is incorrect as I type. I also don't think disabling the LSP is a suitable workaround to avoid battery drain due to excessive diagnostics. The LSP does way more things than just provide diagnostics. A better compromise might be to delay notifying the server as the original submitter suggested. Anyway, I really appreciate the work being done here and hence why I migrated from my previous plugin, to help out testing and provide feedback. |
Though this is contradictory. We don't notify the server to get diagnostics specifically, rather all functionality of the server requires frequent updates of buffer to function properly. Especially completion requires the latest text of the line being edited while insert mode is still in progress. Servers are suppose throttle reparsing etc themselves for a reasonable tradeoff between speedy diagnostics and CPU usage. Servers might have their specific options to configure, like clangd allows you to explicitly request or suppress reparsing (though the default works perfectly fine to me), perhaps gopls has something similar? |
I managed to scramble something like this together. Not sure it's the most idiomatic approach though. do
local default_callback = vim.lsp.callbacks["textDocument/publishDiagnostics"]
local err, method, params, client_id
vim.lsp.callbacks["textDocument/publishDiagnostics"] = function(...)
err, method, params, client_id = ...
if vim.api.nvim_get_mode().mode ~= "i" then
publish_diagnostics()
end
end
function publish_diagnostics()
default_callback(err, method, params, client_id)
end
end
local on_attach = function(_, bufnr)
vim.api.nvim_command [[autocmd InsertLeave <buffer> lua publish_diagnostics()]]
end
nvim_lsp.gopls.setup({on_attach=on_attach}) |
A response regarding this issue from the gopls maintainer: |
I have the same issue with GDScript and C++ ( @lithammer, your solution not worked for me :( |
The biggest problem with this issue is that nvim-lsp will display internal lsp server errors as blocking messages, thus interrupting typing. Having diagnostics on incomplete statements, while annoying, is not disruptive. |
@urandom Could you call I suspect the error message you get that interrupts typing isn't related to diagnostics at all, but rather is something sent to |
There's quite a log of output being generated: https://gist.github.com/urandom/53bccd1a28b0ef865fd82cad244b90af The output is for when i start typing to some point after the error is displayed. From what I can tell, the error is a result of a didChange message |
Well, my suspicion was almost right, it's
As a workaround you could set vim.lsp.callbacks["window/logMessage"] = function log_message(_, _, result, client_id)
local message_type = result.type
local message = result.message
local client = vim.lsp.get_client_by_id(client_id)
local client_name = client and client.name or string.format("id=%d", client_id)
if not client then
err_message("LSP[", client_name, "] client has shut down after sending the message")
end
local message_type_name = vim.lsp.protocol.MessageType[message_type]
vim.api.nvim_out_write(string.format("LSP[%s][%s] %s\n", client_name, message_type_name, message))
return result
end |
Fixes neovim/nvim-lspconfig#127 Same could also happen with haskell-ide-engine, where messages as follows were sent: ``` "window/showMessage" { client_id = 1, params = { message = '"cannot satisfy -package-id junittui-0.1.0.0-AmJpwWxXMEHEoylTJC167n\\n (use -v for more informatio n)"', type = 1 } } ```
It doesn't seem like the workaround is working. It is still sending in a trailing newline, so it will be displayed immediately in a blocking manner, from what I understand. EDIT: actually, the error is different. It's complaining that it doesn't know what this |
Can you change the 2 lines to:
I missed initially that |
With that change I'm no longer seeing the error. |
Fixes neovim/nvim-lspconfig#127 Same could also happen with haskell-ide-engine, where messages as follows were sent: ``` "window/showMessage" { client_id = 1, params = { message = '"cannot satisfy -package-id junittui-0.1.0.0-AmJpwWxXMEHEoylTJC167n\\n (use -v for more informatio n)"', type = 1 } } ``` (cherry picked from commit ae4002a)
…age' notification related with neovim#127
…age' notification related with neovim#127
…age' notification related with neovim#127
@lithammer, made your solution works for me by changing this line: if vim.api.nvim_get_mode().mode ~= "i" then into this: if vim.api.nvim_get_mode().mode ~= "i" and vim.api.nvim_get_mode().mode ~= "ic" then Thank you! Would be nice to see such option built-in. |
@urandom Would you try this branch? neovim/neovim#11942 |
Add None because the user has no way to hide logMessage and showMessage. ref: neovim#127
Would that be with or without the other fix? |
Yes. |
Yes is definitely not an appropriate answer for that question ;) |
An initial test (overriding the previous fix) doesn't show any errors. I'll keep using it throughout the day to see if anything turns up |
@urandom |
What should I add to my configuration if I want to hide all diagnostics? I'm having the same issue where clangd is warning me about syntax errors on every character typed. |
To answer my own question, setting |
That's actually not a bad way to do it. Guess we can mention it in the docs. Alternatively use can set If errors are being printed a lot that's a different problem... |
@urandom Is this an issue anymore? see You should be able to add :lua << EOF
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
-- delay update diagnostics
update_in_insert = false,
}
)
EOF To get what you want. |
@mjlbach |
it was so simple. wow |
Thanks very much |
Is there any way to force a particular lsp server to delay its diagnostics, or not run them during insert mode?
gopls is tends to be quite chatty when i'm writing and i see a lot of temporary diagnostics virtual texts. Worse yet, at some point in time, the following messages (in a different buffer) start being printed out, causing pauses in the ui:
LSP[gopls] 2020/02/17 09:01:01 failed to fix AST: unable to parse defer or go from *ast.BadStmt: no defer or go statement found
The text was updated successfully, but these errors were encountered: