richterger / Perl-LanguageServer

Language Server for Perl
Other
220 stars 53 forks source link

Error "Can't locate MODULE_NAME" for local modules #119

Closed fabioperrella closed 2 years ago

fabioperrella commented 2 years ago

Hi, first of all, thank you for work in this Extension, it helps me a lot!

I'm a newbie using Perl, so maybe this is not a problem in this extension.

I'm facing a problem when I require local modules, for example, giving the following files:

bin/test.pl:

#!/usr/bin/perl -Ilib -Iextlib/lib/perl5

use strict;
use warnings;
use Airport::Search; # this line is showing an error in the "Problems" window
#...

lib/Airport/Search.pm:

package Airport::Search;
use strict;
use warnings;

#...

I'm getting this error in the "problems" window:

Can't locate Airport/Search.pm in @INC (you may need to install the Airport::Search module) ...

However, when I run perl -c, I don't get this error:

$ perl -c bin/search_airports
bin/search_airports syntax OK

I think this is related to the usage of -Ilib in the bin/test.pl script, but I don't know how to tell the Perl extension the same.

Do you know what I can do fix error message on VsCode?

ecos-ps commented 2 years ago

I think you have to set perlInc in your VSCode Settings.

Try open your settings with Ctrl + , and choose where you wanna insert them. I usually include it in my workspace for a given project.

Now add the following lines in your settings:

"settings": {
        "perl.perlInc": 
        [
          "lib/Airport",
          "another/path/you/want/to/include",
        ],
...
}
ecos-ps commented 2 years ago

Did my answer help you and the issue is done? Please select it as answer and close your issue on your own, when you can confirm.

richterger commented 2 years ago

Please use absolute path names in the perlInc settings or make sure you are running in the expected directory with the cwd setting in the lauch.json