VSCode as a Perl IDE
Dean Hamstead
Posted on June 5, 2021
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!
Posted on June 5, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.