| 1 | package PLS::Server::Response::RangeFormatting; | ||||||||||
| 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::RangeFormatting | ||||||||||
| 17 | |||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||
| 19 | |||||||||||
| 20 | This is a message from the server to the client with a document range | ||||||||||
| 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_range( | ||||||||||
| 33 | text => $text, | ||||||||||
| 34 | range => $request->{params}{range}, | ||||||||||
| 35 | formatting_options => $request->{params}{options}, | ||||||||||
| 36 | 0 | perltidyrc => $perltidyrc, | |||||||||
| 37 | workspace_folders => $workspace_folders | ||||||||||
| 38 | ); | ||||||||||
| 39 | 0 | return $ok, $formatted; | |||||||||
| 40 | } | ||||||||||
| 41 | 13 | ); | |||||||||
| 42 | 13 | $loop->add($function); | |||||||||
| 43 | |||||||||||
| 44 | sub new | ||||||||||
| 45 | 0 | ▶ | { | ||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 46 | 0 | my ($class, $request) = @_; | |||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | if (ref $request->{params}{options} eq 'HASH') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | { | ||||||||||
| 50 | # these options aren't really valid for range formatting | ||||||||||
| 51 | 0 | delete $request->{params}{options}{trimFinalNewlines}; | |||||||||
| 52 | 0 | delete $request->{params}{options}{insertFinalNewline}; | |||||||||
| 53 | } ## end if (ref $request->{params...}) | ||||||||||
| 54 | |||||||||||
| 55 | 0 | my $self = bless {id => $request->{id}}, $class; | |||||||||
| 56 | 0 | my $text = PLS::Parser::Document->text_from_uri($request->{params}{textDocument}{uri}); | |||||||||
| 57 | 0 | my $workspace_folders = PLS::Parser::Index->new->workspace_folders; | |||||||||
| 58 | |||||||||||
| 59 | return $function->call(args => [$self, $request, $text, $PLS::Server::State::CONFIG->{perltidy}{perltidyrc}, $workspace_folders])->then( | ||||||||||
| 60 | 0 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 61 | 0 | my ($ok, $formatted) = @_; | |||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | if ($ok) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | { | ||||||||||
| 65 | 0 | $self->{result} = $formatted; | |||||||||
| 66 | } | ||||||||||
| 67 | else | ||||||||||
| 68 | { | ||||||||||
| 69 | 0 | $self->{error} = $formatted; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 0 | return $self; | |||||||||
| 73 | } | ||||||||||
| 74 | 0 | ); | |||||||||
| 75 | } ## end sub new | ||||||||||
| 76 | |||||||||||
| 77 | 13 | 1; | |||||||||