richterger / Perl-LanguageServer

Language Server for Perl
Other
224 stars 51 forks source link

`cwd` doesn't work #99

Closed ermshiperete closed 3 years ago

ermshiperete commented 3 years ago

It seems that the cwd option doesn't work.

In my launch.json I have:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "perl",
      "request": "launch",
      "name": "Perl-Debug",
      "program": "tools/app.pl",
      "cwd": "${workspaceFolder}/linux",
      "stopOnEntry": true,
      "reloadModules": true
    }
  ]
}

For testing, I have a project with just one file (besides .vscode folder...):

linux/tools/app.pl:

#!/usr/bin/perl -w
use Cwd qw(cwd);
my $dir = cwd;

print "cwd=$dir\n";

When I try to debug, the Debug Console shows an error:

Can't open perl script "tools/app.pl": No such file or directory

When I change launch.json to contain the full path:

      "program": "${workspaceFolder}/linux/tools/app.pl",

and the output is:

cwd=/tmp/perl-bug

instead of the expected /tmp/perl-bug/linux.

dseynhae commented 3 years ago

I have experienced the same problem, in a variety of ways, however the test case from @ermshiperete is an excellent way to reproduce it. Looking for a work around (using other predefined variables), even this doesn't work (reveals that cwd does not get applied): launch.json

...
      "program": "${file}",
      "cwd": "${fileDirname}",
...
cycollins commented 3 years ago

I have this same problem and it's rough because the perl script I'm debugging drives git, where cwd is everything. I suppose I could just modify a copy of the script to cd to a directory, and then TRY REAL HARD to remember not to check that sh.. er stuff in. The developer seems like a responsible and thorough guy, but it has been a rough roll-out. I should put a pwd in. If it's not the cwd from the launch.json, what IS the cwd? Probably workspaceFolder.

richterger commented 3 years ago

cwd in launch.json really currently does not work, will be fixed in next release. I am just working on it.

cycollins commented 3 years ago

Thank you. I’m sorry if I struck a critical tone. I quite like the software, but for my application it was important. I looked for the problem in the source, but I’m simply not sufficiently well-versed in the extension model. Otherwise I’d have simply made a pull request. I’m curious now, though. Isn’t the “cwd” function provided by the application? As a piece of global state, it would be easy to get stomped on, but I could see no obvious evidence of that. Or am I mistaken in the impression that handling the “cwd” entry in the configuration is a service of the app framework?

Sent from my iPhone

On Jul 8, 2021, at 6:22 AM, Gerald Richter @.***> wrote:

 cwd in launch.json really currently does not work, will be fixed in next release. I am just working on it.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

richterger commented 3 years ago

cwd needs to be handled by the debugger (e.g. Perl::LanguageServer) It's fixed in af895ae91ae825aef363125ad4b87ccabb4b020f