autozimu / LanguageClient-neovim

Language Server Protocol (LSP) support for vim and neovim.
MIT License
3.55k stars 273 forks source link

Add parameter to silence explainErrorAtPoint #1143

Closed martskins closed 3 years ago

martskins commented 3 years ago

This PR adds an optional parameter to be sent to explainErrorAtPoint so that the no diagnostics found error can be silenced. The function can be called as it was called normally, but it also now can be called like this:

:call LanguageClient#explainErrorAtPoint({'silent': v:true})

This is useful for users that want to set up this call on CursorHold without having an error displayed every time they stop on a position with no diagnostic in it. The relevant autocmd config for that would then look like this:

autocmd CursorHold * call LanguageClient#explainErrorAtPoint({'silent': v:true})

Note that I had to move things around a little so that the cursor would not move inside the window after a second CursorHold with the hover open. And also to prevent moving into the window by calling LanguageClient#textDocument_hover(). There is an interaction between those two that is not really ideal, but I think it makes sense in any case, and that is that if you call hover on a position where you have an error (meaning, the window for explainErrorAtPoint is being display), the documentation window will basically show and immediately hide, because the CursorHold fires the explainErrorAtPoint again. I think we can probably do something about this, but I suppose the wanted behaviour is a little user-specific, so I'm leaving it as is because it's at least somewhat useful like this (you at least get a peek at the documentation).

Closes #884