Subject: | env not properly handled in Perl/LanguageServer/DebuggerProcess.pm |
From: | github [...] jason-gouger.com |
When passing the "env" : [ "VAR1=VALUE1", "VAR2=VALUE2" ] from the VSCode launch.json debug settings the perl module throws and error about being an incorrect type.
https://metacpan.org/source/GRICHTER/Perl-LanguageServer-2.0.2/lib/Perl/LanguageServer/DebuggerProcess.pm#L128
It would also be nice if the module preserved some of the PERL related env settings in the current env before wiping the environment. Specifically the PERL5LIB variable to allow the module to be located if it is outside of the normal perl installation.
Here is a potential solution :
sub lauch
{
my ($self, $workspace, $cmd) = @_ ;
my $fn = $workspace -> file_client2server ($self -> program) ;
my $pid ;
{
my %env;
for ('PERL5LIB', 'PERLLIB')
{
$env{$_} = $ENV{$_} if (defined $ENV{$_});
}
local %ENV ;
for (keys(%env))
{
$ENV{$_} = $env{$_};
}
foreach (@{$self -> env})
{
if (m/^(.*?)=(.*)$/) {
$ENV{$1} = $2 ;
}
}
$ENV{PLSDI_REMOTE} = '127.0.0.1:' . $self -> debug_adapter -> listen_port ;
$ENV{PLSDI_OPTIONS} = $self -> reload_modules?'reload_modules':'' ;
$ENV{PERL5DB} = 'BEGIN { require Perl::LanguageServer::DebuggerInterface }' ;
$ENV{PLSDI_SESSION}= $self -> session_id ;
$pid = $self -> run_async ([$cmd, '-d', $fn, @{$self -> args}]) ;
}
$self -> pid ($pid) ;
$self -> send_event ('process',
{
name => $self -> program,
systemProcessId => $pid,
isLocalProcess => JSON::true(),
startMethod => 'launch',
}) ;
return ;
}