Perl setup in visual code

Visual code Perl Extension

When launching visual code on Ubuntu 22.04, an annoying issue for the Perl extension always happens:

Can't locate Perl/LanguageServer.pm

The root cause is that Perl 5.34 hasn't been configured with LanguageServer 2.6.2 required. However, when installing via

cpanm Perl::LanguageServer --force

you will encounter another issue for IO::AIO

Fetching http://www.cpan.org/authors/id/M/ML/MLEHMANN/IO-AIO-4.81.tar.gz ... OK
Configuring IO-AIO-4.81 ... N/A
! Configure failed for IO-AIO-4.81. See /data/orlando/.cpanm/work/1712601891.4691/build.log for details.
! Installing the dependencies failed: Module 'IO::AIO' is not installed
! Bailing out the installation for AnyEvent-AIO-1.1.

The reason behind is the system-wide Perl needs to be upgraded in sudo mode with dependencies configured well.

Reference: https://gist.github.com/hakonhagland/15800c09d36ba8ee034ca1b962ad33e2

To be specific, follow-up like below:

  1. Install build tools
sudo apt-get install libperl-dev

2. Install cpanm

sudo apt-get install cpanminus

3. Install Perl::LanguageServer

sudo /usr/bin/cpanm Perl::LanguageServer

The key is to install  libperl-dev and use /usr/bin/cpanm in the system path. Now, no more "Perl/LanguageServer.pm" issue. You should see the output in Visual code's Perl Language Server after connecting:

tcp server start listen on port 13603
LS: apply_all_roles (Perl::LanguageServer=HASH(0x55f5d651be00), Perl::LanguageServer::Methods, Perl/LanguageServer/Methods.pm)
LS: apply_all_roles (Moose::Meta::Class::__ANON__::SERIAL::1=HASH(0x55f5d651be00), Perl::LanguageServer::Methods::workspace, Perl/LanguageServer/Methods/workspace.pm)
LS: perl = do {
  my $a = {
    cacheDir               => undef,
    containerArgs          => undef,
    containerCmd           => undef,
    containerMode          => "exec",
    containerName          => undef,
    ctagsEnabledFolders    => [],
    ctagsFile              => ".vstags",
    ctagsPath              => "ctags",
    debugAdapterPort       => 13603,
    debugAdapterPortRange  => 100,
    disableCache           => bless(do{\(my $o = 0)}, "JSON::PP::Boolean"),
    disablePassEnv         => undef,
    enable                 => bless(do{\(my $o = 1)}, "JSON::PP::Boolean"),
    env                    => undef,
    extraProjectCtagsArgs  => ["--extra=+q"],
    fileFilter             => undef,
    ignoreDirs             => undef,
    logFile                => undef,
    logLevel               => 0,
    maxSymbolResults       => 500,
    pathMap                => undef,
    perlCmd                => undef,
    perlInc                => undef,
    perltidy               => "perltidy",
    perltidyArgs           => [
                                "-q",
                                "-et=4",
                                "-t",
                                "-ce",
                                "-l=0",
                                "-bar",
                                "-naws",
                                "-blbs=2",
                                "-mbl=2",
                              ],
    perltidyContainer      => "",
    showLocalVars          => 'fix',
    sshAddr                => undef,
    sshArgs                => undef,
    sshCmd                 => undef,
    sshPort                => undef,
    sshUser                => undef,
    sshWorkspaceRoot       => undef,
    useTaintForSyntaxCheck => 'fix',
  };
  $a->{showLocalVars} = \${$a->{disableCache}};
  $a->{useTaintForSyntaxCheck} = \${$a->{disableCache}};
  $a;
}
LS: log_level = 0
LS: path_map = undef
LS: perlinc = undef
LS: use_taint_for_syntax_check = bless(do{\(my $o = 0)}, "JSON::PP::Boolean")
LS: file_filter_regex = "(?:\\.pm|\\.pl)\$"
LS: ignore_dir = { ".git" => 1, ".svn" => 1, ".vscode" => 1 }
state_dir = /data/orlando/workspace/AndroidAgentModelZoo/.vscode/perl-lang
LS: background_parser folders = {
  "file:///data/orlando/workspace/AndroidAgentModelZoo" => "/data/orlando/workspace/AndroidAgentModelZoo",
}
LS: initial parsing done, loaded  files, parsed  files, 0 files

In my case, it's trying to load a JSON file and do parsing.