blib/lib/PLS/Server/Response/Formatting.pm

filter: Statementstmt 78.9% 30 / 38 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 1 totaltotal 74.5% 38 / 51 CC 2 SCAR 7.0
CC
2
Cov
75%
__ANON__
6.0
__ANON__
2.0
new
1.2
CRAP 2.0
« blib/lib/PLS/Server/Request/CancelRequest.pm ↑ Summary blib/lib/PLS/Server/Request/Initialize.pm »
1 package PLS::Server::Response::Formatting;
2  
3 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 13 ▶use parent q(PLS::Server::Response);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 13 ▶use IO::Async::Function;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use IO::Async::Loop;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 13 ▶use PLS::Parser::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 13 ▶use PLS::Server::State;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 13 my $loop = IO::Async::Loop->new();
27 my $function = IO::Async::Function->new(
28 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
29 0 my ($self, $request, $text, $perltidyrc, $workspace_folders) = @_;
30  
31 my ($ok, $formatted) =
32 PLS::Parser::Document->format(
33 text => $text,
34 formatting_options => $request->{params}{options},
35 0 perltidyrc => $perltidyrc,
36 workspace_folders => $workspace_folders
37 );
38 0 return $ok, $formatted;
39 }
40 13 );
41 13 $loop->add($function);
42  
43 sub new
44 1 ▶{
Subroutine new: called CC=1 SCAR=1.8
Pod undocumented
45 1 my ($class, $request) = @_;
46  
47 1 my $self = bless {id => $request->{id}}, $class;
48 1 my $text = PLS::Parser::Document->text_from_uri($request->{params}{textDocument}{uri});
49 1 my $workspace_folders = PLS::Parser::Index->new->workspace_folders;
50  
51 return $function->call(args => [$self, $request, $text, $PLS::Server::State::CONFIG->{perltidy}{perltidyrc}, $workspace_folders])->then(
52 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
53 0 my ($ok, $formatted) = @_;
54  
55 0 ▶ if ($ok)
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 0 0 0
56 {
57 0 $self->{result} = $formatted;
58 }
59 else
60 {
61 0 $self->{error} = $formatted;
62 }
63  
64 0 return $self;
65 }
66 1 );
67 } ## end sub new
68  
69 13 1;
« blib/lib/PLS/Server/Request/CancelRequest.pm ↑ Summary blib/lib/PLS/Server/Request/Initialize.pm »