autozimu / LanguageClient-neovim

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

`Server not configured for filetype php` seen when calling `LanguageClient_registerServerCommands` #1226

Open TysonAndre opened 3 years ago

TysonAndre commented 3 years ago

Describe the bug

LanguageClient_registerServerCommands no longer works without a key in the g:LanguageClient_serverCommands config,

I'm seeing Server not configured for filetype php after updating this to the latest public release.

LanguageClient#registerServerCommands calls LanguageClient#Call

LanguageClient#Call will filter out messages to skip.

One of the reasons a message could be skipped is that there is no serverCommand configured for that language.

However, LanguageClient#registerServerCommands is what is used to add language server commands

I expect this was caused by "Do not send requests/notifications for buffers without a configured server command (#1121) "

diff --git a/autoload/LanguageClient.vim b/autoload/LanguageClient.vim
index c626666..d050381 100644
--- a/autoload/LanguageClient.vim
+++ b/autoload/LanguageClient.vim
@@ -847,7 +847,7 @@ function! LanguageClient#HasCommand(filetype) abort
 endfunction

 function! LanguageClient#Call(method, params, callback, ...) abort
-    if s:SkipSendingMessage()
+    if a:method != 'languageClient/registerServerCommands' && s:SkipSendingMessage()
         echo '[LC] Server not configured for filetype ' . &filetype
         return
     endif

I assume that .vim/settings.json is now recommended instead?

I still get issues even with this patch - file updates aren't sent to the language server if I use the plugin rather than hardcoding serverCommands

Environment

To Reproduce

  1. Install latest https://github.com/TysonAndre/LanguageServer-phan-neovim and LanguageClient-neovim using instructions in LanguageServer-phan-neovim (e.g. phan itself has a .phan config)
  2. Open a php file belonging to the project (e.g. src/Phan/Config.php)
  3. Edit the file and observe that language server doesn't start

Current behavior

Server not configured for filetype php is seen with https://github.com/TysonAndre/LanguageServer-phan-neovim

Oddly, the language server doesn't start in the latest LanguageClient-neovim versions if I use that repo to set serverCommands, but if I manually hardcode g:LanguageClient_serverCommands it works

    let g:LanguageClient_serverCommands = {
        \ 'php': ['/home/tyson/php-7.4.19-dev-nts-install/bin/php', '/home/tyson/.vim/plugged/LanguageServer-phan-neovim/vendor/phan/phan/phan', '--require-config-exists', '--language-server-on-stdin', '--project-root-directory', '/path/to/phan', '--quick', '--language-server-allow-missing-pcntl', '--use-fallback-parser', '--allow-polyfill-parser', '--memory-limit', '2G', '--language-server-enable-go-to-definition', '--language-server-enable-hover', '--language-server-enable-completion', '--language-server-hide-category', '--analyze-all-files', '--language-server-verbose', '--plugin', 'InvokePHPNativeSyntaxCheckPlugin'],
        \ }

g:LanguageClient_serverStderr was set for --language-server-verbose to get logged to a file while debugging this, it's extremely verbose.

(unrelatedly, this works better when pcntl is available in php -m. The language server is throwing exceptions in some edge cases when pcntl is unavailable and LanguageClient-neovim doesn't indicate this - I fixed that in github.com/phan/phan v4 just now)

Expected behavior

registerServerCommands should work as expected. Modified file contents should get sent to language server if a language server is registered through LanguageClient_registerServerCommand

Additional context

I haven't updated the client in a while, but the server worked on old releases.

If I call LanguageClientStart with the plugin as-is, calling registerServerCommands, the client stops sending commands after the s:SetHighlights line.

If I hardcode the exact same command line the plugin would generate, then the client works as expected

13:27:41 INFO unnamed src/vim.rs:225 Begin setqflist
13:27:41 DEBUG writer-None src/rpcclient.rs:256 => None {"jsonrpc":"2.0","method":"setqflist","params":[[{"col":1,"filename":"/home/tyson/programming/phan/src/Phan/Config.php","lnum":7,"nr":null,"text":"PhanNativePHPSyntaxCheckPlugin Saw error or notice for /home/tyson/php-7.2.34-nts-install/bin/php --syntax-check: \"Parse error: syntax error, unexpected 'Phan' (T_STRING)\"","type":"E"},{"col":1,"filename":"/home/tyson/programming/phan/src/Phan/Config.php","lnum":7,"nr":null,"text":"PhanNoopConstant Unused constant","type":"I"},{"col":1,"filename":"/home/tyson/programming/phan/src/Phan/Config.php","lnum":7,"nr":null,"text":"PhanPluginNotFullyQualifiedGlobalConstant Expected usage of Phan\\Config\\Initializer to be fully qualified or have a use statement but none were found in namespace \\Phan","type":"W"},{"col":1,"filename":"/home/tyson/programming/phan/src/Phan/Config.php","lnum":7,"nr":null,"text":"PhanPluginNotFullyQualifiedGlobalConstant Expected usage of se to be fully qualified or have a use statement but none were found in namespace \\Phan","type":"W"},{"col":4,"filename":"/home/tyson/programming/phan/src/Phan/Config.php","lnum":7,"nr":null,"text":"PhanSyntaxError syntax error, unexpected 'Phan' (T_STRING)","type":"E"},{"col":1,"filename":"/home/tyson/programming/phan/src/Phan/Config.php","lnum":7,"nr":null,"text":"PhanUndeclaredConstant Reference to undeclared constant \\Phan\\Phan\\Config\\Initializer. This will cause a thrown Error in php 8.0+.","type":"E"},{"col":1,"filename":"/home/tyson/programming/phan/src/Phan/Config.php","lnum":7,"nr":null,"text":"PhanUndeclaredConstant Reference to undeclared constant \\se. This will cause a thrown Error in php 8.0+.","type":"E"},{"col":1,"filename":"/home/tyson/programming/phan/src/Phan/Config.php","lnum":1306,"nr":null,"text":"PhanUndeclaredClassMethod Call to method determineTargetPHPVersion from undeclared class \\Phan\\Initializer (Did you mean class \\Phan\\Config\\Initializer)","type":"E"}],"r"]}
13:27:41 DEBUG writer-None src/rpcclient.rs:256 => None {"jsonrpc":"2.0","method":"setqflist","params":[[],"a",{"title":"[LC]: diagnostics"}]}
13:27:41 DEBUG writer-None src/rpcclient.rs:256 => None {"jsonrpc":"2.0","method":"eval","params":["bufnr('/home/tyson/programming/phan/src/Phan/Config.php')"],"id":26}
13:27:41 DEBUG reader-None src/rpcclient.rs:209 <= None {"id":26,"jsonrpc":"2.0","result":1}
13:27:41 DEBUG writer-None src/rpcclient.rs:256 => None {"jsonrpc":"2.0","method":"setbufvar","params":["/home/tyson/programming/phan/src/Phan/Config.php","LanguageClient_statusLineDiagnosticsCounts",{"E":5,"H":0,"I":1,"W":2}]}
13:27:41 DEBUG writer-None src/rpcclient.rs:256 => None {"jsonrpc":"2.0","method":"eval","params":["LSP#filename()"],"id":27}
13:27:41 DEBUG reader-None src/rpcclient.rs:209 <= None {"id":27,"jsonrpc":"2.0","result":"/home/tyson/programming/phan/src/Phan/Config.php"}
13:27:41 DEBUG unnamed src/language_client.rs:158 state.highlights./home/tyson/programming/phan/src/Phan/Config.php: [] ==> [{"character_end":0,"character_start":0,"group":"LanguageClientInfo","line":6,"text":""},{"character_end":0,"character_start":0,"group":"LanguageClientWarning","line":6,"text":""},{"character_end":0,"character_start":0,"group":"LanguageClientWarning","line":6,"text":""},{"character_end":0,"character_start":0,"group":"LanguageClientError","line":6,"text":""},{"character_end":0,"character_start":3,"group":"LanguageClientError","line":6,"text":""},{"character_end":0,"character_start":0,"group":"LanguageClientError","line":6,"text":""},{"character_end":0,"character_start":0,"group":"LanguageClientError","line":6,"text":""},{"character_end":0,"character_start":0,"group":"LanguageClientError","line":1305,"text":""}]
13:27:41 DEBUG writer-None src/rpcclient.rs:256 => None {"jsonrpc":"2.0","method":"s:MatchDelete","params":[[]]}
13:27:41 DEBUG writer-None src/rpcclient.rs:256 => None {"jsonrpc":"2.0","method":"matchaddpos","params":["LanguageClientInfo",[[7,1,999999]]],"id":28}
13:27:41 DEBUG reader-None src/rpcclient.rs:209 <= None {"id":28,"jsonrpc":"2.0","result":7}
13:27:41 DEBUG writer-None src/rpcclient.rs:256 => None {"jsonrpc":"2.0","method":"matchaddpos","params":["LanguageClientError",[[7,1,999999],[7,4,999999],[7,1,999999],[7,1,999999],[1306,1,999999]]],"id":29}
13:27:41 DEBUG reader-None src/rpcclient.rs:209 <= None {"id":29,"jsonrpc":"2.0","result":8}
13:27:41 DEBUG writer-None src/rpcclient.rs:256 => None {"jsonrpc":"2.0","method":"matchaddpos","params":["LanguageClientWarning",[[7,1,999999],[7,1,999999]]],"id":30}
13:27:41 DEBUG reader-None src/rpcclient.rs:209 <= None {"id":30,"jsonrpc":"2.0","result":9}
13:27:41 DEBUG unnamed src/language_client.rs:158 state.highlight_match_ids: [] ==> [7,8,9]
13:27:41 INFO unnamed src/language_client.rs:1604 handle_cursor_moved; params=Null force_redraw=true
13:27:41 DEBUG writer-None src/rpcclient.rs:256 => None {"jsonrpc":"2.0","method":"eval","params":["LSP#filename()"],"id":31}
13:27:41 DEBUG reader-None src/rpcclient.rs:209 <= None {"id":31,"jsonrpc":"2.0","result":"/home/tyson/programming/phan/src/Phan/Config.php"}
13:27:41 DEBUG writer-None src/rpcclient.rs:256 => None {"jsonrpc":"2.0","method":"getbufvar","params":["/home/tyson/programming/phan/src/Phan/Config.php","&filetype"],"id":32}
13:27:41 DEBUG reader-None src/rpcclient.rs:209 <= None {"id":32,"jsonrpc":"2.0","result":"php"}
13:27:41 DEBUG writer-None src/rpcclient.rs:256 => None {"jsonrpc":"2.0","method":"eval","params":["LSP#position()"],"id":33}
13:27:41 DEBUG reader-None src/rpcclient.rs:209 <= None {"id":33,"jsonrpc":"2.0","result":{"character":0,"line":6}}
13:27:41 DEBUG writer-None src/rpcclient.rs:256 => None {"jsonrpc":"2.0","method":"eval","params":["LSP#viewport()"],"id":34}
13:27:41 DEBUG reader-None src/rpcclient.rs:209 <= None {"id":34,"jsonrpc":"2.0","result":{"end":18,"start":0}}
13:27:41 INFO unnamed src/language_client.rs:1569 get_signs_to_display; filename="/home/tyson/programming/phan/src/Phan/Config.php" viewport=Viewport { start: 0, end: 18 }
13:27:41 DEBUG writer-None src/rpcclient.rs:256 => None {"jsonrpc":"2.0","method":"s:set_signs","params":["/home/tyson/programming/phan/src/Phan/Config.php",[{"id":75025,"line":6,"name":"LanguageClientError"}]],"id":35}
13:27:41 DEBUG reader-None src/rpcclient.rs:209 <= None {"id":35,"jsonrpc":"2.0","result":0}
13:27:41 DEBUG writer-None src/rpcclient.rs:256 => None {"jsonrpc":"2.0","method":"s:SetHighlights","params":[[{"character_end":0,"character_start":0,"group":"LanguageClientInfo","line":6,"text":""},{"character_end":0,"character_start":0,"group":"LanguageClientWarning","line":6,"text":""},{"character_end":0,"character_start":0,"group":"LanguageClientWarning","line":6,"text":""},{"character_end":0,"character_start":0,"group":"LanguageClientError","line":6,"text":""},{"character_end":0,"character_start":3,"group":"LanguageClientError","line":6,"text":""},{"character_end":0,"character_start":0,"group":"LanguageClientError","line":6,"text":""},{"character_end":0,"character_start":0,"group":"LanguageClientError","line":6,"text":""}],"__LCN_DIAGNOSTIC_HIGHLIGHT__"]}
13:27:41 DEBUG writer-None src/rpcclient.rs:256 => None {"jsonrpc":"2.0","method":"s:ExecuteAutocmd","params":["LanguageClientDiagnosticsChanged"]}
martskins commented 3 years ago

Ah good catch! I think this should be easy to solve by just adding a value for the missing registered server on the call to LanguageClient#registerServerCommands if there is nothing else configured. Will try and think if there's a simplest solution to this in the next few days but I think that will most likely be the solution.