File Coverage

blib/lib/PLS/Server/Request/Workspace/Configuration.pm
Criterion Covered Total %
statement 74 82 90.2
branch 12 28 42.8
condition 6 17 35.2
subroutine 15 15 100.0
pod 0 3 0.0
total 107 145 73.7


line stmt bran cond sub pod time code
1             package PLS::Server::Request::Workspace::Configuration;
2              
3 11     11   200 use strict;
  11         268  
  11         983  
4 11     11   265 use warnings;
  11         142  
  11         1183  
5              
6 11     11   237 use parent 'PLS::Server::Request';
  11         123  
  11         780  
7              
8 11     11   3371 use List::Util;
  11         66  
  11         4745  
9 11     11   350 use Scalar::Util;
  11         276  
  11         1419  
10              
11 11     11   259 use PLS::Parser::Document;
  11         222  
  11         807  
12 11     11   94 use PLS::Parser::Index;
  11         57  
  11         832  
13 11     11   205 use PLS::Parser::PackageSymbols;
  11         180  
  11         1018  
14 11     11   345 use PLS::Parser::Pod;
  11         197  
  11         694  
15 11     11   8819 use PLS::Server::Cache;
  11         209  
  11         891  
16 11     11   111 use PLS::Server::Request::TextDocument::PublishDiagnostics;
  11         186  
  11         1007  
17 11     11   85 use PLS::Server::State;
  11         35  
  11         12396  
18              
19             =head1 NAME
20              
21             PLS::Server::Request::Workspace::Configuration
22              
23             =head1 DESCRIPTION
24              
25             This is a message from the server to the client requesting that it send
26             the values of some configuration items.
27              
28             PLS requests all configuration starting with C<pls.>.
29              
30             This class also handles the response from the client which stores the configuration
31             in memory.
32              
33             =cut
34              
35             sub new
36             {
37 5     5 0 54 my ($class) = @_;
38              
39 5         375 return bless {
40             id => undef, # assigned by the server
41             method => 'workspace/configuration',
42             params => {
43             items => [{section => 'perl'}, {section => 'pls'}]
44             }
45             }, $class;
46             } ## end sub new
47              
48             sub handle_response
49             {
50 4     4 0 133 my ($self, $response, $server) = @_;
51              
52 4 50 33     215 return if (Scalar::Util::reftype($response) ne 'HASH' or ref $response->{result} ne 'ARRAY');
53              
54 4         49 my $config = {};
55              
56 4         10 foreach my $result (@{$response->{result}})
  4         2308  
57             {
58 4 50       56 next if (ref $result ne 'HASH');
59 4 50 33     90 next if (exists $result->{pls} and not length $result->{pls});
60              
61 4         98 foreach my $key (keys %{$result})
  4         52  
62             {
63 28 50       102 $config->{$key} = $result->{$key} unless (length $config->{$key});
64             }
65             } ## end foreach my $result (@{$response...})
66              
67 4         90 convert_config($config);
68              
69 4         195 my $index = PLS::Parser::Index->new();
70 4         68 my @inc;
71              
72 4 50 33     115 if (exists $config->{inc} and ref $config->{inc} eq 'ARRAY')
73             {
74 4         18 foreach my $inc (@{$config->{inc}})
  4         55  
75             {
76 0         0 push @inc, PLS::Util::resolve_workspace_relative_path($inc, $index->workspace_folders, 1);
77             }
78              
79 4         53 $config->{inc} = [List::Util::uniq @inc];
80             } ## end if (exists $config->{inc...})
81              
82 4 50 33     120 if (exists $config->{syntax}{perl} and length $config->{syntax}{perl})
83             {
84 0         0 my ($perl) = glob $config->{syntax}{perl};
85 0         0 PLS::Parser::Pod->set_perl_exe($perl);
86             }
87              
88 4 0 33     125 if (exists $config->{syntax}{args} and ref $config->{syntax}{args} eq 'ARRAY' and scalar @{$config->{syntax}{args}})
  0   50     0  
89             {
90 0         0 PLS::Parser::Pod->set_perl_args($config->{syntax}{args});
91             }
92              
93 4         194 $PLS::Server::State::CONFIG = $config;
94              
95             # @INC may have changed - republish diagnostics
96 4         62 foreach my $uri (@{PLS::Parser::Document->open_files()})
  4         135  
97             {
98 0         0 $server->send_server_request(PLS::Server::Request::TextDocument::PublishDiagnostics->new(uri => $uri));
99             }
100              
101 4         230 PLS::Parser::PackageSymbols::start_package_symbols_process($config);
102 4         336 PLS::Parser::PackageSymbols::start_imported_package_symbols_process($config);
103              
104 4         257 PLS::Server::Cache::warm_up();
105              
106 4         34 return;
107             } ## end sub handle_response
108              
109             sub convert_config
110             {
111 4     4 0 51 my ($config) = @_;
112              
113 4 50       59 if (length $config->{pls})
114             {
115 4 50       116 $config->{cmd} = $config->{pls} unless (length $config->{cmd});
116 4         67 delete $config->{pls};
117             }
118              
119 4 50       51 if (ref $config->{plsargs} eq 'ARRAY')
120             {
121 0 0       0 $config->{args} = $config->{plsargs} if (ref $config->{args} ne 'ARRAY');
122 0         0 delete $config->{plsargs};
123             }
124              
125 4 50       118 $config->{perltidy} = {} if (ref $config->{perltidy} ne 'HASH');
126              
127 4 50       17 if (length $config->{perltidyrc})
128             {
129 4 50       79 $config->{perltidy}{perltidyrc} = $config->{perltidyrc} unless (length $config->{perltidy}{perltidyrc});
130 4         40 delete $config->{perltidyrc};
131             }
132              
133 4         11 return;
134             } ## end sub convert_config
135              
136             1;