richterger / Perl-LanguageServer

Language Server for Perl
Other
220 stars 53 forks source link

Perltidy failed with exit code 126 #160

Closed dseynhae closed 1 year ago

dseynhae commented 1 year ago

@richterger On Windows 10, using remote sessions (remote WSL or Remote SSH): When trying to run Format Document, with the format section of the Perl VS Code Extension:

LS: end aio read cnt=278, buffer len = 278
LS: line=<Content-Length: 255>
LS: line=<>
LS: read data={"jsonrpc":"2.0","id":5,"method":"textDocument/rangeFormatting","params":{"textDocument":{"uri":"file:///home/dseynhae/_PERL/test.pl"},"range":{"start":{"line":0,"character":0},"end":{"line":14,"character":0}},"options":{"tabSize":2,"insertSpaces":true}}}
LS: read header={ "Content-Length" => 255 }
LS: ---> Request: {
   "params" : {
      "options" : {
         "insertSpaces" : true,
         "tabSize" : 2
      },
      "textDocument" : {
         "uri" : "file:///home/dseynhae/_PERL/test.pl"
      },
      "range" : {
         "start" : {
            "character" : 0,
            "line" : 0
         },
         "end" : {
            "line" : 14,
            "character" : 0
         }
      }
   },
   "id" : 5,
   "jsonrpc" : "2.0",
   "method" : "textDocument/rangeFormatting"
}

LS: handle_req id=5
LS: method=_rpcreq_rangeFormatting
LS: {
  options => {
    insertSpaces => bless(do{\(my $o = 1)}, "JSON::PP::Boolean"),
    tabSize => 2,
  },
  range => {
    end => { character => 0, line => 14 },
    start => { character => 0, line => 0 },
  },
  textDocument => { uri => "file:///home/dseynhae/_PERL/test.pl" },
}LS: perltidy text: <package main;
use strict;
use warnings;

sub hello {
    print "hello\n";

}

sub main {
    hello;
}

main;>
LS: start perltidy file:///home/dseynhae/_PERL/test.pl from line 0 to 13
LS: start aio read, buffer len = 0
LS: start aio read, buffer len = 0
LS: perltidy rc=126 errout=
LS: <--- Notification: {
   "jsonrpc" : "2.0",
   "method" : "textDocument/publishDiagnostics",
   "params" : {
      "uri" : "file:///home/dseynhae/_PERL/test.pl",
      "diagnostics" : []
   }
}

LS: ERROR: perltidy failed with exit code 126 at /usr/local/share/perl/5.26.1/Perl/LanguageServer/Methods/textDocument.pm line 484.

LS: <--- Response: {
   "jsonrpc" : "2.0",
   "error" : {
      "message" : "perltidy failed with exit code 126 at /usr/local/share/perl/5.26.1/Perl/LanguageServer/Methods/textDocument.pm line 484.\n",
      "code" : -32001
   },
   "id" : "5"
}

LS: done handle_req id=5
[Error - 8:23:33 PM] Request textDocument/rangeFormatting failed.
  Message: perltidy failed with exit code 126 at /usr/local/share/perl/5.26.1/Perl/LanguageServer/Methods/textDocument.pm line 484.

  Code: -32001 
##### 9 #####
 running: {} coros: {}

Using:

dseynhae commented 1 year ago

When I install Simple Perl, on the same file, I have no problems formatting with PerlTidy.

I am assuming that both the Perl extension and this Simple Perl extension use the same PerlTidy installation...

dseynhae commented 1 year ago

I just installed VS Code on Linux, and even there the same problem exists, when I try to format Perl with the VS Code Perl extension; I guess this shouldn't be a surprise, as it is probably the same extension code executing with the same PerlTidy installation...

LS: {
  options => {
    insertSpaces => bless(do{\(my $o = 1)}, "JSON::PP::Boolean"),
    tabSize => 2,
  },
  range => {
    end => { character => 0, line => 28 },
    start => { character => 0, line => 0 },
  },
  textDocument => {
    uri => "file:///nfs/site/disks/swuser_work_dseynhae/home/_PERL/quick_test/test.pl",
  },
}LS: ERROR: perltidy failed with exit code 126 at /nfs/site/home/dseynhae/perl5/lib/perl5/Perl/LanguageServer/Methods/textDocument.pm line 484.

[Error - 9:57:48 AM] Request textDocument/rangeFormatting failed.
  Message: perltidy failed with exit code 126 at /nfs/site/home/dseynhae/perl5/lib/perl5/Perl/LanguageServer/Methods/textDocument.pm line 484.

  Code: -32001 
marghidanu commented 1 year ago

Same for me on macOS:

[Error - 8:12:48 PM] Request textDocument/rangeFormatting failed.
  Message: perltidy failed with exit code 126 at /Library/Perl/5.30/Perl/LanguageServer/Methods/textDocument.pm line 484.

  Code: -32001 
richterger commented 1 year ago

@dseynhae @marghidanu Looks like perltidy binary is not in the PATH vscode is searching. Maybe you could try to add the full path to perltidy in Perl/LanguageServer/Methods/textDocument.pm or set your PATH via perl.env setting

marghidanu commented 1 year ago

That worked, but I had to set the entire value for the PATH variable. Can this be inferred automatically by the extension? Or maybe add a variable just for the perltidy path?

dseynhae commented 1 year ago

I went ahead and updated the user settings.json:

"perl.env": {"PATH": "/home/dseynhae/bin:/bin:/usr/local/bin:/sbin:/usr/local/sbin"}

Since Perltidy was installed through cpanm in the system libraries, it was indeed in /usr/local/bin...

However, that location has always been in my main PATH variable, and I swear that it used to work before with the VS Code Perl Extension...

We first talked about this for environment variables in general, within VS Code.

It looks like there is a proposal to fix this through an option. I personally don't think this should be an option, it should be the normal behavior (all of my other Language Servers seem to import the existing environment for when I launch code...).

Would we at least consider this the "normal" behavior for at least the PATH variable?

richterger commented 1 year ago

Environment is now passed per default. This can be disabled by disablesPassEnv, see 29ad712a55348a1ba06a375bbf5e00fb62abbf05