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

fixes #1105 : check for LSP progress, report working/linted file #1144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lafleurdeboum
Copy link

This small PR adds a handler to vim.lsp.handlers, checking if a language server reported that it was working on the current file and is not done yet. If it's the case, a "Working" icon is appended to the diagnostics component. Then when the language server reports that it's done working, if no error, warning, hint or info is declared, the "Working" icon is replaced by an "OK" icon.

This behaviour is useful when working on heavyweight linters, like rust-analyzer, that can take a minute to lint a project. The user gets the bare useful information with very little overhead. Unfortunately, several language servers don't report their progress (thinking about vim-language-server and bash-language-server. In this case, I found no way to make sure that a linting is currently running. Indeed, the vim.diagnostic API lets any process diagnose what they please. My intention is to ask vim-language-server and bash-language-server to declare a minimal work progress, since this behaviour seems quite standard.

I tested my PR against luacheck and it succeeded. I also tried to respect the project's customs (like indentation). Any comment greatly appreciated !

vim.lsp.handlers["$/progress"] = function(_, result)
self.lsp_started = true
if result.value.kind == "end" then
self.lsp_working = false
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gopls will emit a "begin" event when encountering an issue loading workspace, with no followup "end". In order to recover from bad actors, LSP progress handlers need to implement a debounced clear routine.

@lafleurdeboum
Copy link
Author

lafleurdeboum commented Nov 18, 2023 via email

@Slotos
Copy link

Slotos commented Nov 18, 2023

In my case it was enough to initiate an edit on a new go buffer in a directory with no go.mod in its hierarchy with gopls set up. So something like:

:=require('lspconfig').gopls.setup{}
:new test.go

I was implementing a primitive progress reporter, and saw gopls message getting stuck in a routine very similar to the one I commented on. When logging progress messages, I saw “begin”, “end”, and “begin” messages arrive in that order.

@lafleurdeboum
Copy link
Author

lafleurdeboum commented Nov 18, 2023 via email

@lafleurdeboum
Copy link
Author

lafleurdeboum commented Nov 18, 2023 via email

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

Successfully merging this pull request may close these issues.

None yet

2 participants