LanguageServer/Workspace.pm

filter: Statementstmt 32.2% 41 / 127 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 34.7% 8 / 23 Podpod 0.0% 0 / 9 totaltotal 22.5% 49 / 217 CC 31 SCAR 40.0
CC
31
Cov
23%
add_diagnostic_messages
182.0
file_server2client
30.0
file_client2server
30.0
CRAP 54.9
« LanguageServer/DebuggerInterface.pm ↑ Summary LanguageServer/IO.pm »
1 package Perl::LanguageServer::Workspace ;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Moose ;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use File::Basename ;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Coro ;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Coro::AIO ;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Data::Dump qw{dump} ;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 with 'Perl::LanguageServer::SyntaxChecker' ;
13 1 with 'Perl::LanguageServer::Parser' ;
14  
15 1 ▶no warnings 'uninitialized' ;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # ---------------------------------------------------------------------------
18  
19 1 has 'config' =>
20 (
21 isa => 'HashRef',
22 is => 'ro'
23 ) ;
24  
25 1 has 'is_shutdown' =>
26 (
27 isa => 'Bool',
28 is => 'rw',
29 default => 0,
30 ) ;
31  
32 has 'files' =>
33 (
34 isa => 'HashRef',
35 is => 'rw',
36 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 1 ) ;
38  
39 has 'folders' =>
40 (
41 isa => 'HashRef',
42 is => 'rw',
43 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
44 1 ) ;
45  
46 has 'symbols' =>
47 (
48 isa => 'HashRef',
49 is => 'rw',
50 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 1 ) ;
52  
53 1 has 'path_map' =>
54 (
55 isa => 'Maybe[ArrayRef]',
56 is => 'rw'
57 ) ;
58  
59 1 has 'file_filter_regex' =>
60 (
61 isa => 'Str',
62 is => 'rw',
63 default => '(?:\.pm|\.pl)$',
64 ) ;
65  
66 has 'ignore_dir' =>
67 (
68 isa => 'HashRef',
69 is => 'rw',
70 0 ▶ default => sub { { '.git' => 1, '.svn' => 1, '.vscode' => 1 } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
71 1 ) ;
72  
73 1 has 'perlcmd' =>
74 (
75 isa => 'Str',
76 is => 'rw',
77 default => $^X,
78 ) ;
79  
80 1 has 'perlinc' =>
81 (
82 isa => 'Maybe[ArrayRef]',
83 is => 'rw',
84 ) ;
85  
86 1 has 'use_taint_for_syntax_check' =>
87 (
88 isa => 'Maybe[Bool]',
89 is => 'rw'
90 ) ;
91  
92 1 has 'show_local_vars' =>
93 (
94 isa => 'Maybe[Bool]',
95 is => 'rw',
96 ) ;
97  
98  
99 has 'parser_channel' =>
100 (
101 is => 'rw',
102 isa => 'Coro::Channel',
103 0 ▶ default => sub { Coro::Channel -> new }
Subroutine __ANON__: not called CC=1 SCAR=6.9
104 1 ) ;
105  
106 1 has 'state_dir' =>
107 (
108 is => 'rw',
109 isa => 'Str',
110 lazy_build => 1,
111 clearer => 'clear_state_dir',
112 ) ;
113  
114 1 has 'disable_cache' =>
115 (
116 isa => 'Maybe[Bool]',
117 is => 'rw',
118 ) ;
119  
120 # ---------------------------------------------------------------------------
121  
122 sub logger
123 0 ▶ {
Subroutine logger: not called CC=1 SCAR=6.9
Pod undocumented
124 0 my $self = shift ;
125  
126 0 Perl::LanguageServer::logger (undef, @_) ;
127 }
128  
129 # ----------------------------------------------------------------------------
130  
131  
132 sub mkpath
133 0 ▶ {
Subroutine mkpath: not called CC=3 SCAR=24.8
Pod undocumented
134 0 my ($self, $dir) = @_ ;
135  
136 0 aio_stat ($dir) ;
137 0 ▶ if (! -d _)
Branch: 1 branch
BranchTrueFalseTotal
if (not -d _) 0 0 0
138 {
139 0 $self -> mkpath (dirname($dir)) ;
140 0 ▶ aio_mkdir ($dir, 0755) and die "Cannot make $dir ($!)" ;
Branch: 1 branch
BranchTrueFalseTotal
&aio_mkdir($dir, 493) and die "Cannot make $dir ($!)" 0 0 0
141 }
142 }
143  
144 # ---------------------------------------------------------------------------
145  
146 sub _build_state_dir
147 0 ▶ {
Subroutine _build_state_dir: not called CC=2 SCAR=17.9
148 0 my ($self) = @_ ;
149  
150 0 ▶ my $root = $self -> config -> {rootUri} || 'file:///tmp' ;
Condition0%0/2
$self->config->{'rootUri'} || 'file:///tmp'
l!l
00
MC/DC0%0/1
$self->config->{'rootUri'} || 'file:///tmp'
$self->config->{'rootUri'}
Truth table0%0/2
A
A= $self->config->{'rootUri'}
Aresult
11
00
151 0 my $rootpath = substr ($self -> uri_client2server ($root), 7) ;
152 0 $rootpath =~ s#^/(\w)%3A/#$1:/# ;
153 0 $rootpath .= '/.vscode/perl-lang' ;
154 0 print STDERR "state_dir = $rootpath\n" ;
155 0 $self -> mkpath ($rootpath) ;
156  
157 0 return $rootpath ;
158 }
159  
160 # ---------------------------------------------------------------------------
161  
162  
163 sub shutdown
164 0 ▶ {
Subroutine shutdown: not called CC=1 SCAR=6.9
Pod undocumented
165 0 my ($self) = @_ ;
166  
167 0 $self -> is_shutdown (1) ;
168 }
169  
170 # ---------------------------------------------------------------------------
171  
172 sub uri_server2client
173 0 ▶ {
Subroutine uri_server2client: not called CC=4 SCAR=30.0
Pod undocumented
174 0 my ($self, $uri) = @_ ;
175  
176 0 my $map = $self -> path_map ;
177 0 ▶ return $uri if (!$map) ;
Branch: 1 branch
BranchTrueFalseTotal
unless $map 0 0 0
178  
179 #print STDERR ">uri_server2client $uri\n", dump($map), "\n" ;
180 0 foreach my $m (@$map)
181 {
182 0 ▶ last if ($uri =~ s/$m->[0]/$m->[1]/) ;
Branch: 1 branch
BranchTrueFalseTotal
if $uri =~ s/$m->[0]/$m->[1]/ 0 0 0
183 }
184 #print STDERR "<uri_server2client $uri\n" ;
185  
186 0 return $uri ;
187 }
188  
189 # ---------------------------------------------------------------------------
190  
191 sub uri_client2server
192 0 ▶ {
Subroutine uri_client2server: not called CC=4 SCAR=30.0
Pod undocumented
193 0 my ($self, $uri) = @_ ;
194  
195 0 my $map = $self -> path_map ;
196 0 ▶ return $uri if (!$map) ;
Branch: 1 branch
BranchTrueFalseTotal
unless $map 0 0 0
197  
198 #print STDERR ">uri_client2server $uri\n" ;
199 0 foreach my $m (@$map)
200 {
201 0 ▶ last if ($uri =~ s/$m->[1]/$m->[0]/) ;
Branch: 1 branch
BranchTrueFalseTotal
if $uri =~ s/$m->[1]/$m->[0]/ 0 0 0
202 }
203 #print STDERR "<uri_client2server $uri\n" ;
204  
205 0 return $uri ;
206 }
207  
208 # ---------------------------------------------------------------------------
209  
210 sub file_server2client
211 0 ▶ {
Subroutine file_server2client: not called CC=5 SCAR=34.0
Pod undocumented
212 0 my ($self, $fn, $map) = @_ ;
213  
214 0 ▶ $map ||= $self -> path_map ;
Condition0%0/3
$map ||= $self->path_map
l!l&&r!l&&!r
000
MC/DC0%0/2
$map ||= $self->path_map
$map $self->path_map
Truth table0%0/3
A ||= B
A= $mapB= $self->path_map
ABresult
1X1
011
000
215 0 ▶ return $fn if (!$map) ;
Branch: 1 branch
BranchTrueFalseTotal
unless $map 0 0 0
216  
217 0 foreach my $m (@$map)
218 {
219 #print STDERR "file_server2client $m->[2] -> $m->[3] : $fn\n" ;
220 0 ▶ last if ($fn =~ s/$m->[2]/$m->[3]/) ;
Branch: 1 branch
BranchTrueFalseTotal
if $fn =~ s/$m->[2]/$m->[3]/ 0 0 0
221 }
222  
223 0 return $fn ;
224 }
225  
226 # ---------------------------------------------------------------------------
227  
228 sub file_client2server
229 0 ▶ {
Subroutine file_client2server: not called CC=5 SCAR=34.0
Pod undocumented
230 0 my ($self, $fn, $map) = @_ ;
231  
232 0 ▶ $map ||= $self -> path_map ;
Condition0%0/3
$map ||= $self->path_map
l!l&&r!l&&!r
000
MC/DC0%0/2
$map ||= $self->path_map
$map $self->path_map
Truth table0%0/3
A ||= B
A= $mapB= $self->path_map
ABresult
1X1
011
000
233 0 ▶ return $fn if (!$map) ;
Branch: 1 branch
BranchTrueFalseTotal
unless $map 0 0 0
234  
235 0 $fn =~ s/\\/\//g ;
236  
237 0 foreach my $m (@$map)
238 {
239 #print STDERR "file_client2server $m->[3] -> $m->[2] : $fn\n" ;
240 0 ▶ last if ($fn =~ s/$m->[3]/$m->[2]/) ;
Branch: 1 branch
BranchTrueFalseTotal
if $fn =~ s/$m->[3]/$m->[2]/ 0 0 0
241 }
242  
243 0 return $fn ;
244 }
245  
246 # ---------------------------------------------------------------------------
247  
248 sub set_workspace_folders
249 0 ▶ {
Subroutine set_workspace_folders: not called CC=2 SCAR=17.9
Pod undocumented
250 0 my ($self, $workspace_folders) = @_ ;
251  
252 0 my $folders = $self -> folders ;
253 0 foreach my $ws (@$workspace_folders)
254 {
255 0 my $diruri = $self -> uri_client2server ($ws -> {uri}) ;
256  
257 0 my $dir = substr ($diruri, 7) ;
258 0 $dir =~ s#^/(\w)%3A/#$1:/# ;
259 0 $folders -> {$ws -> {uri}} = $dir ;
260 }
261 }
262  
263 # ---------------------------------------------------------------------------
264  
265 sub add_diagnostic_messages
266 0 ▶ {
Subroutine add_diagnostic_messages: not called CC=13 SCAR=52.0
Pod undocumented
267 0 my ($self, $server, $uri, $source, $messages, $version) = @_ ;
268  
269 0 my $files = $self -> files ;
270 0 $files -> {$uri}{messages}{$source} = $messages ;
271 0 ▶ $files -> {$uri}{messages_version} = $version if (defined ($version));
Branch: 1 branch
BranchTrueFalseTotal
if defined $version 0 0 0
272  
273 # make sure all old messages associated with this uri are cleaned up
274 0 my %diags = ( map { $_ => [] } @{$files -> {$uri}{diags} } ) ;
275 0 foreach my $src (keys %{$files -> {$uri}{messages}})
276 {
277 0 my $msgs = $files -> {$uri}{messages}{$src} ;
278 0 ▶ if ($msgs && @$msgs)
Branch: 1 branch
BranchTrueFalseTotal
if ($msgs and @$msgs) 0 0 0
Condition0%0/3
$msgs and @$msgs
!ll&&!rl&&r
000
MC/DC0%0/2
$msgs and @$msgs
$msgs @$msgs
Truth table0%0/3
A and B
A= $msgsB= @$msgs
ABresult
0X0
100
111
279 {
280 0 my $line ;
281 0 my $lineno = 0 ;
282 0 my $filename ;
283 0 my $lastline = 1 ;
284 0 my $msg ;
285 my $severity ;
286 0 foreach $line (@$msgs)
287 {
288 0 ($filename, $lineno, $severity, $msg) = @$line ;
289 0 ▶ if ($lineno)
Branch: 1 branch
BranchTrueFalseTotal
if ($lineno) 0 0 0
290 {
291 0 ▶ if ($msg)
Branch: 1 branch
BranchTrueFalseTotal
if ($msg) 0 0 0
292 {
293 0 ▶ my $diag =
Branch: 1 branch
BranchTrueFalseTotal
$severity ? : 0 0 0
294 {
295 # range: Range;
296 # severity?: DiagnosticSeverity;
297 # code?: number | string;
298 # codeDescription?: CodeDescription;
299 # source?: string;
300 # message: string;
301 # tags?: DiagnosticTag[];
302 # relatedInformation?: DiagnosticRelatedInformation[];
303 # data?: unknown;
304  
305 # DiagnosticSeverity
306 # const Error: 1 = 1;
307 # const Warning: 2 = 2;
308 # const Information: 3 = 3;
309 # const Hint: 4 = 4;
310  
311 # DiagnosticTag
312 # * Clients are allowed to render diagnostics with this tag faded out
313 # * instead of having an error squiggle.
314 # export const Unnecessary: 1 = 1;
315 # * Clients are allowed to rendered diagnostics with this tag strike through.
316 # export const Deprecated: 2 = 2;
317  
318 # DiagnosticRelatedInformation
319 # * Represents a related message and source code location for a diagnostic.
320 # * This should be used to point to code locations that cause or are related to
321 # * a diagnostics, e.g when duplicating a symbol in a scope.
322 #
323 # * The location of this related diagnostic information.
324 # location: Location;
325 # * The message of this related diagnostic information.
326 # message: string;
327  
328 range => { start => { line => $lineno-1, character => 0 }, end => { line => $lineno+0, character => 0 }},
329 ($severity?(severity => $severity + 0):()),
330 message => $msg,
331 source => $src,
332 } ;
333 0 ▶ $diags{$filename} ||= [] ;
Condition0%0/2
$diags{$filename} ||= []
l!l
00
MC/DC0%0/1
$diags{$filename} ||= []
$diags{$filename}
Truth table0%0/2
A
A= $diags{$filename}
Aresult
11
00
334 0 push @{$diags{$filename}}, $diag ;
335 }
336 0 $lastline = $lineno ;
337 0 $lineno = 0 ;
338 0 $msg = '' ;
339 }
340 }
341 }
342 }
343 0 $files -> {$uri}{diags} = [keys %diags] ;
344  
345 0 foreach my $filename (keys %diags)
346 {
347 0 ▶ my $fnuri = !$filename || $filename eq '-'?$uri:$self -> uri_server2client ('file://' . $filename) ;
Branch: 1 branch
BranchTrueFalseTotal
!$filename || $filename eq '-' ? : 0 0 0
Condition0%0/3
not $filename or $filename eq "-"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $filename or $filename eq "-"
not $filename $filename eq "-"
Truth table0%0/3
not(A) or B
A= not $filenameB= $filename eq "-"
ABresult
1X1
011
000
348 my $result =
349 {
350 method => 'textDocument/publishDiagnostics',
351 params =>
352 {
353 uri => $fnuri,
354 0 diagnostics => $diags{$filename},
355 },
356 } ;
357  
358 0 $server -> send_notification ($result) ;
359 }
360 }
361  
362 # ---------------------------------------------------------------------------
363  
364  
365 1 1 ;
366  
« LanguageServer/DebuggerInterface.pm ↑ Summary LanguageServer/IO.pm »