line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PLS::Server::Request::Workspace::ExecuteCommand; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
55
|
use strict; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
219
|
|
4
|
9
|
|
|
9
|
|
46
|
use warnings; |
|
9
|
|
|
|
|
10
|
|
|
9
|
|
|
|
|
205
|
|
5
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
48
|
use parent 'PLS::Server::Request'; |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
43
|
|
7
|
|
|
|
|
|
|
|
8
|
9
|
|
|
9
|
|
414
|
use PLS::Parser::Document; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
146
|
|
9
|
9
|
|
|
9
|
|
3378
|
use PLS::Server::Request::Workspace::ApplyEdit; |
|
9
|
|
|
|
|
26
|
|
|
9
|
|
|
|
|
1644
|
|
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
|
|
|
|
|
|
|
{ |
53
|
0
|
|
|
0
|
0
|
|
my ($self, $server) = @_; |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if ($self->{params}{command} eq 'pls.sortImports') |
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
|
0
|
|
|
|
|
error => { |
64
|
|
|
|
|
|
|
code => -32602, |
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
|
|
|
|
|
|
|
1; |