richterger / Perl-LanguageServer

Language Server for Perl
Other
225 stars 52 forks source link

Cannot load source #179

Closed quentinnuk closed 1 year ago

quentinnuk commented 1 year ago

This is a followup to #100.

When calling a package from within a perl script, the package source fails to load when a full path is in settings.json. but a relative path is given in a use lib.

Error messages: Could not load source './src/th_main.pm': Unknown perlmethod _dapreq_source at /usr/local/share/perl/5.32.1/Perl/LanguageServer.pm line 224.

My source code:

#!/usr/bin/env perl

use strict;

$| = 1;

BEGIN { -d 'src' or chdir '..' or die $! };

use lib 'src';  # TH library is in here relative to cwd set above

use TH;

TH::th_init(); # this goes on to import more modules and call `th_main` which is in `src/th_main.pm` file but is not a package.

My settings.json with the full path for the lib directory src:

"perl.perlInc": [
          "/home/username/dev/code/2.0/src/",
         "/home/username/devel/perltest/"],
}

The use of a relative path in the use lib seems to be the problem, and that it is dynamically generated later on in the code when further imports are done, and that seems to throw the debugger off in finding the source. I anticipated that by specifying the full paths in the json settings that this would overcome that issue, but it seems not. Is this something that could be addressed?

richterger commented 1 year ago

The _dapreq_source is called when vscode cannot find your source locally (or the debugger returns a wrong path, that cannot found locally). _dapreq_source is not need under normal circumstances and is not implement by the Perl::LanguageServer. I guess the debugger assume the wrong working directory, so relative path points to nowhere. Please try to set cwd to the directory you are running in.