richterger / Perl-LanguageServer

Language Server for Perl
Other
224 stars 51 forks source link

Server terminates prematurely when sent a `shutdown` LSP request #88

Closed siegel closed 3 years ago

siegel commented 3 years ago

I'm finding that when my client (which I'm writing) sends a shutdown request to the Perl-LanguageServer, the server appears to terminate immediately rather than returning a suitable response. This breaks clients who follow the LSP specification and wait for the server to return a response to shutdown before sending an exit request.

Platform: macOS 10.15.7 Perl v5.32.1 installed via brew install perl Perl-LanguageServer v2.2.0

Here is an excerpt from the log (with level 2):

2021-04-07 09:05:17.037: stderr output from server: LS: end aio read cnt=80
LS: line=<Content-Length: 58>
LS: line=<>
LS: read data={"jsonrpc":"2.0","id":2,"method":"shutdown","params":null}

2021-04-07 09:05:17.037: stderr output from server: LS: read header={ "Content-Length" => 58 }

2021-04-07 09:05:17.037: stderr output from server: LS: ---> Request: {
   "params" : null,
   "method" : "shutdown",
   "jsonrpc" : "2.0",
   "id" : 2
}

2021-04-07 09:05:17.037: stderr output from server: LS: handle_req id=2

2021-04-07 09:05:17.037: stderr output from server: Attribute (params) does not pass the type constraint because: Validation failed for 'HashRef' with value undef at /usr/local/Cellar/perl/5.32.1_1/lib/perl5/site_perl/5.32.1/darwin-thread-multi-2level/Moose/Object.pm line 24
    Moose::Object::new('Perl::LanguageServer::Req', 'HASH(0x7f98772e5aa8)') called at /usr/local/Cellar/perl/5.32.1_1/lib/perl5/site_perl/5.32.1/Perl/LanguageServer.pm line 250
    Perl::LanguageServer::__ANON__ at /usr/local/Cellar/perl/5.32.1_1/lib/perl5/site_perl/5.32.1/darwin-thread-multi-2level/Coro.pm line 716
    Coro::_coro_run at /Users/siegel/Dropbox/Apps/BBEdit/Language Servers/start-languageserver-perl.pl line 0
LS: done handle_req id=2

At this point the server process terminates, leaving the client hanging.

I will be happy to provide additional log data, if that would be helpful.

richterger commented 3 years ago

The problem is that LanguageServer expects params and don't get any. I will fix this. For the time being you can send an empty params object.

siegel commented 3 years ago

OK, great, thanks. The same fix will probably be useful for exit.

richterger commented 3 years ago

It's fixed as part of the commit 6c04cf1b9f645e57825a402de9d6871918ceb42f

siegel commented 3 years ago

Confirmed, pulled HEAD and verified.