richterger / Perl-LanguageServer

Language Server for Perl
Other
224 stars 51 forks source link

Not receiving `textDocument/publishDiagnostics` #90

Open siegel opened 3 years ago

siegel commented 3 years ago

I'm writing a new LSP client (i.e. one that's not VS Code), and I'd like to support the Perl language server. Basic integration is working, but I'm finding that the server never reports any diagnostics, even for obvious syntax errors.

When sending initialize, my client reports the following capabilities:

    capabilities =     {
        completion =         {
            completionItem =             {
                deprecatedSupport = 1;
                insertReplaceSupport = 1;
                insertTextModeSupport =                 {
                    valueSet =                     (
                        1,
                        2
                    );
                };
                preselectSupport = 1;
                snippetSupport = 1;
            };
            contextSupport = 1;
        };
        textDocument =         {
            codeAction =             {
            };
            completion =             {
                completionItem =                 {
                    deprecatedSupport = 1;
                    insertReplaceSupport = 1;
                    insertTextModeSupport =                     {
                        valueSet =                         (
                            1,
                            2
                        );
                    };
                    preselectSupport = 1;
                    resolveSupport =                     {
                        properties =                         (
                            detail,
                            documentation
                        );
                    };
                    snippetSupport = 1;
                };
            };
            documentSymbol =             {
                hierarchicalDocumentSymbolSupport = 1;
                labelSupport = 1;
            };
            publishDiagnostics =             {
                categorySupport = 1;
                codeActionsInline = 1;
                codeDescription = 1;
                dataSupport = 1;
                relatedInformation = 1;
            };
            signatureHelp =             {
                signatureInformation =                 {
                    activeParameterSupport = 1;
                    parameterInformation =                     {
                        labelOffsetSupport = 1;
                    };
                };
            };
            synchronization =             {
                didSave = 1;
                willSave = 1;
            };
        };
        workspace =         {
            configuration = 1;
            workspaceFolders = 1;
        };
    };
    initializationOptions =     {
    };
    rootUri = "file:///Users/siegel/Desktop/LSPTest/";
    trace = verbose;
    workspaceFolders =     (
                {
            name = LSPTest;
            uri = "file:///Users/siegel/Desktop/LSPTest/";
        }
    );
}

Subsequently, I send a textDocument/didOpen for an example file provided by a beta tester:

2021-04-29 09:46:55.914: stderr output from server: LS: ---> Request: {
   "method" : "textDocument/didOpen",
   "params" : {
      "textDocument" : {
         "text" : "#!/usr/bin/perl\n\nuse Net::DNS;\nmy $res  = Net::DNS::Resolver->new;\n$res->nameservers(\"ns1.make-tracks.com\");\n\nmy @zone = $res->axfr(\"make-tracks.biz\");\n\nforeach $rr (@zone) {\n\t$rr->print;\n}\n\n1;\n",
         "languageId" : "perl",
         "uri" : "file:///Users/siegel/Desktop/LSPTest/zone-transfer.pl",
         "version" : 1
      }
   },
   "jsonrpc" : "2.0"
}

Then, after some (unsuccessful) random experimenting with textDocument/definition and workspace/symbol, I make a trivial edit to introduce a syntax error. The server logs this:

2021-04-29 09:54:10.858: stderr output from server: LS: end aio read cnt=441
LS: line=<Content-Length: 418>
LS: line=<>
LS: read data={"jsonrpc":"2.0","method":"textDocument\/didChange","params":{"contentChanges":[{"text":"#!\/usr\/bin\/perl\n\nuse Net::DNS;\nmy $res  = Net::DNS::Resolver->new;\n$res->nameservers(\"ns1.make-tracks.com\");\nxyzzy)\nmy @zone = $res->axfr(\"make-tracks.biz\");\nxyzzy\nforeach $rr (@zone) {\n\t$rr->print;\n}\n\n1;\n"}],"textDocument":{"uri":"file:\/\/\/Users\/siegel\/Desktop\/LSPTest\/zone-transfer.pl","version":3}}}
2021-04-29 09:54:10.858: stderr output from server: 

2021-04-29 09:54:10.858: stderr output from server: LS: read header={ "Content-Length" => 418 }

2021-04-29 09:54:10.860: stderr output from server: LS: ---> Request: {
   "jsonrpc" : "2.0",
   "params" : {
      "contentChanges" : [
         {
            "text" : "#!/usr/bin/perl\n\nuse Net::DNS;\nmy $res  = Net::DNS::Resolver->new;\n$res->nameservers(\"ns1.make-tracks.com\");\nxyzzy)\nmy @zone = $res->axfr(\"make-tracks.biz\");\nxyzzy\nforeach $rr (@zone) {\n\t$rr->print;\n}\n\n1;\n"
         }
      ],
      "textDocument" : {
         "version" : 3,
         "uri" : "file:///Users/siegel/Desktop/LSPTest/zone-transfer.pl"
      }
   },
   "method" : "textDocument/didChange"
}

However, the server never returns a textDocument/publishDiagnostics notification, and there's nothing in the stderr output that indicates why this might be. Is there an additional command-line flag I can use to enable additional debug output to stderr, or is there someplace else I should be looking for logging to explain this behavior?

Thanks for any assistance you can provide.

richterger commented 3 years ago

After the didOpen and didChange notifications you should see something like

start perl -c
perl -c rc=0 out= errout=- syntax OK

do you?

siegel commented 3 years ago

There is nothing like that in the log output from the server. I do see an acknowledgement when I send didOpenDocument:

2021-06-06 07:43:21.124: stderr output from server: LS: ---> Request: {
   "method" : "textDocument/didOpen",
   "jsonrpc" : "2.0",
   "params" : {
      "textDocument" : {
         "uri" : "file:///Users/siegel/Dropbox/Apps/Redacted/Scripts/Hello%20World.pl",
         "version" : 1,
         "text" : "#!/usr/bin/env perl -w\n\nuse strict;\n\nprint \"Hello, Perl!\\n\";\n",
         "languageId" : "perl"
      }
   }
}

LS: handle_req id=
LS: apply_all_roles (Moose::Meta::Class::__ANON__::SERIAL::1=HASH(0x7f84e47968f0), Perl::LanguageServer::Methods::textDocument, Perl/LanguageServer/Methods/textDocument.pm)

2021-06-06 07:43:21.129: stderr output from server: LS: method=_rpcnot_didOpen
LS: done handle_req id=1000000001
LS: start aio read

2021-06-06 07:43:31.122: stderr output from server: ##### 1 #####
 running: {} coros: {}

2021-06-06 07:43:41.126: stderr output from server: ##### 2 #####
 running: {} coros: {}

And the running: {} coros: {} logging repeats every few seconds, with an increasing number. There is nothing else logged to stderr by the server, and no indication of it running perl -c.

siegel commented 3 years ago

Further, if I make a nonsense edit in the file, the server logs to stderr:

2021-06-06 09:27:38.043: stderr output from server: LS: read data={"jsonrpc":"2.0","method":"textDocument\/didChange","params":{"contentChanges":[{"text":"#!\/usr\/bin\/env perl -w\n\nuse strict;\n\nprint \"Hello, Perl!\\n\";\n\nfoobar;\n"}],"textDocument":{"uri":"file:\/\/\/Users\/siegel\/Dropbox\/Apps\/BBEdit\/Scripts\/Hello%20World.pl","version":2}}}
LS: read header={ "Content-Length" => 289 }

2021-06-06 09:27:38.044: stderr output from server: LS: ---> Request: {
   "method" : "textDocument/didChange",
   "jsonrpc" : "2.0",
   "params" : {
      "textDocument" : {
         "version" : 2,
         "uri" : "file:///Users/siegel/Dropbox/Apps/BBEdit/Scripts/Hello%20World.pl"
      },
      "contentChanges" : [
         {
            "text" : "#!/usr/bin/env perl -w\n\nuse strict;\n\nprint \"Hello, Perl!\\n\";\n\nfoobar;\n"
         }
      ]
   }
}

LS: handle_req id=

2021-06-06 09:27:38.044: stderr output from server: LS: method=_rpcnot_didChange

2021-06-06 09:27:38.044: stderr output from server: LS: done handle_req id=1000000006

Again, no indication of running perl -c, and diagnostics are not returned.

siegel commented 3 years ago

Is there any additional logging or diagnostics that I can enable, which might help figure out why the server doesn't seem to be running perl -c when a document is opened? (The server is being started with --debug --log-level 2.)

richterger commented 3 years ago

Are you running on Windows or on Linux? There is an issue with starting child processes on Windows, for which I wasn't able to figure out the reason so far.

siegel commented 3 years ago

Are you running on Windows or on Linux?

Neither - macOS (10.15.7, Intel x86_64), perl --version reports:

This is perl 5, version 34, subversion 0 (v5.34.0) built for darwin-thread-multi-2level