Closed nametable closed 3 years ago
The local directory has been removed from the search path in Perl 5.26, for security purposes. Although I can reproduce the problem as described (Using Perl5.30.3), the problem goes away if we use the recommended approach to find information in the same directory as the Perl program (FindBin):
main.pl
use strict;
print "Hello World from main.pl\n";
use Cwd qw(cwd);
print "cwd=" . cwd . "\n";
use FindBin;
use lib "$FindBin::Bin";
require 'Lib/TestLib.pm';
TestLib::doStuff();
With this code, everything works as expected (including the step into
for the TestLib::doStuff(); You don't have to remove the
perl.perlInc` setting, but I wouldn't include the "local" directory in there, the Perl coding style guidelines have recommended against this for quite a long time...
I don't expect Perl::LanguageServer to support the original syntax, but it is a bug. However, as a developer, I would recommend "wont_fix".
It seems the module simply cannot handle relative paths in %INC. Struggled earlier today with a launch.json configuration that had env: "PERL5OPT=-Ilib ..."
and could not find files either, but using absolute paths made it work in the debugger.
It is not defined what the current working directory is, at the start of a perl program. So Perl::LanguageServer makes no assumtion about it. To solve your problem, you can set the directory via cwd configurationm parameter during debugging. Which you already did, but it is is broken in 2.2 and will be fixed in 2.3. Even better is to set the perl include path. In your settings.json do something like:
"perl.perlInc": [
"/path/a/lib",
"/path/b/lib",
"/path/c/lib",
],
Include path works for syntax check and inside of debugger. perl.perlInc
should be an absolute path.
cwd parameter is fixed in af895ae91ae825aef363125ad4b87ccabb4b020f
Adding this just before an old CGI script's main block and after the other 'use' statements made it work for me:
use FindBin;
use lib "$FindBin::Bin/..";
This script is in a sub-directory below the code root directory hence /.. If I put these lines up above the other use lib and use Module statements, then it didn't work. Below them and it did. I could not figure out why.
I am leaving this comment in case anyone else comes across this and is looking for a solution.
I am trying to figure out why my source code is not being found by the debugger. Either I am making a mistake or there is a bug in the debugger.
My directory structure looks like so
main.pl
TestLib.pm
.vscode/settings.json
.vscode/launch.json
When I start the Perl Debugger in VSCode, it starts as usual from the top of
main.pl
but when I step intoTestLib::doStuff();
I get brought to a new tab namedTestLib.pm
which says:This result does not make sense to me since the launch
cwd
is specified and theperl.perlInc
path is set to include./
. If I continue the execution, it finishes and outputs what is expected:There must be some sort of path issue. Does someone know if this is a configuration issue, or a bug in the extension?