blib/lib/PLS/Server/Request/Workspace/ExecuteCommand.pm

filter: Statementstmt 66.6% 16 / 24 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 60.0% 21 / 35 CC 3 SCAR 16.3
CC
3
Cov
57%
service
12.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.1
« blib/lib/PLS/Server/Request/Workspace/DidChangeWorkspaceFolders.pm ↑ Summary blib/lib/PLS/Server/Method/ServerMethod.pm »
1 package PLS::Server::Request::Workspace::ExecuteCommand;
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 'PLS::Server::Request';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 13 ▶use PLS::Parser::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use PLS::Server::Request::Workspace::ApplyEdit;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 PLS::Server::Request::Workspace::ExecuteCommand
14  
15 =head1 DESCRIPTION
16  
17 This is a message from the client to the server requesting that a
18 command be executed.
19  
20 The commands that are currently implemented are:
21  
22 =over
23  
24 =item pls.sortImports
25  
26 This sorts the imports of the current Perl file. The sorting follows this order:
27  
28 =over
29  
30 =item C<use strict> and C<use warnings>
31  
32 =item C<use parent> and C<use base>
33  
34 =item Other pragmas (excluding C<use constant>)
35  
36 =item Core and external imports
37  
38 =item Internal imports (from the current project)
39  
40 =item Constants (C<use constant>)
41  
42 =back
43  
44 This command is not perfect and is a work in progress. It does not handle
45 comments or non-contiguous imports well.
46  
47 =back
48  
49 =cut
50  
51 sub service
52 0 ▶{
Subroutine service: not called CC=3 SCAR=24.8
Pod undocumented
53 0 my ($self, $server) = @_;
54  
55 0 ▶ if ($self->{params}{command} eq 'pls.sortImports')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"params"}{"command"} eq "pls.sortImports") 0 0 0
56 {
57 0 my $file = $self->{params}{arguments}[0]{path};
58 0 my $doc = PLS::Parser::Document->new(path => $file);
59 return
60 PLS::Server::Response->new(
61 {
62 id => $self->{id},
63 0 ▶ error => {
Branch: 1 branch
BranchTrueFalseTotal
if ref $doc ne "PLS::Parser::Document" 0 0 0
64 code => -32_602,
65 message => 'Failed to sort imports.',
66 data => $file
67 }
68 }
69 )
70 if (ref $doc ne 'PLS::Parser::Document');
71 0 my ($new_text, $lines) = $doc->sort_imports();
72  
73 0 $server->send_server_request(PLS::Server::Request::Workspace::ApplyEdit->new(text => $new_text, path => $file, lines => $lines));
74 } ## end if ($self->{params}{command...})
75  
76 0 return PLS::Server::Response->new({id => $self->{id}, result => undef});
77 } ## end sub service
78  
79 13 1;
« blib/lib/PLS/Server/Request/Workspace/DidChangeWorkspaceFolders.pm ↑ Summary blib/lib/PLS/Server/Method/ServerMethod.pm »