bscan / PerlNavigator

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

More Sublime Text experience from anyone? #74

Open nugged opened 1 year ago

nugged commented 1 year ago

Tried to install it manually, and lost a whole day to make Perl::Critic work but nope. It works in vscode out of the box, but not in ST4. Sigh.

bscan commented 1 year ago

Hi @nugged, sorry for the painful experience here. I agree it's certainly easier to get running in vscode, as vscode provides the node.js runtime, but the Navigator works in Sublime Text as well. I just tested using Sublime Text 4 with the latest binary release (tested on Windows) and it worked for me, including Perl::Critic. Binary from here: https://github.com/bscan/PerlNavigator/releases/tag/v0.5.5

I downloaded a fresh copy of ST4, installed the LSP client, and used these settings.

{
    "clients": {
        "perlnavigator": {
            "enabled": true,
            "command": ["D:\\Applications\\perlnavigator.exe","--stdio"],
            "selector": "source.perl",
            "settings": {
                 "perlnavigator.perlPath": "c:\\path\\to\\perl.exe",
            }
        },
    }
}

What platform are you using? Are you seeing any errors? Or any perl compilation results?

nugged commented 1 year ago

MacOS (M1)

I did:

cd ~/git/PerlNavigator
npm run ci-all
cd server
npx tsc

I build it (main), it works well regarding syntax errors & warnings. It sees perlbrew's perl successfully, even. With no other specials

        "perlnavigator": {
            "enabled": true,
            "command": ["node", "~/git/PerlNavigator/server/out/server.js","--stdio"],
            "selector": "source.perl",
            "settings": {
                "perlnavigator.perlcriticEnabled": true,
                "perlnavigator.enableWarnings": true,
                "perlnavigator.perlcriticSeverity": 3
        },

then code:

#!/bin/env perl
use warnings; use strict; use 5.30.0; use utf8;
binmode STDOUT, ":encoding(UTF-8)"; $| = 1;

our $ThisOus = "It Is!";

my $abc = "It Is also never used!";

BEGIN { 
    warn "Warning iside BEGIN!";
    warn "I am Perl $^V ($]) and located " . ($^X =~ s|.+/perl5|~/perl5|r);
}

syntax_error

in ST4: image

but in opposition to vscode: image

it doesn't give anything from Perl::Critic (vscode does).

What I tried manually inside the guts:

$>cat /tmp/info.pl | perl criticWrapper.pl -f criticWrapper.pl

Perlcritic on criticWrapper.pl and using profile $HOME/.perlcriticrc
Perl Critic violations:
3~|~2~|~27~|~Version string used~|~ValuesAndExpressions::ProhibitVersionStrings~||~
4~|~3~|~40~|~Magic variable "$|" should be assigned as "local"~|~Variables::RequireLocalizedPunctuationVars~||~
3~|~5~|~1~|~Package variable declared or used~|~Variables::ProhibitPackageVars~||~
3~|~10~|~5~|~"warn" used instead of "carp"~|~ErrorHandling::RequireCarping~||~
3~|~11~|~5~|~"warn" used instead of "carp"~|~ErrorHandling::RequireCarping~||~
3~|~11~|~54~|~Regular expression without "/x" flag~|~RegularExpressions::RequireExtendedFormatting~||~

but I lost how to debug full chain why it drowns somewhere in ST4 guts

bscan commented 1 year ago

Unfortunately, I have not been able to reproduce. I installed the latest version of Perl Navigator on a Mac and Perl::Critic worked for me. I tested with the MacOS binary and with building from source. However, I got logging working in Sublime Text if you update to the latest version of Perl Navigator and enable perlnavigator.logging. Hopefully more details are available with the log. Thanks!

    "settings": {
         "perlnavigator.logging": true,
    }
image
nugged commented 1 year ago

Yeah, I tried logging, but in Sublime, it's not THAT trivial :). That's why calling for ideas on how I can inject my code somewhere to debug deeper into why in ST4 it's acting up.

Saying this: it DOES NOT log into the console in ST4.

nugged commented 1 year ago

Woohooo!!!! :)

image

LSP-config:

// Settings in here override those in "LSP/LSP.sublime-settings"
{
    "log_debug": false,
    "clients": {
        "LSP-perl": {
            "enabled": true,
            "selector": "source.perl",
            "command": ["node", "~/git/PerlNavigator/server/out/server.js","--stdio"],
            "settings": {
                "perlnavigator.enableWarnings": true,
                "perlnavigator.perlcriticEnabled": true,
            },
        },
    }
}

On the dozen-one iteration, it started to work, but I am still unsure in which place something changed "to be right instead of to be wrong".

Ok, good.

UPDATE: it even works with simplified config, all the rest by default:

// Settings in here override those in "LSP/LSP.sublime-settings"
{
    "clients": {
        "LSP-perl": {
            "enabled": true,
            "selector": "source.perl",
            "command": ["node", "~/git/PerlNavigator/server/out/server.js","--stdio"],
        },
    }
}

And works well with .bash-profiled Perl (perlbrew), catching up the proper Perl and modules.

image

nugged commented 1 year ago

Now next step is to find out how to make PerlTidy work from it. It works in VSCode, not yet in Sublime :P.

UPDATE: ... still have not succeeded yet.

bscan commented 1 year ago

Sounds like progress is happening. Thanks for continuing to work on this. Pertidy works for me in both "Format Selection" and "Format File" modes on Sublime Text. Regarding logging, I just fixed the logging capabilities for ST4 last night, so you'll need to grab the latest version of Perl Navigator (and enable logging in the settings). Then it will show up in the "LSP: Toggle Log Panel".

perltidy

nugged commented 1 year ago

Whoa! Logging capabilities will help. Let's see, I'll check now why it fails on Tidy now for me.