Installing Perl in VSCode
Asked Answered
A

2

7

I am trying to go back in time a little and play around with Perl once again. I have a Mac and VSCode installed and did the following:

  • brew install perl to install perl
    • this installs perl at /opt/homebrew/bin/perl and perl --version returns "This is perl 5, version 34, subversion 0 (v5.34.0) built for darwin-thread-multi-2level"
  • cpanm Perl::LanguageServer to install the language server
  • and in VSCode I install the Perl extension by Gerald Richter (v2.3.0)

However, when I open create a new text file and set Perl as the file's language, I get the following error message:

ListUtil.c: loadable library and perl binaries are mismatched (got handshake key 0xc700080, needed 0xfb80080)
[Info  - 12:52:54 PM] Connection to server got closed. Server will restart.
ListUtil.c: loadable library and perl binaries are mismatched (got handshake key 0xc700080, needed 0xfb80080)
[Info  - 12:52:54 PM] Connection to server got closed. Server will restart.
ListUtil.c: loadable library and perl binaries are mismatched (got handshake key 0xc700080, needed 0xfb80080)
[Info  - 12:52:54 PM] Connection to server got closed. Server will restart.
ListUtil.c: loadable library and perl binaries are mismatched (got handshake key 0xc700080, needed 0xfb80080)
[Info  - 12:52:54 PM] Connection to server got closed. Server will restart.
ListUtil.c: loadable library and perl binaries are mismatched (got handshake key 0xc700080, needed 0xfb80080)
[Error - 12:52:54 PM] Connection to server got closed. Server will not be restarted.

FOLLOW-UP:

In the meantime I uninstalled homebrew perl (brew uninstall perl), and rely on the already installed /usr/bin/perl ("This is perl 5, version 30, subversion 3 (v5.30.3) built for darwin-thread-multi-2level").

Using this version, I could install the language server and get it to run in VSCode. All I needed to do is select "File"->"Save Workspace As" to assign the ${workspace} variable of VSCode.

However, now I run into a new problem, as when I press F-5 (Run), I get the following error message:

Can't locate Perl/LanguageServer/DebuggerInterface.pm in @INC (you may need to install the Perl::LanguageServer::DebuggerInterface module) (@INC contains: /Library/Perl/5.30/darwin-thread-multi-2level /Library/Perl/5.30 /Network/Library/Perl/5.30/darwin-thread-multi-2level /Network/Library/Perl/5.30 /Library/Perl/Updates/5.30.3 /System/Library/Perl/5.30/darwin-thread-multi-2level /System/Library/Perl/5.30 /System/Library/Perl/Extras/5.30/darwin-thread-multi-2level /System/Library/Perl/Extras/5.30).
BEGIN failed--compilation aborted.

The library in question in ~/perl5/lib/perl5/Perl/LanguageServer. I assume I would have to add this directory to the module search path of VSCode - however not sure how.

FOLLOW-UP 2:

The module path can be added in the settings.json file belonging to the module. To get there click on "Perl" in the lower right corner of VSCode, and select "Configure 'Perl' based language settings" in the menu that pops up. This opens the settings.json file.

Once there, add the following line:

"perl.perlInc": [ "/Users/divingtobi/perl5/lib/perl5" ],

and you should be good to go. For some reason it has to be the full path, and ~/ is not interpolated.

Ashleaashlee answered 9/8, 2022 at 11:1 Comment(5)
I believe I came a step further. The perl I installed using brew install perl does not go together with the LanguageServer. Once I run brew uninstall perl; cpanm uninstall Perl::LanguageServer, and then just run cpan install Perl::LanguageServer (notice cpan... vs. cpanm...), I can create a file without the language server crashing. Next problem is that launching the file will open a dialog Variable ${workspaceFolder} can not be resolved. Please open a folder. -> Open 'launch.json'. And there i do not see how I can open a folder or what is meant.Ashleaashlee
I'd guess this is a version incompatibility thing. This post describes a similar issue.Fash
The README of the repo of the extension says, it is [o]nly tested with Perl 5.18 and newer. So in case you want to use is with older versions of Perl slight modifications might be necessary.Fash
@TorgeRosendahl: But he's using Perl 5.34 which is newer than 5.18.Torino
parallel brew perl is no problem see my answer. @DaveCross I use on OSX Perl 5.30.3 - it work fine with Perl::LanguageServerSiegbahn
B
7

On Ventura(13.1) this works for me:

  1. Open system's default Terminal(Terminal.app). NOTE: Don't use vscode's terminal. We will use system's own perl (v5.30.3). I assume you've already installed the perl extension.
  2. brew install cpanm. I don't know why we're using cpanm instead of cpan but I see it everywhere so I thought I'd use it too.
  3. cpanm Perl::LanguageServer. This will fail but it's expected. It'll prompt you to set up cpan stuff. Set it up as default. Note that it'll probably say something like "Can't write to /Library/Perl/5.30 and /usr/local/bin: Installing modules to /Users/<username>/perl5". Remember this because vscode will mess up and miss this path.
  4. cpanm --force AnyEvent::AIO. It's a dependency of Perl::LanguageServer.
  5. cpanm --force Coro. It's a dependency of Perl::LanguageServer.
  6. cpanm Perl::LanguageServer. Install the actual language server.
  7. Go to vscode. Open settings. Search for "perlinc". Press "Edit in settings.json".
  8. perl -e "print \"@INC\";" | grep "/Users/<username>/perl5". @INC stores the module search paths and we're looking for the paths that store what cpan installs. Note down the paths that contain "/Users/<username>/perl5". For my example output, the first four paths are what we're looking for.
/Users/<username>/perl5/lib/perl5/5.30.3/darwin-thread-multi-2level /Users/<username>/perl5/lib/perl5/5.30.3 /Users/<username>/perl5/lib/perl5/darwin-thread-multi-2level /Users/<username>/perl5/lib/perl5 /Library/Perl/5.30/darwin-thread-multi-2level /Library/Perl/5.30 /Network/Library/Perl/5.30/darwin-thread-multi-2level /Network/Library/Perl/5.30 /Library/Perl/Updates/5.30.3 /System/Library/Perl/5.30/darwin-thread-multi-2level /System/Library/Perl/5.30 /System/Library/Perl/Extras/5.30/darwin-thread-multi-2level /System/Library/Perl/Extras/5.30
  1. Input those paths into the perlInc in settings.json.
  "perl.perlInc": ["/Users/<username>/perl5/lib/perl5/5.30.3/darwin-thread-multi-2level",
                   "/Users/<username>/perl5/lib/perl5/5.30.3",
                   "/Users/<username>/perl5/lib/perl5/darwin-thread-multi-2level",
                   "/Users/<username>/perl5/lib/perl5"]
  1. Reload vscode and you're done! Now you can use go-to-def or go-to-refs and all that jazz.

I figured this out from this thread and that comment in particular points out the problem: vscode's perl has different module search paths than those of terminal's perl. You can see this from doing perl -e "print \"@INC\";" in both of them to see the difference.

Bandeen answered 14/3, 2023 at 18:48 Comment(0)
S
3

On OS/X 12.6:

  1. open cpan
  2. cpan[1]> force install AnyEvent::IO (ignore warnings)
  3. cpan[2]> force install Coro (ignore warnings)
  4. cpan[3]> install Perl::LanguageServer
  5. start VSC
  6. install perl extention
  7. have fun with perl & VSC
Siegbahn answered 15/11, 2022 at 14:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.