bscan / RakuNavigator

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

False positive errors? #14

Closed gdonald closed 2 years ago

gdonald commented 2 years ago

I have a raku module installed:

zef list --installed | grep ^BDD                                                                                                                                                       ─╯
===> Found via /Users/gd/rakudo/share/perl6/site
===> Found via /Users/gd/rakudo/share/perl6/core
BDD::Behave:ver<0.0.4>:auth<github:gdonald>

And I'm getting this error:

Screen Shot 2022-06-05 at 4 14 04 PM

My code works, but vscode thinks it's broken.

Further down when I use the module like this:

Screen Shot 2022-06-05 at 4 25 56 PM

It gives me this weird error I do not get when I run my code. This code is supported by a Raku Grammer, so that may be related:

Screen Shot 2022-06-05 at 4 23 37 PM

Again, works fine when I run it, just that vscode thinks it's broken and underlines it with red.

bscan commented 2 years ago

Thanks for the report. Digging in now. I checked out the BDD::Behave repo from github and am able to reproduce the errors:

image

For the first error, when the Navigator gets an error from the Rakudo parser but can't figure out which line to place it on, it will place it on the first line of the file, regardless of content. I'll need to dig into that particular error.

However, for the expect errors, I get those even when simply running the script directly.

===SORRY!===
Calling expect(Int) will never work with declared signature ()
at /tmp/test.raku:7
------>     ⏏expect(42).to.be(42);
Calling expect(Int) will never work with declared signature ()
at /tmp/test.raku:13
------>     ⏏expect(42).to.be(41);

I believe this is because Behave.rakumod includes the line sub expect is export {}. When I create a module for testing that contains only:

sub expect is export {}

sub expectWithArgs($foo) is export {
    print $foo*2;
}

I get the same errors on expect, but not on expectWithArgs image

My guess is that you are running the script differently than the Navigator in terms of the Raku path, include paths, or environment variables that the Navigator is not picking up. If you view the Raku Navigator logs, it will show the command it uses for compiling and parsing the file. Try running that command manually and see if you still generate the same errors. It works by piping the source code into the parser, which passes back some formatted errors and symbols. The stdin piece is necessary to allow the language server to work without requiring saving the file. Let me know what you find. For completeness, my raku --version is:

Welcome to Rakudo™ v2022.04.
Implementing the Raku® Programming Language v6.d.
Built on MoarVM version 2022.04.

image

Thanks again for helping work through some of these potential issues.

bscan commented 2 years ago

@gdonald , looking more into this, it appears that the BDD spec files are supposed to be run with the executable behave script, and don't work when running with raku directly. If that's the case, it sounds like these files aren't supposed to be valid Raku syntax at all, but spec files instead. Thoughts?

gdonald commented 2 years ago

BDD::Behave is a Grammar, yes.

bscan commented 2 years ago

In that case, it seems like .raku is not really the appropriate extension for these files as they don't actually contain Raku code. This seems analogous to the Gherkin language with it's own syntax that is often integrated into testing frameworks. https://en.wikipedia.org/wiki/Cucumber_(software)#Gherkin_language . One solution could be a custom language or extension for these types of spec files.

It might also be nice to have a live grammar preview tool similar to the one in CommaIDE: https://commaide.com/docs/grammar-live-view . I haven't used it, but it looks useful for debugging arbitrary grammars and their input files. For building in vscode, perhaps it could look similar to this: https://github.com/chrmarti/vscode-regex . Either way, it's probably a bit too far out of scope for me.