| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use strict; |
|
3
|
9
|
|
|
9
|
|
62
|
use warnings; |
|
|
9
|
|
|
|
|
18
|
|
|
|
9
|
|
|
|
|
206
|
|
|
4
|
9
|
|
|
9
|
|
44
|
|
|
|
9
|
|
|
|
|
18
|
|
|
|
9
|
|
|
|
|
188
|
|
|
5
|
|
|
|
|
|
|
use parent 'PLS::Server::Request'; |
|
6
|
9
|
|
|
9
|
|
37
|
|
|
|
9
|
|
|
|
|
26
|
|
|
|
9
|
|
|
|
|
44
|
|
|
7
|
|
|
|
|
|
|
use Encode; |
|
8
|
9
|
|
|
9
|
|
409
|
use File::Basename; |
|
|
9
|
|
|
|
|
19
|
|
|
|
9
|
|
|
|
|
944
|
|
|
9
|
9
|
|
|
9
|
|
54
|
use File::Path; |
|
|
9
|
|
|
|
|
26
|
|
|
|
9
|
|
|
|
|
518
|
|
|
10
|
9
|
|
|
9
|
|
60
|
use File::Spec; |
|
|
9
|
|
|
|
|
18
|
|
|
|
9
|
|
|
|
|
360
|
|
|
11
|
9
|
|
|
9
|
|
101
|
use File::Temp; |
|
|
9
|
|
|
|
|
26
|
|
|
|
9
|
|
|
|
|
174
|
|
|
12
|
9
|
|
|
9
|
|
37
|
use IO::Async::Function; |
|
|
9
|
|
|
|
|
9
|
|
|
|
9
|
|
|
|
|
759
|
|
|
13
|
9
|
|
|
9
|
|
45
|
use IO::Async::Loop; |
|
|
9
|
|
|
|
|
18
|
|
|
|
9
|
|
|
|
|
299
|
|
|
14
|
9
|
|
|
9
|
|
61
|
use IO::Async::Process; |
|
|
9
|
|
|
|
|
10
|
|
|
|
9
|
|
|
|
|
155
|
|
|
15
|
9
|
|
|
9
|
|
37
|
use Path::Tiny; |
|
|
9
|
|
|
|
|
18
|
|
|
|
9
|
|
|
|
|
193
|
|
|
16
|
9
|
|
|
9
|
|
44
|
use Perl::Critic; |
|
|
9
|
|
|
|
|
17
|
|
|
|
9
|
|
|
|
|
331
|
|
|
17
|
9
|
|
|
9
|
|
4429
|
use PPI; |
|
|
9
|
|
|
|
|
5079391
|
|
|
|
9
|
|
|
|
|
427
|
|
|
18
|
9
|
|
|
9
|
|
97
|
use URI; |
|
|
9
|
|
|
|
|
18
|
|
|
|
9
|
|
|
|
|
168
|
|
|
19
|
9
|
|
|
9
|
|
52
|
|
|
|
9
|
|
|
|
|
18
|
|
|
|
9
|
|
|
|
|
192
|
|
|
20
|
|
|
|
|
|
|
use PLS::Parser::Pod; |
|
21
|
9
|
|
|
9
|
|
52
|
use PLS::Server::State; |
|
|
9
|
|
|
|
|
22
|
|
|
|
9
|
|
|
|
|
190
|
|
|
22
|
9
|
|
|
9
|
|
45
|
|
|
|
9
|
|
|
|
|
10
|
|
|
|
9
|
|
|
|
|
11941
|
|
|
23
|
|
|
|
|
|
|
=head1 NAME |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
PLS::Server::Request::TextDocument::PublishDiagnostics |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This is a message from the server to the client requesting that |
|
30
|
|
|
|
|
|
|
diagnostics be published. |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
These diagnostics currently include compilation errors and linting (using L<perlcritic>). |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $function = IO::Async::Function->new(code => \&run_perlcritic); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $loop = IO::Async::Loop->new(); |
|
39
|
|
|
|
|
|
|
$loop->add($function); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
{ |
|
42
|
|
|
|
|
|
|
my ($class, %args) = @_; |
|
43
|
|
|
|
|
|
|
|
|
44
|
2
|
|
|
2
|
0
|
25
|
return if (ref $PLS::Server::State::CONFIG ne 'HASH'); |
|
45
|
|
|
|
|
|
|
|
|
46
|
2
|
50
|
|
|
|
23
|
my $uri = URI->new($args{uri}); |
|
47
|
|
|
|
|
|
|
return if (ref $uri ne 'URI::file'); |
|
48
|
2
|
|
|
|
|
47
|
|
|
49
|
2
|
50
|
|
|
|
267
|
my $self = bless { |
|
50
|
|
|
|
|
|
|
method => 'textDocument/publishDiagnostics', |
|
51
|
2
|
|
|
|
|
55
|
params => { |
|
52
|
|
|
|
|
|
|
uri => $uri->as_string, |
|
53
|
|
|
|
|
|
|
diagnostics => [] |
|
54
|
|
|
|
|
|
|
}, |
|
55
|
|
|
|
|
|
|
notification => 1 |
|
56
|
|
|
|
|
|
|
}, |
|
57
|
|
|
|
|
|
|
$class; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my (undef, $dir) = File::Basename::fileparse($uri->file); |
|
60
|
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
88
|
my $source = $uri->file; |
|
62
|
|
|
|
|
|
|
my $text = PLS::Parser::Document->text_from_uri($uri->as_string); |
|
63
|
2
|
|
|
|
|
496
|
$source = $text if (ref $text eq 'SCALAR'); |
|
64
|
2
|
|
|
|
|
175
|
my $version = PLS::Parser::Document::uri_version($uri->as_string); |
|
65
|
2
|
50
|
|
|
|
23
|
my $client_has_version_support = $PLS::Server::State::CLIENT_CAPABILITIES->{textDocument}{publishDiagnostics}{versionSupport}; |
|
66
|
2
|
|
|
|
|
21
|
$self->{params}{version} = $version if (length $version and $client_has_version_support); |
|
67
|
2
|
|
|
|
|
16
|
|
|
68
|
2
|
50
|
33
|
|
|
66
|
# If closing, return empty list of diagnostics. |
|
69
|
|
|
|
|
|
|
return Future->done($self) if $args{close}; |
|
70
|
|
|
|
|
|
|
|
|
71
|
2
|
50
|
|
|
|
37
|
my @futures; |
|
72
|
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
16
|
push @futures, get_compilation_errors($source, $dir) if (defined $PLS::Server::State::CONFIG->{syntax}{enabled} and $PLS::Server::State::CONFIG->{syntax}{enabled}); |
|
74
|
|
|
|
|
|
|
push @futures, get_perlcritic_errors($source, $uri->file) |
|
75
|
2
|
50
|
33
|
|
|
28
|
if (defined $PLS::Server::State::CONFIG->{perlcritic}{enabled} and $PLS::Server::State::CONFIG->{perlcritic}{enabled}); |
|
76
|
|
|
|
|
|
|
|
|
77
|
2
|
50
|
33
|
|
|
137
|
return Future->wait_all(@futures)->then( |
|
78
|
|
|
|
|
|
|
sub { |
|
79
|
|
|
|
|
|
|
my $current_version = PLS::Parser::Document::uri_version($uri->as_string); |
|
80
|
|
|
|
|
|
|
|
|
81
|
1
|
|
|
1
|
|
363886
|
# No version will be returned if the document has been closed. |
|
82
|
|
|
|
|
|
|
# Since the only way we got here is if the document is open, we |
|
83
|
|
|
|
|
|
|
# should return nothing, since any diagnostics we return will be from |
|
84
|
|
|
|
|
|
|
# when the document was still open. |
|
85
|
|
|
|
|
|
|
return Future->done(undef) unless (length $current_version); |
|
86
|
|
|
|
|
|
|
|
|
87
|
1
|
50
|
|
|
|
13
|
# If the document has been updated since the diagnostics were created, |
|
88
|
|
|
|
|
|
|
# send nothing back. The next update will re-trigger the diagnostics. |
|
89
|
|
|
|
|
|
|
return Future->done(undef) if (length $version and $current_version > $version); |
|
90
|
|
|
|
|
|
|
|
|
91
|
1
|
50
|
33
|
|
|
25
|
@{$self->{params}{diagnostics}} = map { $_->result } @_; |
|
92
|
|
|
|
|
|
|
|
|
93
|
1
|
|
|
|
|
10
|
return Future->done($self); |
|
|
1
|
|
|
|
|
30
|
|
|
|
2
|
|
|
|
|
31
|
|
|
94
|
|
|
|
|
|
|
} |
|
95
|
1
|
|
|
|
|
15
|
); |
|
96
|
|
|
|
|
|
|
} ## end sub new |
|
97
|
2
|
|
|
|
|
3321
|
|
|
98
|
|
|
|
|
|
|
{ |
|
99
|
|
|
|
|
|
|
my ($source, $dir) = @_; |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $temp; |
|
102
|
2
|
|
|
2
|
0
|
44
|
my $future = $loop->new_future(); |
|
103
|
|
|
|
|
|
|
|
|
104
|
2
|
|
|
|
|
12
|
my $fh; |
|
105
|
2
|
|
|
|
|
15
|
my $path; |
|
106
|
|
|
|
|
|
|
|
|
107
|
2
|
|
|
|
|
55
|
if (ref $source eq 'SCALAR') |
|
108
|
|
|
|
|
|
|
{ |
|
109
|
|
|
|
|
|
|
$temp = eval { File::Temp->new(CLEANUP => 0, TEMPLATE => '.pls-tmp-XXXXXXXXXX', DIR => $dir) }; |
|
110
|
2
|
50
|
|
|
|
15
|
$temp = eval { File::Temp->new(CLEANUP => 0) } if (ref $temp ne 'File::Temp'); |
|
111
|
|
|
|
|
|
|
$path = $temp->filename; |
|
112
|
2
|
|
|
|
|
18
|
|
|
|
2
|
|
|
|
|
90
|
|
|
113
|
2
|
50
|
|
|
|
1498
|
$future->on_done(sub { unlink $temp }); |
|
|
0
|
|
|
|
|
0
|
|
|
114
|
2
|
|
|
|
|
13
|
my $source_text = Encode::encode_utf8($$source); |
|
115
|
|
|
|
|
|
|
|
|
116
|
2
|
|
|
1
|
|
69
|
print {$temp} $source_text; |
|
|
1
|
|
|
|
|
59
|
|
|
117
|
2
|
|
|
|
|
103
|
close $temp; |
|
118
|
|
|
|
|
|
|
|
|
119
|
2
|
|
|
|
|
43
|
open $fh, '<', \$source_text; |
|
|
2
|
|
|
|
|
22
|
|
|
120
|
2
|
|
|
|
|
92
|
} ## end if (ref $source eq 'SCALAR'...) |
|
121
|
|
|
|
|
|
|
else |
|
122
|
2
|
|
|
2
|
|
149
|
{ |
|
|
2
|
|
|
|
|
30
|
|
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
57
|
|
|
123
|
|
|
|
|
|
|
$path = $source; |
|
124
|
|
|
|
|
|
|
open $fh, '<', $path or return []; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
0
|
|
|
|
|
0
|
|
|
127
|
0
|
0
|
|
|
|
0
|
my @line_lengths; |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
while (my $line = <$fh>) |
|
130
|
2
|
|
|
|
|
2472
|
{ |
|
131
|
|
|
|
|
|
|
chomp $line; |
|
132
|
2
|
|
|
|
|
16
|
$line_lengths[$.] = length $line; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
234
|
|
|
|
|
233
|
|
|
135
|
234
|
|
|
|
|
405
|
close $fh; |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
my $perl = PLS::Parser::Pod->get_perl_exe(); |
|
138
|
2
|
|
|
|
|
18
|
my $inc = PLS::Parser::Pod->get_clean_inc(); |
|
139
|
|
|
|
|
|
|
my $args = PLS::Parser::Pod->get_perl_args(); |
|
140
|
2
|
|
|
|
|
46
|
my @inc = map { "-I$_" } @{$inc // []}; |
|
141
|
2
|
|
|
|
|
44
|
my $index = PLS::Parser::Index->new(); |
|
142
|
2
|
|
|
|
|
53
|
my $workspace_folder = List::Util::first { path($_)->subsumes($path) } @{$index->workspace_folders}; |
|
143
|
2
|
|
50
|
|
|
21
|
($workspace_folder) = @{$index->workspace_folders} unless (length $workspace_folder); |
|
|
16
|
|
|
|
|
45
|
|
|
|
2
|
|
|
|
|
35
|
|
|
144
|
2
|
|
|
|
|
25
|
my $new_cwd = $PLS::Server::State::CONFIG->{cwd} // ''; |
|
145
|
2
|
|
|
2
|
|
64
|
$new_cwd =~ s/\$ROOT_PATH/$workspace_folder/; |
|
|
2
|
|
|
|
|
62
|
|
|
|
2
|
|
|
|
|
24
|
|
|
146
|
2
|
50
|
|
|
|
613
|
|
|
|
0
|
|
|
|
|
0
|
|
|
147
|
2
|
|
50
|
|
|
9
|
my @setup; |
|
148
|
2
|
|
|
|
|
8
|
push @setup, (chdir => $new_cwd) if (length $new_cwd and -d $new_cwd); |
|
149
|
|
|
|
|
|
|
|
|
150
|
2
|
|
|
|
|
14
|
my @diagnostics; |
|
151
|
2
|
50
|
33
|
|
|
20
|
|
|
152
|
|
|
|
|
|
|
my $proc = IO::Async::Process->new( |
|
153
|
2
|
|
|
|
|
16
|
command => [$perl, @inc, '-c', $path, @{$args}], |
|
154
|
|
|
|
|
|
|
setup => \@setup, |
|
155
|
|
|
|
|
|
|
stderr => { |
|
156
|
2
|
|
|
|
|
1448
|
on_read => sub { |
|
157
|
|
|
|
|
|
|
my ($stream, $buffref, $eof) = @_; |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
while ($$buffref =~ s/^(.*)\n//) |
|
160
|
2
|
|
|
2
|
|
1045684
|
{ |
|
161
|
|
|
|
|
|
|
my $line = $1; |
|
162
|
2
|
|
|
|
|
44
|
next if $line =~ /syntax OK$/; |
|
163
|
|
|
|
|
|
|
|
|
164
|
1
|
|
|
|
|
14
|
# Hide warnings from circular references |
|
165
|
1
|
50
|
|
|
|
22
|
next if $line =~ /Subroutine .+ redefined/; |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# Hide "BEGIN failed" and "Compilation failed" messages - these provide no useful info. |
|
168
|
0
|
0
|
|
|
|
0
|
#next if $line =~ /^BEGIN failed/; |
|
169
|
|
|
|
|
|
|
#next if $line =~ /^Compilation failed/; |
|
170
|
|
|
|
|
|
|
if (my ($error, $file, $line, $area) = $line =~ /^(.+) at (.+?) line (\d+)(, .+)?/) |
|
171
|
|
|
|
|
|
|
{ |
|
172
|
|
|
|
|
|
|
$error .= $area if (length $area); |
|
173
|
0
|
0
|
|
|
|
0
|
$line = int $line; |
|
174
|
|
|
|
|
|
|
next if $file ne $path; |
|
175
|
0
|
0
|
|
|
|
0
|
|
|
176
|
0
|
|
|
|
|
0
|
push @diagnostics, |
|
177
|
0
|
0
|
|
|
|
0
|
{ |
|
178
|
|
|
|
|
|
|
range => { |
|
179
|
0
|
|
|
|
|
0
|
start => {line => $line - 1, character => 0}, |
|
180
|
|
|
|
|
|
|
end => {line => $line - 1, character => $line_lengths[$line]} |
|
181
|
|
|
|
|
|
|
}, |
|
182
|
|
|
|
|
|
|
message => $error, |
|
183
|
|
|
|
|
|
|
severity => 1, |
|
184
|
|
|
|
|
|
|
source => 'perl', |
|
185
|
|
|
|
|
|
|
}; |
|
186
|
|
|
|
|
|
|
} ## end if (my ($error, $file,...)) |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
} ## end while ($$buffref =~ s/^(.*)\n//...) |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
return 0; |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
}, |
|
193
|
2
|
|
|
|
|
14
|
stdout => { |
|
194
|
|
|
|
|
|
|
on_read => sub { |
|
195
|
|
|
|
|
|
|
my ($stream, $buffref) = @_; |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# Discard STDOUT, otherwise it might interfere with the server execution. |
|
198
|
1
|
|
|
1
|
|
18963
|
# This can happen if there is a BEGIN block that prints to STDOUT. |
|
199
|
|
|
|
|
|
|
$$buffref = ''; |
|
200
|
|
|
|
|
|
|
return 0; |
|
201
|
|
|
|
|
|
|
} |
|
202
|
1
|
|
|
|
|
4
|
}, |
|
203
|
1
|
|
|
|
|
11
|
on_finish => sub { |
|
204
|
|
|
|
|
|
|
$future->done(@diagnostics); |
|
205
|
|
|
|
|
|
|
} |
|
206
|
|
|
|
|
|
|
); |
|
207
|
1
|
|
|
1
|
|
931
|
|
|
208
|
|
|
|
|
|
|
$loop->add($proc); |
|
209
|
2
|
|
|
|
|
19
|
|
|
210
|
|
|
|
|
|
|
return $future; |
|
211
|
2
|
|
|
|
|
600
|
} ## end sub get_compilation_errors |
|
212
|
|
|
|
|
|
|
|
|
213
|
2
|
|
|
|
|
16146
|
{ |
|
214
|
|
|
|
|
|
|
my ($source, $path) = @_; |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
my ($profile) = glob $PLS::Server::State::CONFIG->{perlcritic}{perlcriticrc}; |
|
217
|
|
|
|
|
|
|
undef $profile if (not length $profile or not -f $profile or not -r $profile); |
|
218
|
2
|
|
|
2
|
0
|
716
|
|
|
219
|
|
|
|
|
|
|
return $function->call(args => [$profile, $source, $path]); |
|
220
|
2
|
|
|
|
|
179
|
} ## end sub get_perlcritic_errors |
|
221
|
2
|
50
|
33
|
|
|
101
|
|
|
|
|
|
33
|
|
|
|
|
|
222
|
|
|
|
|
|
|
{ |
|
223
|
2
|
|
|
|
|
71
|
my ($profile, $source, $path) = @_; |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
my $critic = Perl::Critic->new(-profile => $profile); |
|
226
|
|
|
|
|
|
|
my %args; |
|
227
|
|
|
|
|
|
|
$args{filename} = $path if (ref $source eq 'SCALAR'); |
|
228
|
0
|
|
|
0
|
0
|
0
|
my $doc = PPI::Document->new($source, %args); |
|
229
|
|
|
|
|
|
|
my @violations = eval { $critic->critique($doc) }; |
|
230
|
0
|
|
|
|
|
0
|
|
|
231
|
0
|
|
|
|
|
0
|
my @diagnostics; |
|
232
|
0
|
0
|
|
|
|
0
|
|
|
233
|
0
|
|
|
|
|
0
|
# Mapping from perlcritic severity to LSP severity |
|
234
|
0
|
|
|
|
|
0
|
my %severity_map = ( |
|
|
0
|
|
|
|
|
0
|
|
|
235
|
|
|
|
|
|
|
5 => 1, |
|
236
|
0
|
|
|
|
|
0
|
4 => 1, |
|
237
|
|
|
|
|
|
|
3 => 2, |
|
238
|
|
|
|
|
|
|
2 => 3, |
|
239
|
0
|
|
|
|
|
0
|
1 => 3 |
|
240
|
|
|
|
|
|
|
); |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
foreach my $violation (@violations) |
|
243
|
|
|
|
|
|
|
{ |
|
244
|
|
|
|
|
|
|
my $severity = $severity_map{$violation->severity}; |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
my $doc = URI->new(); |
|
247
|
0
|
|
|
|
|
0
|
$doc->scheme('https'); |
|
248
|
|
|
|
|
|
|
$doc->authority('metacpan.org'); |
|
249
|
0
|
|
|
|
|
0
|
$doc->path('pod/' . $violation->policy); |
|
250
|
|
|
|
|
|
|
|
|
251
|
0
|
|
|
|
|
0
|
push @diagnostics, |
|
252
|
0
|
|
|
|
|
0
|
{ |
|
253
|
0
|
|
|
|
|
0
|
range => { |
|
254
|
0
|
|
|
|
|
0
|
start => {line => $violation->line_number - 1, character => $violation->column_number - 1}, |
|
255
|
|
|
|
|
|
|
end => {line => $violation->line_number - 1, character => $violation->column_number + length($violation->source) - 1} |
|
256
|
0
|
|
|
|
|
0
|
}, |
|
257
|
|
|
|
|
|
|
message => $violation->description, |
|
258
|
|
|
|
|
|
|
code => $violation->policy, |
|
259
|
|
|
|
|
|
|
codeDescription => {href => $doc->as_string}, |
|
260
|
|
|
|
|
|
|
severity => $severity, |
|
261
|
|
|
|
|
|
|
source => 'perlcritic' |
|
262
|
|
|
|
|
|
|
}; |
|
263
|
|
|
|
|
|
|
} ## end foreach my $violation (@violations...) |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
return @diagnostics; |
|
266
|
|
|
|
|
|
|
} ## end sub run_perlcritic |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
1; |