line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PLS::Server::Response::Formatting; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
54
|
use strict; |
|
9
|
|
|
|
|
58
|
|
|
9
|
|
|
|
|
235
|
|
4
|
9
|
|
|
9
|
|
52
|
use warnings; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
191
|
|
5
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
35
|
use parent q(PLS::Server::Response); |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
36
|
|
7
|
|
|
|
|
|
|
|
8
|
9
|
|
|
9
|
|
428
|
use IO::Async::Function; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
147
|
|
9
|
9
|
|
|
9
|
|
28
|
use IO::Async::Loop; |
|
9
|
|
|
|
|
10
|
|
|
9
|
|
|
|
|
240
|
|
10
|
|
|
|
|
|
|
|
11
|
9
|
|
|
9
|
|
54
|
use PLS::Parser::Document; |
|
9
|
|
|
|
|
49
|
|
|
9
|
|
|
|
|
254
|
|
12
|
9
|
|
|
9
|
|
53
|
use PLS::Server::State; |
|
9
|
|
|
|
|
10
|
|
|
9
|
|
|
|
|
2490
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
PLS::Server::Response::Formatting |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
This is a message from the server to the client with the current document |
21
|
|
|
|
|
|
|
after having been formatted. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Set up formatting as a function because it can be slow |
26
|
|
|
|
|
|
|
my $loop = IO::Async::Loop->new(); |
27
|
|
|
|
|
|
|
my $function = IO::Async::Function->new( |
28
|
|
|
|
|
|
|
code => sub { |
29
|
|
|
|
|
|
|
my ($self, $request, $text, $perltidyrc) = @_; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my ($ok, $formatted) = PLS::Parser::Document->format(text => $text, formatting_options => $request->{params}{options}, perltidyrc => $perltidyrc); |
32
|
|
|
|
|
|
|
return $ok, $formatted; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
$loop->add($function); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new |
38
|
|
|
|
|
|
|
{ |
39
|
1
|
|
|
1
|
0
|
4
|
my ($class, $request) = @_; |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
8
|
my $self = bless {id => $request->{id}}, $class; |
42
|
1
|
|
|
|
|
7
|
my $text = PLS::Parser::Document->text_from_uri($request->{params}{textDocument}{uri}); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return $function->call(args => [$self, $request, $text, $PLS::Server::State::CONFIG->{perltidy}{perltidyrc}])->then( |
45
|
|
|
|
|
|
|
sub { |
46
|
0
|
|
|
0
|
|
|
my ($ok, $formatted) = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
if ($ok) |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
|
|
|
|
|
$self->{result} = $formatted; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else |
53
|
|
|
|
|
|
|
{ |
54
|
0
|
|
|
|
|
|
$self->{error} = $formatted; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
return $self; |
58
|
|
|
|
|
|
|
} |
59
|
1
|
|
|
|
|
19
|
); |
60
|
|
|
|
|
|
|
} ## end sub new |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |