File Coverage

blib/lib/Perl/LanguageServer.pm
Criterion Covered Total %
statement 59 293 20.1
branch 0 146 0.0
condition 0 27 0.0
subroutine 20 38 52.6
pod 1 8 12.5
total 80 512 15.6


line stmt bran cond sub pod time code
1             package Perl::LanguageServer;
2              
3 1     1   67613 use v5.16;
  1         4  
4              
5 1     1   5 use strict ;
  1         2  
  1         19  
6 1     1   633 use Moose ;
  1         474840  
  1         6  
7 1     1   7699 use Moose::Util qw( apply_all_roles );
  1         3  
  1         9  
8              
9 1     1   1180 use Coro ;
  1         10377  
  1         74  
10 1     1   498 use Coro::AIO ;
  1         19271  
  1         279  
11 1     1   567 use Coro::Handle ;
  1         33471  
  1         62  
12 1     1   10 use AnyEvent;
  1         8  
  1         24  
13 1     1   6 use AnyEvent::Socket ;
  1         2  
  1         78  
14 1     1   742 use JSON ;
  1         9853  
  1         5  
15 1     1   723 use Data::Dump qw{dump pp} ;
  1         5001  
  1         61  
16 1     1   582 use IO::Select ;
  1         1702  
  1         45  
17              
18 1     1   457 use Perl::LanguageServer::Req ;
  1         2  
  1         38  
19 1     1   543 use Perl::LanguageServer::Workspace ;
  1         4  
  1         77  
20              
21             with 'Perl::LanguageServer::Methods' ;
22             with 'Perl::LanguageServer::IO' ;
23              
24 1     1   11 no warnings 'uninitialized' ;
  1         3  
  1         623  
25              
26             =head1 NAME
27              
28             Perl::LanguageServer - Language Server and Debug Protocol Adapter for Perl
29              
30             =head1 VERSION
31              
32             Version 2.5.0
33              
34             =cut
35              
36             our $VERSION = '2.6.1';
37              
38              
39             =head1 SYNOPSIS
40              
41             This is a Language Server and Debug Protocol Adapter for Perl
42              
43             It implements the Language Server Protocol which provides
44             syntax-checking, symbol search, etc. Perl to various editors, for
45             example Visual Studio Code or Atom.
46              
47             L<https://microsoft.github.io/language-server-protocol/specification>
48              
49             It also implements the Debug Adapter Protocol, which allow debugging
50             with various editors/includes
51              
52             L<https://microsoft.github.io/debug-adapter-protocol/overview>
53              
54             Should work with any Editor/IDE that support the Language-Server-Protocol.
55              
56             To use both with Visual Studio Code, install the extension "perl"
57              
58             Any comments and patches are welcome.
59              
60             =cut
61              
62             our $json = JSON -> new -> utf8(1) -> ascii(1) ;
63             our $jsonpretty = JSON -> new -> utf8(1) -> ascii(1) -> pretty (1) ;
64              
65             our %running_reqs ;
66             our %running_coros ;
67             our $exit ;
68             our $workspace ;
69             our $dev_tool ;
70             our $debug1 = 0 ;
71             our $debug2 = 0 ;
72             our $log_file ;
73             our $client_version ;
74             our $reqseq = 1_000_000_000 ;
75              
76              
77             has 'channel' =>
78             (
79             is => 'ro',
80             isa => 'Coro::Channel',
81             default => sub { Coro::Channel -> new }
82             ) ;
83              
84             has 'debug' =>
85             (
86             is => 'rw',
87             isa => 'Int',
88             default => 1,
89             ) ;
90              
91             has 'listen_port' =>
92             (
93             is => 'rw',
94             isa => 'Maybe[Int]',
95             ) ;
96              
97             has 'roles' =>
98             (
99             is => 'rw',
100             isa => 'HashRef',
101             default => sub { {} },
102             ) ;
103              
104             has 'out_semaphore' =>
105             (
106             is => 'ro',
107             isa => 'Coro::Semaphore',
108             default => sub { Coro::Semaphore -> new }
109             ) ;
110              
111             has 'log_prefix' =>
112             (
113             is => 'rw',
114             isa => 'Str',
115             default => 'LS',
116             ) ;
117              
118             has 'log_req_txt' =>
119             (
120             is => 'rw',
121             isa => 'Str',
122             default => '---> Request: ',
123             ) ;
124              
125             # ---------------------------------------------------------------------------
126              
127             sub logger
128             {
129 0     0 0   my $self = shift ;
130 0           my $src ;
131 0 0 0       if (!defined ($_[0]) || ref ($_[0]))
132             {
133 0           $src = shift ;
134             }
135 0 0         $src = $self if (!$src) ;
136              
137 0 0         if ($log_file)
138             {
139 0 0         open my $fh, '>>', $log_file or warn "$log_file : $!" ;
140 0 0         print $fh $src?$src -> log_prefix . ': ':'', @_ ;
141 0           close $fh ;
142             }
143             else
144             {
145 0 0         print STDERR $src?$src -> log_prefix . ': ':'', @_ ;
146             }
147             }
148              
149              
150             # ---------------------------------------------------------------------------
151              
152             sub send_notification
153             {
154 0     0 0   my ($self, $notification, $src, $txt) = @_ ;
155              
156 0   0       $txt ||= "<--- Notification: " ;
157 0           $notification -> {jsonrpc} = '2.0' ;
158 0           my $outdata = $json -> encode ($notification) ;
159 0           my $guard = $self -> out_semaphore -> guard ;
160 1     1   12 use bytes ;
  1         3  
  1         10  
161 0           my $len = length($outdata) ;
162 0           my $wrdata = "Content-Length: $len\r\nContent-Type: application/vscode-jsonrpc; charset=utf-8\r\n\r\n$outdata" ;
163 0           $self -> _write ($wrdata) ;
164 0 0         if ($debug1)
165             {
166 0           $wrdata =~ s/\r//g ;
167 0 0         $self -> logger ($src, $txt, $jsonpretty -> encode ($notification), "\n") if ($debug1) ;
168             }
169             }
170              
171             # ---------------------------------------------------------------------------
172              
173             sub call_method
174 0           {
175 0     0 0   my ($self, $reqdata, $req, $id) = @_ ;
176              
177 0 0         my $method = $req -> is_dap?$reqdata -> {command}:$reqdata -> {method} ;
178 0           my $module ;
179             my $name ;
180              
181 0 0         if ($method =~ /^(\w+)\/(\w+)$/)
    0          
    0          
182             {
183 0           $module = $1 ;
184 0           $name = $2 ;
185             }
186             elsif ($method =~ /^(\w+)$/)
187             {
188 0           $name = $1 ;
189             }
190             elsif ($method =~ /^\$\/(\w+)$/)
191             {
192 0           $name = $1 ;
193             }
194             else
195             {
196 0           die "Unknown method $method" ;
197             }
198 0 0         $module = $req -> type eq 'dbgint'?'DebugAdapterInterface':'DebugAdapter' if ($req -> is_dap) ;
    0          
199              
200 0           my $base_package = __PACKAGE__ . '::Methods' ;
201 0           my $package = $base_package ;
202 0 0         $package .= '::' . $module if ($module) ;
203              
204 0           my $fn = $package . '.pm' ;
205 0           $fn =~ s/::/\//g ;
206 0 0 0       if (!exists $INC{$fn} || !exists $self -> roles -> {$fn})
207             {
208             #$self -> logger (dump (\%INC), "\n") ;
209 0           $self -> logger ("apply_all_roles ($self, $package, $fn)\n") ;
210 0           apply_all_roles ($self, $package) ;
211 0           $self -> roles -> {$fn} = 1 ;
212             }
213              
214 0           my $perlmethod ;
215 0 0         if ($req -> is_dap)
216             {
217 0           $perlmethod = '_dapreq_' . $name ;
218             }
219             else
220             {
221 0 0         $perlmethod = (defined($id)?'_rpcreq_':'_rpcnot_') . $name ;
222             }
223 0 0         $self -> logger ("method=$perlmethod\n") if ($debug1) ;
224 0 0         die "Unknown perlmethod $perlmethod" if (!$self -> can ($perlmethod)) ;
225              
226 1     1   603 no strict ;
  1         2  
  1         57  
227 0           return $self -> $perlmethod ($workspace, $req) ;
228 1     1   6 use strict ;
  1         4  
  1         588  
229             }
230              
231             # ---------------------------------------------------------------------------
232              
233             sub process_req
234             {
235 0     0 0   my ($self, $id, $reqdata) = @_ ;
236              
237 0           my $xid = $id ;
238 0   0       $xid ||= $reqseq++ ;
239             $running_coros{$xid} = async
240             {
241             my $req_guard = Guard::guard
242             {
243 0 0         $self -> logger ("done handle_req id=$xid\n") if ($debug1) ;
244 0           delete $running_reqs{$xid} ;
245 0           delete $running_coros{$xid} ;
246 0     0     };
247              
248 0           my $type = $reqdata -> {type} ;
249 0 0         my $is_dap = $type?1:0 ;
250 0 0         $type = defined ($id)?'request':'notification' if (!$type) ;
    0          
251 0 0         $self -> logger ("handle_req id=$id\n") if ($debug1) ;
252 0 0 0       my $req = Perl::LanguageServer::Req -> new ({ id => $id, is_dap => $is_dap, type => $type, params => $is_dap?$reqdata -> {arguments} || {}:$reqdata -> {params} || {}}) ;
      0        
253 0           $running_reqs{$xid} = $req ;
254              
255 0           my $rsp ;
256             my $outdata ;
257 0           my $outjson ;
258             eval
259 0           {
260 0           $rsp = $self -> call_method ($reqdata, $req, $id) ;
261 0 0         $id = undef if (!$rsp) ;
262 0 0         if ($req -> is_dap)
263             {
264 0 0         $outjson = { request_seq => -$id, seq => -$id, command => $reqdata -> {command}, success => JSON::true, type => 'response', $rsp?(body => $rsp):()} ;
265             }
266             else
267             {
268 0 0         $outjson = { id => $id, jsonrpc => '2.0', result => $rsp} if ($rsp) ;
269             }
270 0 0         $outdata = $json -> encode ($outjson) if ($outjson) ;
271             } ;
272 0 0         if ($@)
273             {
274 0           $self -> logger ("ERROR: $@\n") ;
275 0 0         if ($req -> is_dap)
276             {
277 0           $outjson = { request_seq => -$id, command => $reqdata -> {command}, success => JSON::false, message => "$@", , type => 'response'} ;
278             }
279             else
280             {
281 0           $outjson = { id => $id, jsonrpc => '2.0', error => { code => -32001, message => "$@" }} ;
282             }
283 0 0         $outdata = $json -> encode ($outjson) if ($outjson) ;
284             }
285              
286 0 0         if (defined($id))
287             {
288 0           my $guard = $self -> out_semaphore -> guard ;
289 1     1   9 use bytes ;
  1         2  
  1         7  
290 0           my $len = length ($outdata) ;
291 0           my $wrdata = "Content-Length: $len\r\nContent-Type: application/vscode-jsonrpc; charset=utf-8\r\n\r\n$outdata" ;
292 0           my $sum = 0 ;
293 0           my $cnt ;
294 0           while ($sum < length ($wrdata))
295             {
296 0           $cnt = $self -> _write ($wrdata, undef, $sum) ;
297 0 0         die "write_error ($!)" if ($cnt <= 0) ;
298 0           $sum += $cnt ;
299             }
300              
301 0 0         if ($debug1)
302             {
303 0           $wrdata =~ s/\r//g ;
304 0           $self -> logger ("<--- Response: ", $jsonpretty -> encode ($outjson), "\n") ;
305             }
306             }
307 0           } ;
308             }
309              
310             # ---------------------------------------------------------------------------
311              
312             sub mainloop
313             {
314 0     0 0   my ($self) = @_ ;
315              
316 0           my $buffer = '' ;
317 0           while (!$exit)
318             {
319 1     1   310 use bytes ;
  1         2  
  1         8  
320 0           my %header ;
321             my $line ;
322 0           my $cnt ;
323 0           my $loop ;
324             header:
325 0           while (1)
326             {
327 0 0         $self -> logger ("start aio read, buffer len = " . length ($buffer) . "\n") if ($debug2) ;
328 0 0         if ($loop)
329             {
330 0           $cnt = $self -> _read (\$buffer, 8192, length ($buffer), undef, 1) ;
331 0 0         $self -> logger ("end aio read cnt=$cnt, buffer len = " . length ($buffer) . "\n") if ($debug2) ;
332 0 0         die "read_error reading headers ($!)" if ($cnt < 0) ;
333 0 0         return if ($cnt == 0) ;
334             }
335              
336 0           while ($buffer =~ s/^(.*?)\R//)
337             {
338 0           $line = $1 ;
339 0 0         $self -> logger ("line=<$line>\n") if ($debug2) ;
340 0 0         last header if ($line eq '') ;
341 0 0         $header{$1} = $2 if ($line =~ /(.+?):\s*(.+)/) ;
342             }
343 0           $loop = 1 ;
344             }
345              
346 0           my $len = $header{'Content-Length'} ;
347 0 0         return 1 if ($len == 0);
348 0           my $data ;
349             #$self -> logger ("len=$len len buffer=", length ($buffer), "\n") if ($debug2) ;
350 0           while ($len > length ($buffer))
351             {
352 0           $cnt = $self -> _read (\$buffer, $len - length ($buffer), length ($buffer)) ;
353              
354             #$self -> logger ("cnt=$cnt len=$len len buffer=", length ($buffer), "\n") if ($debug2) ;
355 0 0         die "read_error reading data ($!)" if ($cnt < 0) ;
356 0 0         return if ($cnt == 0) ;
357             }
358 0 0         if ($len == length ($buffer))
    0          
359             {
360 0           $data = $buffer ;
361 0           $buffer = '' ;
362             }
363             elsif ($len < length ($buffer))
364             {
365 0           $data = substr ($buffer, 0, $len) ;
366 0           $buffer = substr ($buffer, $len) ;
367             }
368             else
369             {
370 0           die "to few data bytes" ;
371             }
372 0 0         $self -> logger ("read data=", $data, "\n") if ($debug2) ;
373 0 0         $self -> logger ("read header=", dump (\%header), "\n") if ($debug2) ;
374              
375 0           my $reqdata ;
376 0 0         $reqdata = $json -> decode ($data) if ($data) ;
377 0 0         if ($debug1)
378             {
379 0           $self -> logger ($self -> log_req_txt, $jsonpretty -> encode ($reqdata), "\n") ;
380             }
381 0 0         my $id = $reqdata -> {type}?-$reqdata -> {seq}:$reqdata -> {id};
382              
383 0           $self -> process_req ($id, $reqdata) ;
384 0           cede () ;
385             }
386              
387 0           return 1 ;
388             }
389              
390             # ---------------------------------------------------------------------------
391              
392             sub _run_tcp_server
393             {
394 0     0     my ($listen_port) = @_ ;
395              
396 0 0         if ($listen_port)
397             {
398 0           my $quit ;
399 0   0       while (!$quit && !$exit)
400             {
401 0           logger (undef, "tcp server start listen on port $listen_port\n") ;
402 0           my $tcpcv = AnyEvent::CondVar -> new ;
403 0           my $guard ;
404             eval
405 0           {
406             $guard = tcp_server '127.0.0.1', $listen_port, sub
407             {
408 0     0     my ($fh, $host, $port) = @_ ;
409              
410             async
411             {
412             eval
413 0           {
414 0           $fh = Coro::Handle::unblock ($fh) ;
415 0           my $self = Perl::LanguageServer -> new ({out_fh => $fh, in_fh => $fh, log_prefix => 'DAx'});
416 0           $self -> logger ("connect from $host:$port\n") ;
417 0           $self -> listen_port ($listen_port) ;
418              
419 0           $quit = $self -> mainloop () ;
420 0 0         $self -> logger ("got quit signal\n") if ($quit) ;
421             } ;
422 0 0         logger (undef, $@) if ($@) ;
423 0 0         if ($fh)
424             {
425 0           close ($fh) ;
426 0           $fh = undef ;
427             }
428 0 0 0       if ($quit || $exit)
429             {
430 0           $tcpcv -> send ;
431 0           IO::AIO::reinit () ; # stop AIO requests
432 0           exit (1) ;
433             }
434 0           } ;
435 0           } ;
436             } ;
437 0 0         if (!$@)
438             {
439 0           $tcpcv -> recv ;
440             }
441             else
442             {
443 0           $guard = undef ;
444 0           logger (undef, $@) ;
445             #$quit = 1 ;
446 0 0 0       if (!$guard && ($@ =~ /Address already in use/))
447             {
448             # stop other server
449             tcp_connect '127.0.0.1', $listen_port, sub
450             {
451 0     0     my ($fh) = @_ ;
452 0 0         syswrite ($fh, "Content-Length: 0\r\n\r\n") if ($fh) ;
453 0           } ;
454             }
455 0           $@ = undef ;
456 0           Coro::AnyEvent::sleep (2) ;
457 0           IO::AIO::reinit () ; # stop AIO requests
458 0           exit (1) ; # stop LS, vscode will restart it
459             }
460             }
461             }
462             }
463              
464             # ---------------------------------------------------------------------------
465              
466             sub run
467             {
468 0     0 1   my $listen_port ;
469             my $no_stdio ;
470 0           my $heartbeat ;
471              
472 0           while (my $opt = shift @ARGV)
473             {
474 0 0         if ($opt eq '--debug')
    0          
    0          
    0          
    0          
    0          
    0          
475             {
476 0           $debug1 = $debug2 = 1 ;
477             }
478             elsif ($opt eq '--log-level')
479             {
480 0           $debug1 = shift @ARGV ;
481 0 0         $debug2 = $debug1 > 1?1:0 ;
482             }
483             elsif ($opt eq '--log-file')
484             {
485 0           $log_file = shift @ARGV ;
486             }
487             elsif ($opt eq '--port')
488             {
489 0           $listen_port = shift @ARGV ;
490             }
491             elsif ($opt eq '--nostdio')
492             {
493 0           $no_stdio = 1 ;
494             }
495             elsif ($opt eq '--heartbeat')
496             {
497 0           $heartbeat = 1 ;
498             }
499             elsif ($opt eq '--version')
500             {
501 0           $client_version = shift @ARGV ;
502             }
503             }
504              
505 0           $|= 1 ;
506              
507 0           my $cv = AnyEvent::CondVar -> new ;
508              
509             async
510             {
511 0     0     my $i = 0 ;
512 0           while (1)
513             {
514 0 0 0       if ($heartbeat || $debug2)
515             {
516 0           logger (undef, "##### $i #####\n running: " . dump (\%running_reqs) . " coros: " . dump (\%running_coros), "\n") ;
517 0           $i++ ;
518             }
519              
520 0           Coro::AnyEvent::sleep (10) ;
521             }
522 0           } ;
523              
524 0 0         if (!$no_stdio)
525             {
526             async
527             {
528 0     0     my $self = Perl::LanguageServer -> new ({out_fh => 1, in_fh => 0});
529 0           $self -> listen_port ($listen_port) ;
530              
531 0           $self -> mainloop () ;
532              
533 0           $cv -> send ;
534 0           } ;
535             }
536              
537             async
538             {
539 0     0     _run_tcp_server ($listen_port) ;
540 0           } ;
541              
542 0           $cv -> recv ;
543 0           $exit = 1 ;
544             }
545              
546             # ---------------------------------------------------------------------------
547              
548             sub parsews
549             {
550 0     0 0   my $class = shift ;
551 0           my @args = @_ ;
552              
553 0           $|= 1 ;
554              
555 0           my $cv = AnyEvent::CondVar -> new ;
556              
557             async
558             {
559 0     0     my $self = Perl::LanguageServer -> new ;
560 0           $workspace = Perl::LanguageServer::Workspace -> new ({ config => {} }) ;
561 0           my %folders ;
562 0           foreach my $path (@args)
563             {
564 0           $folders{$path} = $path ;
565             }
566 0           $workspace -> folders (\%folders) ;
567 0           $workspace -> background_parser ($self) ;
568              
569 0           $cv -> send ;
570 0           } ;
571              
572 0           $cv -> recv ;
573             }
574              
575             # ---------------------------------------------------------------------------
576              
577             sub check_file
578             {
579 0     0 0   my $class = shift ;
580 0           my @args = @_ ;
581              
582 0           $|= 1 ;
583              
584 0           my $cv = AnyEvent::CondVar -> new ;
585              
586 0           my $self = Perl::LanguageServer -> new ;
587 0           $workspace = Perl::LanguageServer::Workspace -> new ({ config => {} }) ;
588             async
589             {
590 0     0     my %folders ;
591 0           foreach my $path (@args)
592             {
593 0           $folders{$path} = $path ;
594             }
595 0           $workspace -> folders (\%folders) ;
596 0           $workspace -> background_checker ($self) ;
597              
598 0           $cv -> send ;
599 0           } ;
600              
601             async
602             {
603 0     0     foreach my $path (@args)
604             {
605 0           my $text ;
606 0           aio_load ($path, $text) ;
607              
608 0           $workspace -> check_perl_syntax ($workspace, $path, $text) ;
609             }
610              
611 0           } ;
612              
613 0           $cv -> recv ;
614             }
615              
616             1 ;
617              
618             __END__
619              
620             =head1 DOCUMENTATION
621              
622             Language Server and Debug Protocol Adapter for Perl
623              
624             =head2 Features
625              
626             =over
627              
628             =item * Language Server
629              
630             =over
631              
632             =item * Syntax checking
633              
634             =item * Symbols in file
635              
636             =item * Symbols in workspace/directory
637              
638             =item * Goto Definition
639              
640             =item * Find References
641              
642             =item * Call Signatures
643              
644             =item * Supports multiple workspace folders
645              
646             =item * Document and selection formatting via perltidy
647              
648             =item * Run on remote system via ssh
649              
650             =item * Run inside docker container
651              
652             =item * Run inside kubernetes
653              
654             =back
655              
656             =item * Debugger
657              
658             =over
659              
660             =item * Run, pause, step, next, return
661              
662             =item * Support for coro threads
663              
664             =item * Breakpoints
665              
666             =item * Conditional breakpoints
667              
668             =item * Breakpoints can be set while program runs and for modules not yet loaded
669              
670             =item * Variable view, can switch to every stack frame or coro thread
671              
672             =item * Set variable
673              
674             =item * Watch variable
675              
676             =item * Tooltips with variable values
677              
678             =item * Evaluate perl code in debuggee, in context of every stack frame of coro thread
679              
680             =item * Automatically reload changed Perl modules while debugging
681              
682             =item * Debug multiple perl programs at once
683              
684             =item * Run on remote system via ssh
685              
686             =item * Run inside docker container
687              
688             =item * Run inside kubernetes
689              
690             =back
691              
692             =back
693              
694             =head2 Requirements
695              
696             You need to install the perl module Perl::LanguageServer to make this extension work,
697             e.g. run C<cpan Perl::LanguageServer> on your target system.
698              
699             Please make sure to always run the newest version of Perl::LanguageServer as well.
700              
701             NOTE: Perl::LanguageServer depend on AnyEvent::AIO and Coro. There is a warning that
702             this might not work with newer Perls. It works fine for Perl::LanguageServer. So just
703             confirm the warning and install it.
704              
705             Perl::LanguageServer depends on other Perl modules. It is a good idea to install most
706             of then with your linux package manager.
707              
708             e.g. on Debian/Ubuntu run:
709              
710              
711            
712             sudo apt install libanyevent-perl libclass-refresh-perl libcompiler-lexer-perl \
713             libdata-dump-perl libio-aio-perl libjson-perl libmoose-perl libpadwalker-perl \
714             libscalar-list-utils-perl libcoro-perl
715            
716             sudo cpan Perl::LanguageServer
717            
718              
719             e.g. on Centos 7 run:
720              
721              
722            
723             sudo yum install perl-App-cpanminus perl-AnyEvent-AIO perl-Coro
724             sudo cpanm Class::Refresh
725             sudo cpanm Compiler::Lexer
726             sudo cpanm Hash::SafeKeys
727             sudo cpanm Perl::LanguageServer
728            
729              
730             In case any of the above packages are not available for your os version, just
731             leave them out. The cpan command will install missing dependencies. In case
732             the test fails, when running cpan C<install>, you should try to run C<force install>.
733              
734             =head2 Extension Settings
735              
736             This extension contributes the following settings:
737              
738             =over
739              
740             =item * C<perl.enable>: enable/disable this extension
741              
742             =item * C<perl.sshAddr>: ip address of remote system
743              
744             =item * C<perl.sshPort>: optional, port for ssh to remote system
745              
746             =item * C<perl.sshUser>: user for ssh login
747              
748             =item * C<perl.sshCmd>: defaults to ssh on unix and plink on windows
749              
750             =item * C<perl.sshWorkspaceRoot>: path of the workspace root on remote system
751              
752             =item * C<perl.perlCmd>: defaults to perl
753              
754             =item * C<perl.perlArgs>: additional arguments passed to the perl interpreter that starts the LanguageServer
755              
756             =item * C<useTaintForSyntaxCheck>: if true, use taint mode for syntax check
757              
758             =item * C<perl.sshArgs>: optional arguments for ssh
759              
760             =item * C<perl.pathMap>: mapping of local to remote paths
761              
762             =item * C<perl.perlInc>: array with paths to add to perl library path. This setting is used by the syntax checker and for the debuggee and also for the LanguageServer itself.
763              
764             =item * C<perl.fileFilter>: array for filtering perl file, defaults to [I<.pm,>.pl]
765              
766             =item * C<perl.ignoreDirs>: directories to ignore, defaults to [.vscode, .git, .svn]
767              
768             =item * C<perl.debugAdapterPort>: port to use for connection between vscode and debug adapter inside Perl::LanguageServer.
769              
770             =item * C<perl.debugAdapterPortRange>: if debugAdapterPort is in use try ports from debugAdapterPort to debugAdapterPort + debugAdapterPortRange. Default 100.
771              
772             =item * C<perl.showLocalVars>: if true, show also local variables in symbol view
773              
774             =item * C<perl.logLevel>: Log level 0-2.
775              
776             =item * C<perl.logFile>: If set, log output is written to the given logfile, instead of displaying it in the vscode output pane. Log output is always appended. Only use during debugging of LanguageServer itself.
777              
778             =item * C<perl.disableCache>: If true, the LanguageServer will not cache the result of parsing source files on disk, so it can be used within readonly directories
779              
780             =item * C<perl.containerCmd>: If set Perl::LanguageServer can run inside a container. Options are: 'docker', 'docker-compose', 'kubectl'
781              
782             =item * C<perl.containerArgs>: arguments for containerCmd. Varies depending on containerCmd.
783              
784             =item * C<perl.containerMode>: To start a new container, set to 'run', to execute inside an existing container set to 'exec'. Note: kubectl only supports 'exec'
785              
786             =item * C<perl.containerName>: Image to start or container to exec inside or pod to use
787              
788             =back
789              
790             =head2 Debugger Settings for launch.json
791              
792             =over
793              
794             =item * C<type>: needs to be C<perl>
795              
796             =item * C<request>: only C<launch> is supported (this is a restriction of perl itself)
797              
798             =item * C<name>: name of this debug configuration
799              
800             =item * C<program>: path to perl program to start
801              
802             =item * C<stopOnEntry>: if true, program will stop on entry
803              
804             =item * C<args>: optional, array or string with arguments for perl program
805              
806             =item * C<env>: optional, object with environment settings
807              
808             =item * C<cwd>: optional, change working directory before launching the debuggee
809              
810             =item * C<reloadModules>: if true, automatically reload changed Perl modules while debugging
811              
812             =item * C<sudoUser>: optional, if set run debug process with sudo -u \<sudoUser\>.
813              
814             =item * C<useTaintForDebug>: optional, if true run debug process with -T (taint mode).
815              
816             =item * C<containerCmd>: If set debugger runs inside a container. Options are: 'docker', 'docker-compose', 'podman', 'kubectl'
817              
818             =item * C<containerArgs>: arguments for containerCmd. Varies depending on containerCmd.
819              
820             =item * C<containerMode>: To start a new container, set to 'run', to debug inside an existing container set to 'exec'. Note: kubectl only supports 'exec'
821              
822             =item * C<containerName>: Image to start or container to exec inside or pod to use
823              
824             =item * C<pathMap>: mapping of local to remote paths for this debug session (overwrites global C<perl.path_map>)
825              
826             =back
827              
828             =head2 Remote syntax check & debugging
829              
830             If you developing on a remote machine, you can instruct the Perl::LanguageServer to
831             run on that remote machine, so the correct modules etc. are available for syntax check and debugger is started on the remote machine.
832             To do so set sshAddr and sshUser, preferably in your workspace configuration.
833              
834             Example:
835              
836              
837             "sshAddr": "10.11.12.13",
838             "sshUser": "root"
839              
840             Also set sshWorkspaceRoot, so the local workspace path can be mapped to the remote one.
841              
842             Example: if your local path is \10.11.12.13\share\path\to\ws and on the remote machine you have /path/to/ws
843              
844              
845             "sshWorkspaceRoot": "/path/to/ws"
846              
847             The other possibility is to provide a pathMap. This allows one to having multiple mappings.
848              
849             Examples:
850              
851              
852             "perl.pathMap": [
853             ["remote uri", "local uri"],
854             ["remote uri", "local uri"]
855             ]
856            
857             "perl.pathMap": [
858             [
859             "file:///",
860             "file:///home/systems/mountpoint/"
861             ]
862             ]
863              
864             =head2 Syntax check & debugging inside a container
865              
866             You can run the LanguageServer and/or debugger inside
867             a container by setting C<containerCmd> and C<conatinerName>.
868             There are more container options, see above.
869              
870             .vscode/settings.json
871              
872              
873             {
874             "perl": {
875             "enable": true,
876             "containerCmd": "docker",
877             "containerName": "perl_container",
878             }
879             }
880              
881             This will start the whole Perl::LanguageServer inside the container. This is espacally
882             helpfull to make syntax check working, if there is a different setup inside
883             and outside the container.
884              
885             In this case you need to tell the Perl::LanguageServer how to map local paths
886             to paths inside the container. This is done by setting C<perl.pathMap> (see above).
887              
888             Example:
889              
890              
891             "perl.pathMap": [
892             [
893             "file:///path/inside/the/container",
894             "file:///local/path/outside/the/container"
895             ]
896             ]
897              
898             It's also possible to run the LanguageServer outside the container and only
899             the debugger inside the container. This is especially helpfull, when the
900             container is not always running, while you are editing.
901             To make only the debugger running inside the container, put
902             C<containerCmd>, C<conatinerName> and C<pasth_map> in your C<launch.json>.
903             You can have different setting for each debug session.
904              
905             Normaly the arguments for the C<containerCmd> are automatically build. In case
906             you want to use an unsupported C<containerCmd> you need to specifiy
907             apropriate C<containerArgs>.
908              
909             =head2 FAQ
910              
911             =head3 Working directory is not defined
912              
913             It is not defined what the current working directory is at the start of a perl program.
914             So Perl::LanguageServer makes no assumptions about it. To solve the problem you can set
915             the directory via cwd configuration parameter in launch.json for debugging.
916              
917             =head3 Module not found when debugging or during syntax check
918              
919             If you reference a module with a relative path or if you assume that the current working directory
920             is part of the Perl search path, it will not work.
921             Instead set the perl include path to a fixed absolute path. In your settings.json do something like:
922              
923              
924             "perl.perlInc": [
925             "/path/a/lib",
926             "/path/b/lib",
927             "/path/c/lib",
928             ],
929             Include path works for syntax check and inside of debugger.
930             C<perl.perlInc> should be an absolute path.
931              
932             =head3 AnyEvent, Coro Warning during install
933              
934             You need to install the AnyEvent::IO and Coro. Just ignore the warning that it might not work. For Perl::LanguageServer it works fine.
935              
936             =head3 'richterger.perl' failed: options.port should be >= 0 and < 65536
937              
938             Change port setting from string to integer
939              
940             =head3 Error "Can't locate MODULE_NAME"
941              
942             Please make sure the path to the module is in C<perl.perlInc> setting and use absolute path names in the perlInc settings
943             or make sure you are running in the expected directory by setting the C<cwd> setting in the lauch.json.
944              
945             =head3 ERROR: Unknown perlmethod I<rpcnot>setTraceNotification
946              
947             This is not an issue, that just means that not all features of the debugging protocol are implemented.
948             Also it says ERROR, it's just a warning and you can safely ignore it.
949              
950             =head3 The debugger sometimes stops at random places
951              
952             Upgrade to Version 2.4.0
953              
954             =head3 Message about Perl::LanguageServer has crashed 5 times
955              
956             This is a problem when more than one instance of Perl::LanguageServer is running.
957             Upgrade to Version 2.4.0 solves this problem.
958              
959             =head3 The program I want to debug needs some input via stdin
960              
961             You can read stdin from a file during debugging. To do so add the following parameter
962             to your C<launch.json>:
963              
964             C<<
965             "args": [ "E<lt>", "/path/to/stdin.txt" ]
966             >>
967              
968             e.g.
969              
970             C<<
971             {
972             "type": "perl",
973             "request": "launch",
974             "name": "Perl-Debug",
975             "program": "${workspaceFolder}/${relativeFile}",
976             "stopOnEntry": true,
977             "reloadModules": true,
978             "env": {
979             "REQUEST_METHOD": "POST",
980             "CONTENT_TYPE": "application/x-www-form-urlencoded",
981             "CONTENT_LENGTH": 34
982             }
983             "args": [ "E<lt>", "/path/to/stdin.txt" ]
984             }
985             >>
986              
987             =head3 Carton support
988              
989             If you are using LL<https://metacpan.org/pod/Carton> to manage dependencies, add the full path to the Carton C<lib> dir to your workspace settings file at C<.vscode/settings.json>. For example:
990              
991             =head4 Linux
992              
993              
994             {
995             "perl.perlInc": ["/home/myusername/projects/myprojectname/local/lib/perl5"]
996             }
997              
998             =head4 Mac
999              
1000              
1001             {
1002             "perl.perlInc": ["/Users/myusername/projects/myprojectname/local/lib/perl5"]
1003             }
1004              
1005             =head2 Known Issues
1006              
1007             Does not yet work on windows, due to issues with reading from stdin.
1008             I wasn't able to find a reliable way to do a non-blocking read from stdin on windows.
1009             I would be happy, if anyone knows how to do this in Perl.
1010              
1011             Anyway, Perl::LanguageServer runs without problems inside of Windows Subsystem for Linux (WSL).
1012              
1013             =head2 Release Notes
1014              
1015             see CHANGELOG.md
1016              
1017             =head2 More Info
1018              
1019             =over
1020              
1021             =item * Presentation at German Perl Workshop 2020:
1022              
1023             =back
1024              
1025             https://github.com/richterger/Perl-LanguageServer/blob/master/docs/Perl-LanguageServer%20und%20Debugger%20f%C3%BCr%20Visual%20Studio%20Code%20u.a.%20Editoren%20-%20Perl%20Workshop%202020.pdf
1026              
1027             =over
1028              
1029             =item * Github: https://github.com/richterger/Perl-LanguageServer
1030              
1031             =item * MetaCPAN: https://metacpan.org/release/Perl-LanguageServer
1032              
1033             =back
1034              
1035             For reporting bugs please use GitHub issues.
1036              
1037             =head2 References
1038              
1039             This is a Language Server and Debug Protocol Adapter for Perl
1040              
1041             It implements the Language Server Protocol which provides
1042             syntax-checking, symbol search, etc. Perl to various editors, for
1043             example Visual Studio Code or Atom.
1044              
1045             https://microsoft.github.io/language-server-protocol/specification
1046              
1047             It also implements the Debug Adapter Protocol, which allows debugging
1048             with various editors/includes
1049              
1050             https://microsoft.github.io/debug-adapter-protocol/overview
1051              
1052             To use both with Visual Studio Code, install the extension "perl"
1053              
1054             https://marketplace.visualstudio.com/items?itemName=richterger.perl
1055              
1056             Any comments and patches are welcome.
1057              
1058             =head2 LICENSE AND COPYRIGHT
1059              
1060             Copyright 2018-2022 Gerald Richter.
1061              
1062             This program is free software; you can redistribute it and/or modify it
1063             under the terms of the Artistic License (2.0). You may obtain a
1064             copy of the full license at:
1065              
1066             LL<http://www.perlfoundation.org/artistic_license_2_0>
1067              
1068             Any use, modification, and distribution of the Standard or Modified
1069             Versions is governed by this Artistic License. By using, modifying or
1070             distributing the Package, you accept this license. Do not use, modify,
1071             or distribute the Package, if you do not accept this license.
1072              
1073             If your Modified Version has been derived from a Modified Version made
1074             by someone other than you, you are nevertheless required to ensure that
1075             your Modified Version complies with the requirements of this license.
1076              
1077             This license does not grant you the right to use any trademark, service
1078             mark, tradename, or logo of the Copyright Holder.
1079              
1080             This license includes the non-exclusive, worldwide, free-of-charge
1081             patent license to make, have made, use, offer to sell, sell, import and
1082             otherwise transfer the Package with respect to any patent claims
1083             licensable by the Copyright Holder that are necessarily infringed by the
1084             Package. If you institute patent litigation (including a cross-claim or
1085             counterclaim) against any party alleging that the Package constitutes
1086             direct or contributory patent infringement, then this Artistic License
1087             to you shall terminate on the date that such litigation is filed.
1088              
1089             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
1090             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
1091             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
1092             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
1093             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
1094             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
1095             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
1096             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1097              
1098             =head1 Change Log
1099              
1100             =head2 2.6.1 C<2023-07-26>
1101              
1102             =over
1103              
1104             =item * Fix: Formatting with perltidy was broken in 2.6.0
1105              
1106             =back
1107              
1108             =head2 2.6.0 C<2023-07-23>
1109              
1110             =over
1111              
1112             =item * Add debug setting for running as different user. See sudoUser setting. (#174) [wielandp]
1113              
1114             =item * Allow to use a string for debuggee arguments. (#149, #173) [wielandp]
1115              
1116             =item * Add stdin redirection (#166) [wielandp]
1117              
1118             =item * Add link to issues to META files (#168) [szabgab/issues]
1119              
1120             =item * Add support for podman
1121              
1122             =item * Add support for run Perl::LanguageServer outside, but debugger inside a container
1123              
1124             =item * Add setting useTaintForSyntaxCheck. If true, use taint mode for syntax check (#172) [wielandp]
1125              
1126             =item * Add setting useTaintForDebug. If true, use taint mode inside debugger (#181) [wielandp]
1127              
1128             =item * Add debug adapter request C<source>, which allows to display source of eval or file that are not available to vscode (#180) [wielandp]
1129              
1130             =item * Fix: Spelling (#170, #171) [pkg-perl-tools]
1131              
1132             =item * Fix: Convert charset encoding of debugger output according to current locale (#167) [wielandp]
1133              
1134             =item * Fix: Fix diagnostic notifications override on clients (based on #185) [bmeneg]
1135              
1136             =back
1137              
1138             =head2 2.5.0 C<2023-02-05>
1139              
1140             =over
1141              
1142             =item * Set minimal Perl version to 5.16 (#91)
1143              
1144             =item * Per default environment from vscode will be passed to debuggee, syntax check and perltidy.
1145              
1146             =item * Add configuration C<disablePassEnv> to not pass environment variables.
1147              
1148             =item * Support for C<logLevel> and C<logFile> settings via LanguageServer protocol and
1149             not only via command line options (#97) [schellj]
1150              
1151             =item * Fix: "No DB::DB routine defined" (#91) [peterdragon]
1152              
1153             =item * Fix: Typos and spelling in README (#159) [dseynhae]
1154              
1155             =item * Fix: Update call to gensym(), to fix 'strict subs' error (#164) [KohaAloha]
1156              
1157             =item * Convert identention from tabs to spaces and remove trailing whitespaces
1158              
1159             =back
1160              
1161             =head2 2.4.0 C<2022-11-18>
1162              
1163             =over
1164              
1165             =item * Choose a different port for debugAdapterPort if it is already in use. This
1166             avoids trouble with starting C<Perl::LanguageServer> if another instance
1167             of C<Perl::LanguageServer> is running on the same machine (thanks to hakonhagland)
1168              
1169             =item * Add configuration C<debugAdapterPortRange>, for choosing range of port for dynamic
1170             port assignment
1171              
1172             =item * Add support for using LanguageServer and debugger inside a Container.
1173             Currently docker containers und containers running inside kubernetes are supported.
1174              
1175             =item * When starting debugger session and C<stopOnEntry> is false, do not switch to sourefile
1176             where debugger would stop, when C<stopOnEntry> is true.
1177              
1178             =item * Added some FAQs in README
1179              
1180             =item * Fix: Debugger stopps at random locations
1181              
1182             =item * Fix: debugAdapterPort is now numeric
1183              
1184             =item * Fix: debugging loop with each statement (#107)
1185              
1186             =item * Fix: display of arrays in variables pane on mac (#120)
1187              
1188             =item * Fix: encoding for C<perltidy> (#127)
1189              
1190             =item * Fix: return error if C<perltidy> fails, so text is not removed by failing
1191             formatting request (#87)
1192              
1193             =item * Fix: FindBin does not work when checking syntax (#16)
1194              
1195             =back
1196              
1197             =head2 2.3.0 C<2021-09-26>
1198              
1199             =over
1200              
1201             =item * Arguments section in Variable lists now C<@ARGV> and C<@_> during debugging (#105)
1202              
1203             =item * C<@_> is now correctly evaluated inside of debugger console
1204              
1205             =item * C<$#foo> is now correctly evaluated inside of debugger console
1206              
1207             =item * Default debug configuration is now automatically provided without
1208             the need to create a C<launch.json> first (#103)
1209              
1210             =item * Add Option C<cacheDir> to specify location of cache dir (#113)
1211              
1212             =item * Fix: Debugger outputted invalid thread reference causes "no such coroutine" message,
1213             so watchs and code from the debug console is not expanded properly
1214              
1215             =item * Fix: LanguageServer hangs when multiple request send at once from VSCode to LanguageServer
1216              
1217             =item * Fix: cwd parameter for debugger in launch.json had no effect (#99)
1218              
1219             =item * Fix: Correctly handle paths with drive letters on windows
1220              
1221             =item * Fix: sshArgs parameter was not declared as array (#109)
1222              
1223             =item * Disable syntax check on windows, because it blocks the whole process when running on windows,
1224             until handling of child's processes is fixed
1225              
1226             =item * Fixed spelling (#86,#96,#101) [chrstphrchvz,davorg,aluaces]
1227              
1228             =back
1229              
1230             =head2 2.2.0 C<2021-02-21>
1231              
1232             =over
1233              
1234             =item * Parser now supports Moose method modifieres before, after and around,
1235             so they can be used in symbol view and within reference search
1236              
1237             =item * Support Format Document and Format Selection via perltidy
1238              
1239             =item * Add logFile config option
1240              
1241             =item * Add perlArgs config option to pass options to Perl interpreter. Add some documentation for config options.
1242              
1243             =item * Add disableCache config option to make LanguageServer usable with readonly directories.
1244              
1245             =item * updated dependencies package.json & package-lock.json
1246              
1247             =item * Fix deep recursion in SymbolView/Parser which was caused by function prototypes.
1248             Solves also #65
1249              
1250             =item * Fix duplicate req id's that caused cleanup of still
1251             running threads which in turn caused the LanguageServer to hang
1252              
1253             =item * Prevent dereferencing an undefined value (#63) [Heiko Jansen]
1254              
1255             =item * Fix datatype of cwd config options (#47)
1256              
1257             =item * Use perlInc setting also for LanguageServer itself (based only pull request #54 from ALANVF)
1258              
1259             =item * Catch Exceptions during display of variables inside debugger
1260              
1261             =item * Fix detecting duplicate LanguageServer processes
1262              
1263             =item * Fix spelling in documentation (#56) [Christopher Chavez]
1264              
1265             =item * Remove notice about Compiler::Lexer 0.22 bugs (#55) [Christopher Chavez]
1266              
1267             =item * README: Typo and grammar fixes. Add Carton lib path instructions. (#40) [szTheory]
1268              
1269             =item * README: Markdown code block formatting (#42) [szTheory]
1270              
1271             =item * Makefile.PL: add META_MERGE with GitHub info (#32) [Christopher Chavez]
1272              
1273             =item * search.cpan.org retired, replace with metacpan.org (#31) [Christopher Chavez]
1274              
1275             =back
1276              
1277             =head2 2.1.0 C<2020-06-27>
1278              
1279             =over
1280              
1281             =item * Improve Symbol Parser (fix parsing of anonymous subs)
1282              
1283             =item * showLocalSymbols
1284              
1285             =item * function names in breadcrump
1286              
1287             =item * Signature Help for function/method arguments
1288              
1289             =item * Add Presentation on Perl Workshop 2020 to repos
1290              
1291             =item * Remove Compiler::Lexer from distribution since
1292             version is available on CPAN
1293              
1294             =item * Make stdout unbuffered while debugging
1295              
1296             =item * Make debugger use perlInc setting
1297              
1298             =item * Fix fileFilter setting
1299              
1300             =item * Sort Arrays numerically in variables view of debugger
1301              
1302             =item * Use rootUri if workspaceFolders not given
1303              
1304             =item * Fix env config setting
1305              
1306             =item * Recongnice changes in config of perlCmd
1307              
1308             =back
1309              
1310             =head2 2.0.2 C<2020-01-22>
1311              
1312             =over
1313              
1314             =item * Plugin: Fix command line parameters for plink
1315              
1316             =item * Perl::LanguageServer: Fix handling of multiple parallel request, improve symlink handling, add support for UNC paths in path mapping, improve logging for logLevel = 1
1317              
1318             =back
1319              
1320             =head2 2.0.1 C<2020-01-14>
1321              
1322             Added support for reloading Perl module while debugging, make log level configurable, make sure tooltips don't call functions
1323              
1324             =head2 2.0.0 C<2020-01-01>
1325              
1326             Added Perl debugger
1327              
1328             =head2 0.9.0 C<2019-05-03>
1329              
1330             Fix issues in the Perl part, make sure to update Perl::LanguageServer from cpan
1331              
1332             =head2 0.0.3 C<2018-09-08>
1333              
1334             Fix issue with not reading enough from stdin, which caused LanguageServer to hang sometimes
1335              
1336             =head2 0.0.2 C<2018-07-21>
1337              
1338             Fix quitting issue when starting Perl::LanguageServer, more fixes are in the Perl part
1339              
1340             =head2 0.0.1 C<2018-07-13>
1341              
1342             Initial Version