DEV Community

VSCode as a Perl IDE

Dean Hamstead on June 05, 2021

Overview The VSCode IDE implements it's language support via the Language Server Protocol which is designed to cleanly separate language...
Collapse
 
peterdragon profile image
Peter Edwards

Nice article!
I've got VSC working from my Mac remoting into a virtualbox Linux VM.
Perl::LanguageServer was requiring perl 5.18.
We are using Centos/RHEL 7 with system perl 5.16.3 and I have modified Perl::LanguageServer so it will run on 5.16.
github.com/richterger/Perl-Languag...
Might of interest @davehodg.

Collapse
 
johntocher profile image
John Tocher

This nearly got me there. Getting the perl language server installed was a pain point for me. For others stumbling on this page, on ubuntu linux 20.04 LTS, the process for me was:

(The following three may not be necessary if you've already got your computer configutred for development, but for a fresh isntall I was helping someone else with, this was necessary).

sudo apt update
sudo apt upgrade
sudo apt install build-essential

The missing library I needed was installed with:
sudo apt install libanyevent-perl libio-aio-perl

I found this from the following source if you would like more details:
github.com/richterger/Perl-Languag...

Then I could successfully install the language server with:
sudo cpan Perl::LanguageServer

VS code would then successfully install the plugin and run as expected.

Collapse
 
kaicarver profile image
Kai Carver

Thank you!

Collapse
 
andrewsolomon profile image
Andrew Solomon • Edited

There are two grant proposals in the area of Perl IDEs which have been bouncing around. If anyone's interested in working on one of these, please get in touch!

Collapse
 
rwp0 profile image
Elvin Aslanov • Edited

If on Windows, this can be run on WSL to debug Perl programs.

Basically what it does, provides an easy way to view your Local, Global, Special, Arguments and variables.

marketplace.visualstudio.com/items...

wsl --install Ubuntu

sudo apt install libanyevent-perl libclass-refresh-perl libcompiler-lexer-perl \
  libdata-dump-perl libio-aio-perl libjson-perl libmoose-perl libpadwalker-perl \
  libscalar-list-utils-perl libcoro-perl

sudo cpan Perl::LanguageServer
Enter fullscreen mode Exit fullscreen mode
Collapse
 
toddbruner profile image
Todd Bruner

Great guide, thank you.
I followed this guide to get this working on a Ubuntu 22 VM.
At first many errors with Perl, LanguageServer, and many modules due to using a custom local perl instance installed in /opt/perl.
Here's what the settings.json file looks like to fix:
{
"perl.perlInc": [
"/opt/perl/lib/5.34.1",
"/opt/perl/lib/5.34.1/x86_64-Linux",
"/opt/perl/lib/site_perl/5.34.1",
"/opt/perl/lib/site_perl/5.34.1/x86_64-linux"
],
"perl.perlCmd": "/opt/perl/bin/perl"
}

Obvious, now, but hopefully this helps someone in the future.

Collapse
 
szabgab profile image
Gabor Szabo • Edited

There are markdown typos in two links and the article says "cpan Perl::LanguageServer" instead of "cpanm Perl::LanguageServer"

Collapse
 
perldean profile image
Dean Hamstead

Fixed. Thanks

Collapse
 
szabgab profile image
Gabor Szabo

Some of the links still show the markdown.

Thread Thread
 
perldean profile image
Dean Hamstead

I think i have got them all now.

Thread Thread
 
dzooli profile image
Zoltan Fabian

cpanm is still in the post.

Collapse
 
randalschwartz profile image
Randal L. Schwartz

Perl::LanguageServer must be rather persnickety to install. I have not had success installing this for either my primary macos system, or my client's centos machnine. Sad.

Collapse
 
adefaria profile image
Andrew DeFaria

The problem for me, Ubuntu 22.04, was that I didn't have the libperl-dev package installed. I found this by looking in the config.log for IO-AIO-4.76:

configure:2725: x86_64-linux-gnu-gcc -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include -I/usr/lib/x86_64-linux-gnu/perl/5.34/CORE  -fstack-protector-strong -L/usr/local/lib -Wl,-E conftest.c -L/usr/lib/x86_64-linux-gnu/perl/5.34/CORE -L/usr/share/perl/5.34 -lperl -ldl -lm -lpthread -lc -lcrypt >&5
/bin/ld: cannot find -lperl: No such file or directory
collect2: error: ld returned 1 exit status
Enter fullscreen mode Exit fullscreen mode

Apparently libperl does not get installed unless you install the dev package for libperl. Kinda makes sense since this LanguageServer is about debugging your Perl scripts thus you're a dev.

Collapse
 
boris_new_968b8684019da0f profile image
Boris New

I could not install on my Macbook M1 neither with Perl base install nor MacPorts but it installed without problem with Homebrew Perl... (once I made sure perlbrew was the new default perl).
Hope it will help someone...

 
peterdragon profile image
Peter Edwards • Edited

Of course, explain it to our customers too. One is List X MOD. Maybe they will welcome your insight.
Within 30 minutes of posting I had another person replying they were trying my fix.
It doesn't do to assume everyone else has the freedom and expert knowledge you have to implement solutions.
One of the reasons perl is going down is no-one thinks about these "hygiene factors" [Henry Mintzberg] which actually put a lot of people off perl because they are: too unread, too stupid, too lazy. We should address that. Using the system perl is part of making people's lives easy. We don't really have a choice, unfortunately.

Collapse
 
peterdragon profile image
Peter Edwards

Your customers are Security Cleared and require RedHat security releases.
Which include patches to perl modules to make the yum rpm modules safe?
So no to using stock CPAN perl modules. Thought not.
BTW hope you are keeping well ;^)

Collapse
 
rhopkins7428 profile image
rhopkins7428

Love VSCode with Perl (even with Windows 10) , but can't get language server to work with Windows 10,(strawberry Perl) seems to be a known problem with running on windows platform

github.com/richterger/Perl-Languag...

Collapse
 
perldean profile image
Dean Hamstead

I dont personally use windows, so i have made an assumption that turns out to be wrong. Your best bet might be to develop in a remote linux or bsd vm. Be that actually remotely or on a vm running locally

Collapse
 
davehodg profile image
Dave Hodgkinson

Great article. Now I'd like a recipe book of useful things you can do with it. I've also got perl-toolbox installed which has a nice interface to perlcritic.

Collapse
 
sigzero profile image
sigzero

You can also install the extension by using the command palette and selecting "Extensions: Install from VSIX...".

Collapse
 
perldean profile image
Dean Hamstead

I did not know this, thanks!

Collapse
 
sigzero profile image
sigzero

You are very welcome.

Collapse
 
otalado profile image
otalado

I've tried the steps above in Widows11 both with VsCode and with VsCodium. Yet (in both), when I try to debug a Perl script it just shows the debug toolbar for a few seconds and nothing else happens. The VsCode version is 1.74.3 and the VsCodium is at the same version.
Jus to be sure I did not make any stuid errors, I uninstalled thr perl, VsCode and VsCodium and repeated whole procedure again, sadly with same result.
As I can run/debug perl scripts in Activestate Komodo I think perl is not the culprit.
Any ideas how should I troubleshoot?

Collapse
 
surajmandal profile image
Suraj_Mandal

I have successfully run the Perl::LanguageServer but not able to get the code-autocompletion feature