DEV Community

Dean Hamstead
Dean Hamstead

Posted on • Updated on

VSCode as a Perl IDE

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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 
Enter fullscreen mode Exit fullscreen mode

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!

Discussion (12)

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
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 Author

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
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
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 Author

I did not know this, thanks!

Collapse
sigzero profile image
sigzero

You are very welcome.

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 Author

Fixed. Thanks

Collapse
szabgab profile image
Gabor Szabo

Some of the links still show the markdown.

Thread Thread
perldean profile image
Dean Hamstead Author

I think i have got them all now.

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.