File Coverage

blib/lib/PLS/Server/Request/Workspace/Configuration.pm
Criterion Covered Total %
statement 69 79 87.3
branch 11 26 42.3
condition 5 14 35.7
subroutine 14 14 100.0
pod 0 3 0.0
total 99 136 72.7


line stmt bran cond sub pod time code
1              
2             use strict;
3 9     9   54 use warnings;
  9         81  
  9         304  
4 9     9   60  
  9         17  
  9         434  
5             use parent 'PLS::Server::Request';
6 9     9   102  
  9         104  
  9         246  
7             use List::Util;
8 9     9   1097 use Scalar::Util;
  9         72  
  9         2007  
9 9     9   78  
  9         74  
  9         772  
10             use PLS::Parser::Document;
11 9     9   165 use PLS::Parser::Index;
  9         74  
  9         422  
12 9     9   61 use PLS::Parser::PackageSymbols;
  9         2944  
  9         478  
13 9     9   110 use PLS::Parser::Pod;
  9         65  
  9         413  
14 9     9   118 use PLS::Server::Request::TextDocument::PublishDiagnostics;
  9         17  
  9         408  
15 9     9   117 use PLS::Server::State;
  9         24  
  9         404  
16 9     9   135  
  9         66  
  9         6765  
17             =head1 NAME
18              
19             PLS::Server::Request::Workspace::Configuration
20              
21             =head1 DESCRIPTION
22              
23             This is a message from the server to the client requesting that it send
24             the values of some configuration items.
25              
26             PLS requests all configuration starting with C<pls.>.
27              
28             This class also handles the response from the client which stores the configuration
29             in memory.
30              
31             =cut
32              
33             {
34             my ($class) = @_;
35              
36 5     5 0 47 return bless {
37             id => undef, # assigned by the server
38 5         209 method => 'workspace/configuration',
39             params => {
40             items => [{section => 'perl'}, {section => 'pls'}]
41             }
42             }, $class;
43             } ## end sub new
44              
45             {
46             my ($self, $response, $server) = @_;
47              
48             return if (Scalar::Util::reftype($response) ne 'HASH' or ref $response->{result} ne 'ARRAY');
49 4     4 0 31  
50             my $config = {};
51 4 50 33     93  
52             foreach my $result (@{$response->{result}})
53 4         28 {
54             next if (ref $result ne 'HASH');
55 4         28  
  4         62  
56             foreach my $key (keys %{$result})
57 4 50       43 {
58             $config->{$key} = $result->{$key} unless (exists $config->{$key});
59 4         9 }
  4         25  
60             } ## end foreach my $result (@{$response...})
61 28 50       123  
62             convert_config($config);
63              
64             my $index = PLS::Parser::Index->new();
65 4         24 my @inc;
66              
67 4         67 # Replace $ROOT_PATH with actual workspace paths in inc
68 4         18 if (exists $config->{inc} and ref $config->{inc} eq 'ARRAY')
69             {
70             foreach my $inc (@{$config->{inc}})
71 4 50 33     77 {
72             foreach my $folder (@{$index->workspace_folders})
73 4         31 {
  4         27  
74             my $interpolated = $inc =~ s/\$ROOT_PATH/$folder/gr;
75 0         0 push @inc, $interpolated;
  0         0  
76             }
77 0         0 } ## end foreach my $inc (@{$config->...})
78 0         0  
79             $config->{inc} = [List::Util::uniq sort @inc];
80             } ## end if (exists $config->{inc...})
81              
82 4         24 if (exists $config->{syntax}{perl} and length $config->{syntax}{perl})
83             {
84             PLS::Parser::Pod->set_perl_exe($config->{syntax}{perl});
85 4 50 33     63 }
86              
87 0         0 if (exists $config->{syntax}{args} and ref $config->{syntax}{args} eq 'ARRAY' and scalar @{$config->{syntax}{args}})
88             {
89             PLS::Parser::Pod->set_perl_args($config->{syntax}{args});
90 4 0 33     38 }
  0   50     0  
91              
92 0         0 $PLS::Server::State::CONFIG = $config;
93              
94             # @INC may have changed - republish diagnostics
95 4         113 foreach my $uri (@{PLS::Parser::Document->open_files()})
96             {
97             $server->send_server_request(PLS::Server::Request::TextDocument::PublishDiagnostics->new(uri => $uri));
98 4         16 }
  4         55  
99              
100 0         0 PLS::Parser::PackageSymbols::start_package_symbols_process($config);
101             PLS::Parser::PackageSymbols::start_imported_package_symbols_process($config);
102              
103 4         118 return;
104 4         190 } ## end sub handle_response
105              
106 4         233 {
107             my ($config) = @_;
108              
109             if (length $config->{pls})
110             {
111 4     4 0 36 $config->{cmd} = $config->{pls} unless (length $config->{cmd});
112             delete $config->{pls};
113 4 50       39 }
114              
115 4 50       74 if (ref $config->{plsargs} eq 'ARRAY')
116 4         17 {
117             $config->{args} = $config->{plsargs} if (ref $config->{args} ne 'ARRAY');
118             delete $config->{plsargs};
119 4 50       32 }
120              
121 0 0       0 $config->{perltidy} = {} if (ref $config->{perltidy} ne 'HASH');
122 0         0  
123             if (length $config->{perltidyrc})
124             {
125 4 50       55 $config->{perltidy}{perltidyrc} = $config->{perltidyrc} unless (length $config->{perltidy}{perltidyrc});
126             delete $config->{perltidyrc};
127 4 50       69 }
128              
129 4 50       19 return;
130 4         27 } ## end sub convert_config
131              
132             1;