autozimu / LanguageClient-neovim

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

Do not send requests/notifications for buffers without a configured server command #1121

Closed martskins closed 3 years ago

martskins commented 3 years ago

This PR stops LCN from trying to communicate with a server for languages or from handling the events we track (such as CursorMoved for languages that don't have a configured server command.

I was a little dubious about setting autocmds inside a function like that, but it seems to work.

Fixes #984

YaLTeR commented 3 years ago

On min-vimrc this seems to fix the freezes indeed. On my particular setup there are still some freezes on network files, seems like they are coming from the airline languageclient extension, not sure who is to blame here:

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
  974   4.328220   0.029451  airline#extensions#languageclient#get()
  974   4.298768             <SNR>137_diagnostics_for_buffer()
  487   4.266051   0.005816  airline#extensions#languageclient#get_warning()
    5   0.674117   0.428210  <SNR>163_AutoUpdate()
    5   0.238006   0.237939  <SNR>163_IsValidFile()
  564   0.148016             <SNR>103_Highlight_Matching_Pair()
  487   0.120216   0.088048  airline#check_mode()
  487   0.110855   0.105453  WebDevIconsGetFileTypeSymbol()
  487   0.082357   0.066268  airline#extensions#whitespace#check()
  487   0.074958   0.014874  airline#extensions#tagbar#currenttag()
  487   0.073400   0.005415  airline#extensions#languageclient#get_error()
   26   0.064010   0.055281  <SNR>163_GetNearbyTag()
   21   0.060084   0.001583  tagbar#currenttag()
 3409   0.048464             airline#util#append()
  487   0.039499   0.013320  airline#parts#readonly()
  974   0.036714   0.023580  airline#util#shorten()
  487   0.033999   0.023655  WebDevIconsGetFileFormatSymbol()
  564   0.029697   0.021910  <SNR>58_on_cursor_moved()
    4   0.029623   0.004828  airline#highlighter#highlight()
  487   0.027735   0.007109  airline#parts#mode()

FUNCTIONS SORTED ON SELF TIME
count  total (s)   self (s)  function
  974              4.298768  <SNR>137_diagnostics_for_buffer()
    5   0.674117   0.428210  <SNR>163_AutoUpdate()
    5   0.238006   0.237939  <SNR>163_IsValidFile()
  564              0.148016  <SNR>103_Highlight_Matching_Pair()
  487   0.110855   0.105453  WebDevIconsGetFileTypeSymbol()
  487   0.120216   0.088048  airline#check_mode()
  487   0.082357   0.066268  airline#extensions#whitespace#check()
   26   0.064010   0.055281  <SNR>163_GetNearbyTag()
 3409              0.048464  airline#util#append()
  974   4.328220   0.029451  airline#extensions#languageclient#get()
 2922              0.027603  airline#util#prepend()
  487              0.026179  airline#util#ignore_buf()
  487              0.024027  airline#extensions#keymap#status()
  487   0.033999   0.023655  WebDevIconsGetFileFormatSymbol()
  974   0.036714   0.023580  airline#util#shorten()
  564   0.029697   0.021910  <SNR>58_on_cursor_moved()
 2922              0.021827  airline#util#wrap()
 1461              0.019283  airline#util#winwidth()
  487              0.017652  airline#parts#spell()
  487   0.074958   0.014874  airline#extensions#tagbar#currenttag()
martskins commented 3 years ago

Yeah I think we should be able to stop some of those calls as well. But that's definitely something we have to do in airline. I'll see about opening a PR there to try and fix that as well 👍

Thanks for testing it out

martskins commented 3 years ago

@YaLTeR Just opened https://github.com/vim-airline/vim-airline/pull/2282 to try to address that last bit. It won't fix it all the way, as I don't think there's a (clean) way for airline to know whether it should load the extension for that specific filetype, but that fix should cut a bunch of that time out of your profile.

One thing that could work better is to just check if there is a configured server in the LanguageClient_serverCommands global and do not load the extension if there isn't, but that sounds a little hacky maybe?

YaLTeR commented 3 years ago

check if there is a configured server in the LanguageClient_serverCommands global and do not load the extension if there isn't

Unfortunately it's impossible to configure extensions at any point past initial plugin load: https://github.com/vim-airline/vim-airline/issues/2086#issuecomment-705420571

martskins commented 3 years ago

Ah well, that settles that then, I think our only bet is to exit early in that airline#extensions#languageclient#get function then. 👍