Overview
The VSCode IDE implements it's language support via the Language Server Protocol which is designed to cleanly separate language support from the editor. For Perl a fully functional language server is implemented in Perl::LanguageServer and will work with any LSP capable editor.
VSCode can edit both locally or in a remote environment. This brief guide will get you started editing locally (i.e. on your desktop or laptop), however the Perl VSCode extension and Perl's LanguageServer will work in either scenario.
Install a Perl interpreter for development
Although a Perl interpreter is likely already installed (i.e. system perl) on Linux , BSD, or MacOS the best practice is to leave if for the system to use and install your own interpreter for your development work. On Windows you likely will install Strawberry Perl.
Please follow this guide to installing a perl interpreter for your development.
Install Perl's LanguageServer
Assuming cpanm is installed, simply run:
cpanm Perl::LanguageServer
That's it. The Perl LanguageServer is now ready.
Install VSCode (actually VSCodium)
VSCodium is the fully-foss version of VSCode (think Chromium). I recommend you install VSCodium rather than VSCode.
Fedora, SuSE, and the Debian family of Linux distributions can install from this maintained repo.
For other OS including MacOS and Windows simply pick your favourite approach from the official install instructions
Install the Perl extension for VSCode
Run VSCode (VSCodium) and using the familiar "File -> Open" interface, open a Perl source file. Observe that whilst syntax highlighting is available already via the built-in "Perl Language Basics" plugin, actual IDE functions do not - i.e. try "Run -> Start Debugging".
We need to configure VSCode to use our Perl LanguageServer by installing the Perl extension. The good news is that the extension is in the official VS Marketplace making it very quick and easy.
In actual VSCode the quickest route is hit Ctrl-P
then type:
ext install richterger.perl
You could also click "File -> Preferences -> Extensions" then search for "perl" and click install.
In VSCodium the Open VSX registry is used which doesn't yet include the perl extensions.
From the VS Marketplace plugin page download the extension with the "Download Extension" link on the right hand side.
On your local system's command line (there is no need to close VSCodium), change directory to your downloads and run:
codium --install-extension richterger.perl-*.vsix
Returning to VSCode or VSCodium, observe that the Perl extension is now installed in the extensions list ("File -> Preferences -> Extensions" or Ctrl-Shift-X
)
Open a Perl source file, click "Run -> Start Debugging" or hit F5
and observe there is no error as before.
Now explore all VSCocde IDE functions working nicely with Perl!
Top comments (24)
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.
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.
Thank you!
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!
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
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.
There are markdown typos in two links and the article says "cpan Perl::LanguageServer" instead of "cpanm Perl::LanguageServer"
Fixed. Thanks
Some of the links still show the markdown.
I think i have got them all now.
cpanm is still in the post.
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.
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:
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.
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...
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.
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 ;^)
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...
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