File Coverage

blib/lib/PLS/Server/Response/RangeFormatting.pm
Criterion Covered Total %
statement 21 33 63.6
branch 0 4 0.0
condition n/a
subroutine 7 9 77.7
pod 0 1 0.0
total 28 47 59.5


line stmt bran cond sub pod time code
1              
2             use strict;
3 9     9   72 use warnings;
  9         10  
  9         228  
4 9     9   40  
  9         17  
  9         316  
5             use parent q(PLS::Server::Response);
6 9     9   53  
  9         10  
  9         44  
7             use IO::Async::Function;
8 9     9   834 use IO::Async::Loop;
  9         74  
  9         362  
9 9     9   46  
  9         18  
  9         170  
10             use PLS::Parser::Document;
11 9     9   37 use PLS::Server::State;
  9         58  
  9         466  
12 9     9   47  
  9         17  
  9         3538  
13             =head1 NAME
14              
15             PLS::Server::Response::RangeFormatting
16              
17             =head1 DESCRIPTION
18              
19             This is a message from the server to the client with a document range
20             after having been formatted.
21              
22             =cut
23              
24             # Set up formatting as a function because it can be slow
25             my $loop = IO::Async::Loop->new();
26             my $function = IO::Async::Function->new(
27             code => sub {
28             my ($self, $request, $text, $perltidyrc) = @_;
29              
30             my ($ok, $formatted) = PLS::Parser::Document->format_range(text => $text, range => $request->{params}{range}, formatting_options => $request->{params}{options}, perltidyrc => $perltidyrc);
31             return $ok, $formatted;
32             }
33             );
34             $loop->add($function);
35              
36             {
37             my ($class, $request) = @_;
38              
39 0     0 0   if (ref $request->{params}{options} eq 'HASH')
40             {
41 0 0         # these options aren't really valid for range formatting
42             delete $request->{params}{options}{trimFinalNewlines};
43             delete $request->{params}{options}{insertFinalNewline};
44 0           } ## end if (ref $request->{params...})
45 0            
46             my $self = bless {id => $request->{id}}, $class;
47             my $text = PLS::Parser::Document->text_from_uri($request->{params}{textDocument}{uri});
48 0            
49 0           return $function->call(args => [$self, $request, $text, $PLS::Server::State::CONFIG->{perltidy}{perltidyrc}])->then(
50             sub {
51             my ($ok, $formatted) = @_;
52              
53 0     0     if ($ok)
54             {
55 0 0         $self->{result} = $formatted;
56             }
57 0           else
58             {
59             $self->{error} = $formatted;
60             }
61 0            
62             return $self;
63             }
64 0           );
65             } ## end sub new
66 0            
67             1;