bscan / RakuNavigator

Raku language support and language server
MIT License
51 stars 3 forks source link

"Could not find" module error in test file #21

Open oyarsa opened 5 months ago

oyarsa commented 5 months ago

I'm getting an error that the editor cannot find the lib when in the test file, but prove6 runs correctly.

Here is the folder structure:

├── HELP.md
├── README.md
├── lib
│   └── Pangram.rakumod
└── t
    └── pangram.rakutest

And here's the top of the test file:

use Test;
use lib $?FILE.IO.parent(2).add('lib');
use Pangram;

This is the full error:

    /Users/italo/.vscode/extensions/bscan.raku-navigator-0.3.2/server/src/lib
    /Users/italo/.raku
    /opt/homebrew/Cellar/rakudo-star/2024.02/share/perl6/site
    /opt/homebrew/Cellar/rakudo-star/2024.02/share/perl6/vendor
    /opt/homebrew/Cellar/rakudo-star/2024.02/share/perl6/core
    CompUnit::Repository::AbsolutePath<6136726709184>
    CompUnit::Repository::NQP<6136721594120>
    CompUnit::Repository::Perl5<6136721594160>
raku navigator

This is from Exercism's Pangram exercise: https://exercism.org/tracks/raku/exercises/pangram

I'm running the Raku VS Code extension v0.3.2, Rakudo v2024.02 on macOS 14.2.1 (M1 Pro).

bscan commented 5 months ago

Hi @oyarsa, thanks for filing the issue. This is a limitation because the Raku Navigator is not taking file locations into account while compiling, so any relative pathing (e.g. $?FILE) is not going to work correctly. The file does not compile in place because a user may be editing the file, so we need to compile the unsaved version that does not exist on disk.

Currently, the code and file-path are both passed into navigator.raku, but file-path is not currently utilized. This would be a great improvement, but I'm not currently sure how to do it. If anyone has any suggestions, or would like to make a pull request, that would be great. https://github.com/bscan/RakuNavigator/blob/master/server/src/raku/navigator.raku

bscan commented 5 months ago

Another option available is using the setting raku.includePaths. This is an array that lets you add things to the search path and you could add "raku.includePaths": ["/path/to/folder/lib"]

I should probably also start adding "./lib" by default. In the Perl version, when you have a folder or workspace open, it will automatically add the ./lib folder as an include path. https://github.com/bscan/PerlNavigator/blob/1f3e38e74277f1f95b6a4a10012a71eb9826b109/server/src/utils.ts#L31