Closed 6aKa closed 3 years ago
I try map, but this not help
"perl.pathMap": [
["../../../lib", "/Users/user/Projects/test/lib"]
]
I think you need to use the cwd
config option, to set your current working directory to whatever is correct. LanguageServer can not know this.
~/Projects/test (master) $ cd a
~/Projects/test/a (master) $ perl test_from_a.pl
[TEST MESSAGE FROM a]
~/Projects/test/a (master) $ cd b
~/Projects/test/a/b (master) $ perl test_from_b.pl
[TEST MESSAGE FROM b]
~/Projects/test/a/b (master) $ cd c
~/Projects/test/a/b/c (master) $ perl test_from_c.pl
[TEST MESSAGE FROM c]
~/Projects/test/a/b/c (master) $
when open for editing
test_from_a.pl get Bad path specification:
../lib' => /Users/user/Projects/test/../lib' (No such file or directory) at - line 6.
test_from_b.pl get Bad path specification:
../../lib' => /Users/user/Projects/test/../../lib' (No such file or directory) at - line 6.
test_from_c.pl get Bad path specification:
../../../lib' => /Users/user/Projects/test/../../../lib' (No such file or directory) at - line 6.
Using the test.tar.gz archive given by @6aKa , I access the test cases from the main folder:
code -n test
I have no problem to debug any of the 3 test cases; Stepping through and in them gives me the expected message:
However, I believe the problem stated is about editing, so I tried @richterger 's recommendation:
launch.json
"version": "0.2.0",
"configurations": [
{
"type": "perl",
"request": "launch",
"name": "Perl-Debug",
"program": "${file}",
"cwd": "${fileDirname}",
"stopOnEntry": true,
"reloadModules": true
}
]
}
That is not working, for a variety of reasons:
code -n test
).So I put the three test cases in a workspace with three folders:
test.code-workspace
{
"folders": [
{
"name": "a",
"path": "test/a"
},
{
"name": "b",
"path": "test/a/b"
},
{
"name": "c",
"path": "test/a/b/c"
},
]
}
Now whichever folder is first, will work (no syntax error)! Note: when you have a workspace with multiple folders, you can drag them to reorder them in the VS Code Explorer. So any folder you drag to the first position will not show syntax errors...
Workspace folder c
, last in order:
Workspace folder c
, first in order:
Since the original problem probably only applied to one single program, I think the problem can be avoided with a workspace:
/Users/user/Projects/
|_test.code-workspace
|_test
|_script/cron/daily/task.pl
$ code -n test.code-workspace
test.code-workspace
{
"folders": [
{
"name": "task",
"path": "test/script/cron/daily/task"
},
]
}
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 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.
In file
/Users/user/Projects/test/script/cron/daily/task.pl
i have lineuse lib::abs qw(../../../lib);
I got errorBad path specification: '../../../lib' => '/Users/user/Projects/test/../../../lib' (No such file or directory) at - line 3.
Directory/Users/user/Projects/test/lib
exist.It seems language server always use root dir for all files instead current file dir for each file.