You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to figure out the best way to set up format on save for all filetypes which have a language server. At first, I thought I could just do this, and at worst, I'd maybe have to silence warnings/errors if no language server is running:
As it turns out, this does work for filetypes which have a language server, but hangs indefinitely on save for filetypes which don't, waiting forever in this loop in LanguageClient_runSync (presumably because the Rust bridge isn't there to respond?):
So I searched the issue tracker and found out about LanguageClient#isAlive, which I thought I could use at runtime to determine whether LanguageClient#textDocument_formatting_sync is safe to run (presumably, if LanguageClient#isAlive, then the call won't hang). However, as per the suggestion in the linked comment, I would need to use LanguageClient_runSync to run LanguageClient#isAlive synchronously, which means we get stuck in the aforementioned while loop once again.
So I ended up devising with the following solution, which seems to be working so far:
In other words: install a FileType autocommand, which sets up a per-buffer autocommand to run LSP formatting for each buffer belonging to one of the supported filetypes. To make matters worse, the whole thing has to be wrapped in an execute, because we need determine the list of supported filetypes based on the keys of g:LanguageClient_serverCommands.
This feels somewhat baroque and complicated, so I was wondering whether I've missed a more obvious, cleaner way, that someone better acquainted with the internals of the project might recommend over this? :)
The text was updated successfully, but these errors were encountered:
This still has the problem that if the language server does not have formatting capabilities you will probably face an error (or maybe even end up in the loop again, not sure).
Thanks very much for the alternative suggestion! I'm currently using/evaluating the builtin LSP in Neovim nightly, so I don't have a pressing need for this anymore, but it's definitely useful to have it here :)
I'm trying to figure out the best way to set up format on save for all filetypes which have a language server. At first, I thought I could just do this, and at worst, I'd maybe have to silence warnings/errors if no language server is running:
As it turns out, this does work for filetypes which have a language server, but hangs indefinitely on save for filetypes which don't, waiting forever in this loop in
LanguageClient_runSync
(presumably because the Rust bridge isn't there to respond?):LanguageClient-neovim/autoload/LanguageClient.vim
Lines 1024 to 1026 in fb02afe
So I searched the issue tracker and found out about
LanguageClient#isAlive
, which I thought I could use at runtime to determine whetherLanguageClient#textDocument_formatting_sync
is safe to run (presumably, ifLanguageClient#isAlive
, then the call won't hang). However, as per the suggestion in the linked comment, I would need to useLanguageClient_runSync
to runLanguageClient#isAlive
synchronously, which means we get stuck in the aforementioned while loop once again.So I ended up devising with the following solution, which seems to be working so far:
In other words: install a
FileType
autocommand, which sets up a per-buffer autocommand to run LSP formatting for each buffer belonging to one of the supported filetypes. To make matters worse, the whole thing has to be wrapped in anexecute
, because we need determine the list of supported filetypes based on the keys ofg:LanguageClient_serverCommands
.This feels somewhat baroque and complicated, so I was wondering whether I've missed a more obvious, cleaner way, that someone better acquainted with the internals of the project might recommend over this? :)
The text was updated successfully, but these errors were encountered: