bscan / PerlNavigator

Perl Language Server that includes syntax checking, perl critic, and code navigation
MIT License
206 stars 40 forks source link

Feature Request: exceptions for warning in the code #136

Open Reissner opened 3 months ago

Reissner commented 3 months ago

I am working on something special but still the feature request seems to be more general useful. I have a perl file which is read in by another software, it is the config file .latexmkrc which is read by latexmk. As a result, there are some variables read only once and this leads to a warning. I dont want to disable this in general, nor in the profile, but just for this file, and maybe only at a specific place.

chktex has an interesting technique: Just at the critical line start a comment and include chktex num, where num is a number. In perl and perlnavigator one would exclude warning via

$bibtex='bibtexu %O';# perlnavigator 15

if the warning has identifier 15.

Of course to make this work, each of the warnings must be endowed with an identifier for the kind of warning.

bscan commented 2 months ago

I'd recommend using no warnings 'once'; in your file if you want to disable this warning. This can also be localized to a specific function or code block as needed. It's the simplest fix and localizes it only to this file.

Perl Navigator always enables warnings even when you don't use warnings in your code, which may add to the confusion. You can disable this behavior by setting "perlnavigator.enableWarnings": false, if you want it to apply to all files.

The issue with disabling compiler warnings via code comments is that they'll still print warnings when the code is run (unlike perlcritic warnings for example). Plus, they'll still show up if anyone is using a different tool that still calls perl -c for syntax checking (e.g. flycheck or another language server).

There are also perlcritic warnings that may need to be disabled depending on your particular profile and set of installed policies. Those can be disabled via ## no critic (PolicyName) if needed.

As a side note, the Perl Navigator does support some code comments for typing, so I'm not opposed to the concept of using comments as instructions. For example:

use LWP::UserAgent;
my $ua = LWP::UserAgent->new(timeout => 10);
my $res= $ua->get( $url );    # $res isa HTTP::Response

And this will enable autocompletion of methods available on $res, and improve the accuracy of go-to definition on any $res-> methods. I like this format because it's also a meaningful comment for people not using the Perl Navigator.