File Coverage

blib/lib/PLS/Server/Request/Workspace/Configuration.pm
Criterion Covered Total %
statement 70 80 87.5
branch 12 28 42.8
condition 6 17 35.2
subroutine 14 14 100.0
pod 0 3 0.0
total 102 142 71.8


line stmt bran cond sub pod time code
1              
2             use strict;
3 9     9   109 use warnings;
  9         18  
  9         334  
4 9     9   117  
  9         39  
  9         476  
5             use parent 'PLS::Server::Request';
6 9     9   53  
  9         63  
  9         400  
7             use List::Util;
8 9     9   1173 use Scalar::Util;
  9         64  
  9         1967  
9 9     9   54  
  9         120  
  9         766  
10             use PLS::Parser::Document;
11 9     9   53 use PLS::Parser::Index;
  9         65  
  9         397  
12 9     9   61 use PLS::Parser::PackageSymbols;
  9         3441  
  9         403  
13 9     9   59 use PLS::Parser::Pod;
  9         9  
  9         363  
14 9     9   115 use PLS::Server::Request::TextDocument::PublishDiagnostics;
  9         106  
  9         318  
15 9     9   93 use PLS::Server::State;
  9         25  
  9         414  
16 9     9   92  
  9         66  
  9         6755  
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 23 return bless {
37             id => undef, # assigned by the server
38 5         153 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 28  
50             my $config = {};
51 4 50 33     89  
52             foreach my $result (@{$response->{result}})
53 4         17 {
54             next if (ref $result ne 'HASH');
55 4         17 next if (exists $result->{pls} and not length $result->{pls});
  4         41  
56              
57 4 50       37 foreach my $key (keys %{$result})
58 4 50 33     91 {
59             $config->{$key} = $result->{$key} unless (length $config->{$key});
60 4         12 }
  4         30  
61             } ## end foreach my $result (@{$response...})
62 28 50       104  
63             convert_config($config);
64              
65             my $index = PLS::Parser::Index->new();
66 4         59 my @inc;
67              
68 4         86 # Replace $ROOT_PATH with actual workspace paths in inc
69 4         13 if (exists $config->{inc} and ref $config->{inc} eq 'ARRAY')
70             {
71             foreach my $inc (@{$config->{inc}})
72 4 50 33     101 {
73             foreach my $folder (@{$index->workspace_folders})
74 4         23 {
  4         18  
75             my $interpolated = $inc =~ s/\$ROOT_PATH/$folder/gr;
76 0         0 push @inc, $interpolated;
  0         0  
77             }
78 0         0 } ## end foreach my $inc (@{$config->...})
79 0         0  
80             $config->{inc} = [List::Util::uniq sort @inc];
81             } ## end if (exists $config->{inc...})
82              
83 4         23 if (exists $config->{syntax}{perl} and length $config->{syntax}{perl})
84             {
85             PLS::Parser::Pod->set_perl_exe($config->{syntax}{perl});
86 4 50 33     50 }
87              
88 0         0 if (exists $config->{syntax}{args} and ref $config->{syntax}{args} eq 'ARRAY' and scalar @{$config->{syntax}{args}})
89             {
90             PLS::Parser::Pod->set_perl_args($config->{syntax}{args});
91 4 0 33     120 }
  0   50     0  
92              
93 0         0 $PLS::Server::State::CONFIG = $config;
94              
95             # @INC may have changed - republish diagnostics
96 4         72 foreach my $uri (@{PLS::Parser::Document->open_files()})
97             {
98             $server->send_server_request(PLS::Server::Request::TextDocument::PublishDiagnostics->new(uri => $uri));
99 4         23 }
  4         67  
100              
101 0         0 PLS::Parser::PackageSymbols::start_package_symbols_process($config);
102             PLS::Parser::PackageSymbols::start_imported_package_symbols_process($config);
103              
104 4         103 return;
105 4         145 } ## end sub handle_response
106              
107 4         223 {
108             my ($config) = @_;
109              
110             if (length $config->{pls})
111             {
112 4     4 0 15 $config->{cmd} = $config->{pls} unless (length $config->{cmd});
113             delete $config->{pls};
114 4 50       46 }
115              
116 4 50       67 if (ref $config->{plsargs} eq 'ARRAY')
117 4         15 {
118             $config->{args} = $config->{plsargs} if (ref $config->{args} ne 'ARRAY');
119             delete $config->{plsargs};
120 4 50       17 }
121              
122 0 0       0 $config->{perltidy} = {} if (ref $config->{perltidy} ne 'HASH');
123 0         0  
124             if (length $config->{perltidyrc})
125             {
126 4 50       44 $config->{perltidy}{perltidyrc} = $config->{perltidyrc} unless (length $config->{perltidy}{perltidyrc});
127             delete $config->{perltidyrc};
128 4 50       15 }
129              
130 4 50       18 return;
131 4         18 } ## end sub convert_config
132              
133             1;