PLS/Server/Response/Completion.pm

filter: Statementstmt 25.9% 34 / 131 Branchbran 0.0% 0 / 62 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 1 totaltotal 20.9% 45 / 215 CC 44 SCAR 73.7
CC
44
Cov
17%
new
1980.0
BEGIN
1.0
BEGIN
1.0
CRAP 1584.2
↑ Summary PLS/Parser/Document.pm »
1 package PLS::Server::Response::Completion;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use parent q(PLS::Server::Response);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Pod::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Module::CoreList;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Module::Metadata;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use ExtUtils::Installed;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use PLS::Parser::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use PLS::Parser::PackageSymbols;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use PLS::Parser::Pod;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 =head1 NAME
19  
20 PLS::Server::Response::Completion
21  
22 =head1 DESCRIPTION
23  
24 This is a message from the server to the client with a list
25 of completion items for the current location.
26  
27 =cut
28  
29 sub new
30 {
31 0 ▶ my ($class, $request) = @_;
Subroutine new: not called CC=44 SCAR=75.9
Pod undocumented
32  
33 0 my $self = bless {id => $request->{id}, result => undef}, $class;
34  
35 0 my $document = PLS::Parser::Document->new(uri => $request->{params}{textDocument}{uri}, line => $request->{params}{position}{line});
36 0 ▶ return $self unless (ref $document eq 'PLS::Parser::Document');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $document eq "PLS::Parser::Document" 0 0 0
37  
38 0 my @word_under_cursor_info = $document->find_word_under_cursor(@{$request->{params}{position}}{qw(line character)});
39 0 ▶ return $self unless (scalar @word_under_cursor_info);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @word_under_cursor_info 0 0 0
40 0 my ($range, $arrow, $package, $filter) = @word_under_cursor_info;
41 0 ▶ my $retrieve_packages = not $arrow or $filter =~ /^[\$\%\@]/ ? 0 : 1;
Branch: 2 branches
BranchTrueFalseTotal
my $retrieve_packages = !$arrow or $filter =~ /^[\$\%\@]/ ? '???' : '???' 0 0 0
$filter =~ /^[\$\%\@]/ ? : 0 0 0
42  
43 0 ▶ if (ref $range eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $range eq "HASH") 0 0 0
44 {
45 0 $range->{start}{line} = $request->{params}{position}{line};
46 0 $range->{end}{line} = $request->{params}{position}{line};
47 }
48  
49 0 ▶ return $self unless (ref $range eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $range eq "HASH" 0 0 0
50 0 ▶ $package =~ s/::$// if (length $package);
Branch: 1 branch
BranchTrueFalseTotal
if length $package 0 0 0
51  
52 0 my @results;
53 my %seen_subs;
54 0 my $functions = PLS::Parser::PackageSymbols::get_package_functions($package, $PLS::Server::State::CONFIG->{inc});
55  
56 0 ▶ if (ref $functions eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $functions eq "ARRAY") 0 0 0
57 {
58 0 ▶ my $separator = $arrow ? '->' : '::';
Branch: 1 branch
BranchTrueFalseTotal
$arrow ? : 0 0 0
59  
60 0 foreach my $name (@{$functions})
61 {
62 0 ▶ next if $seen_subs{$name}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_subs{$name}++ 0 0 0
63  
64 0 my $fully_qualified = join $separator, $package, $name;
65 0 my $result = {
66 label => $name,
67 sortText => $fully_qualified,
68 filterText => $fully_qualified,
69 kind => 3
70 };
71  
72 0 ▶ if ($arrow)
Branch: 1 branch
BranchTrueFalseTotal
if ($arrow) { } 0 0 0
73 {
74 0 $result->{insertText} = "->$name";
75 }
76 else
77 {
78 0 $result->{insertText} = $fully_qualified;
79 }
80  
81 0 push @results, $result;
82 } ## end foreach my $name (@{$functions...})
83 } ## end if (ref $functions eq ...)
84  
85 0 my $subs = $document->{index}{subs_trie}->find($filter);
86 0 my $packages = [];
87 0 ▶ $packages = $document->{index}{packages_trie}->find($filter) if $retrieve_packages;
Branch: 1 branch
BranchTrueFalseTotal
if $retrieve_packages 0 0 0
88 0 state @keywords;
89  
90 0 my $full_text;
91 my %seen_packages;
92  
93 0 ▶ unless ($filter =~ /^[\$\%\@]/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($filter =~ /^[\$\%\@]/) 0 0 0
94 {
95 0 ▶ if (scalar @keywords)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @keywords) { } 0 0 0
96 {
97 0 push @results, @keywords;
98 }
99 else
100 {
101 0 my %seen_keywords;
102  
103 0 foreach my $family (keys %Pod::Functions::Kinds)
104 {
105 0 foreach my $sub (@{$Pod::Functions::Kinds{$family}})
106 {
107 0 ▶ next if $sub =~ /\s+/;
Branch: 1 branch
BranchTrueFalseTotal
if $sub =~ /\s+/ 0 0 0
108 0 ▶ next if $seen_keywords{$sub}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_keywords{$sub}++ 0 0 0
109 0 push @keywords, {label => $sub, kind => 14};
110 } ## end foreach my $sub (@{$Pod::Functions::Kinds...})
111 } ## end foreach my $family (keys %Pod::Functions::Kinds...)
112  
113 0 foreach my $keyword (
114 qw(cmp continue default do else elsif eq for foreach ge given gt if le lock lt ne not or package sub unless until when while x xor))
115 {
116 0 ▶ next if $seen_keywords{$keyword}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_keywords{$keyword}++ 0 0 0
117 0 push @keywords, {label => $keyword, kind => 14};
118 }
119  
120 0 push @results, @keywords;
121 } ## end else [ if (scalar @builtins) ]
122  
123 0 $full_text = $document->get_full_text();
124  
125 0 foreach my $sub (@{$document->get_subroutines_fast($full_text)})
126 {
127 0 ▶ next if $seen_subs{$sub}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_subs{$sub}++ 0 0 0
128 0 push @results, {label => $sub, kind => 3};
129 }
130  
131 0 my %seen_constants;
132  
133 0 foreach my $constant (@{$document->get_constants_fast($full_text)})
134 {
135 0 ▶ next if $seen_constants{$constant}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_constants{$constant}++ 0 0 0
136 0 push @results, {label => $constant, kind => 21};
137 }
138  
139 0 ▶ if ($retrieve_packages)
Branch: 1 branch
BranchTrueFalseTotal
if ($retrieve_packages) 0 0 0
140 {
141 0 foreach my $pack (@{$document->get_packages_fast($full_text)})
142 {
143 0 ▶ next if $seen_packages{$pack}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_packages{$pack}++ 0 0 0
144 0 push @results, {label => $pack, kind => 9};
145 }
146 } ## end if ($retrieve_packages...)
147 } ## end unless ($filter =~ /^[\$\%\@]/...)
148  
149 # Can use state here, core and external modules unlikely to change.
150 0 state $core_modules = [Module::CoreList->find_modules(qr//, $])];
151 0 state $include = PLS::Parser::Pod->get_clean_inc();
152 0 state $ext_modules = [ExtUtils::Installed->new(inc_override => $include)->modules];
153  
154 0 ▶ if ($retrieve_packages)
Branch: 1 branch
BranchTrueFalseTotal
if ($retrieve_packages) 0 0 0
155 {
156 0 foreach my $module (@{$core_modules}, @{$ext_modules})
157 {
158 0 ▶ next if $seen_packages{$module}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_packages{$module}++ 0 0 0
159 0 push @results,
160 {
161 label => $module,
162 kind => 7
163 };
164 } ## end foreach my $module (@{$core_modules...})
165 } ## end if ($retrieve_packages...)
166  
167 0 my %seen_variables;
168  
169 # Add variables to the list if the current word is obviously a variable.
170 0 ▶ if (not $arrow and not length $package and $filter =~ /^[\$\@\%]/)
Branch: 1 branch
BranchTrueFalseTotal
if (not $arrow || length $package and $filter =~ /^[\$\@\%]/) 0 0 0
Condition0%0/6
not $arrow || length $package and $filter =~ /^[\$\@\%]/
!ll&&!rl&&r
000
$arrow || length $package
l!l&&r!l&&!r
000
MC/DC0%0/3
not $arrow || length $package and $filter =~ /^[\$\@\%]/
$arrow length $package $filter =~ /^[\$\@\%]/
Truth table0%0/4
not(A || B) and C
A= $arrowB= length $packageC= $filter =~ /^[\$\@\%]/
ABCresult
1XX0
01X0
0000
0011
171 {
172 0 ▶ $full_text = $document->get_full_text() unless (ref $full_text eq 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $full_text eq "SCALAR" 0 0 0
173  
174 0 foreach my $variable (@{$document->get_variables_fast($full_text)})
175 {
176 0 ▶ next if $seen_variables{$variable}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_variables{$variable}++ 0 0 0
177 0 push @results,
178 {
179 label => $variable,
180 kind => 6
181 };
182  
183 # add other variable forms to the list for arrays and hashes
184 0 ▶ if ($variable =~ /^[\@\%]/)
Branch: 1 branch
BranchTrueFalseTotal
if ($variable =~ /^[\@\%]/) 0 0 0
185 {
186 0 my $name = $variable =~ s/^[\@\%]/\$/r;
187 0 ▶ my $append = $variable =~ /^\@/ ? '[' : '{';
Branch: 1 branch
BranchTrueFalseTotal
$variable =~ /^\@/ ? : 0 0 0
188 0 push @results,
189 {
190 label => $variable,
191 insertText => $name . $append,
192 filterText => $name,
193 kind => 6
194 };
195 } ## end if ($variable =~ /^[\@\%]/...)
196 } ## end foreach my $variable (@{$document...})
197 } ## end if (not $arrow and not...)
198  
199 0 ▶ $subs = [] unless (ref $subs eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $subs eq "ARRAY" 0 0 0
200 0 ▶ $packages = [] unless (ref $packages eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $packages eq "ARRAY" 0 0 0
201  
202 0 @$subs = map { {label => $_, kind => 3} } grep { not $seen_subs{$_}++ } @$subs;
203 0 @$packages = map { {label => $_, kind => 7} } grep { not $seen_packages{$_}++ } @$packages;
204  
205 0 @results = (@results, @$subs, @$packages);
206  
207 0 foreach my $result (@results)
208 {
209 0 my $new_text = $result->{label};
210 0 ▶ $new_text = $result->{insertText} if (length $result->{insertText});
Branch: 1 branch
BranchTrueFalseTotal
if length $result->{"insertText"} 0 0 0
211 0 delete $result->{insertText};
212  
213 0 push @{$self->{result}},
214 {
215 %$result,
216 textEdit => {newText => $new_text, range => $range},
217 data => $request->{params}{textDocument}{uri}
218 0 };
219 } ## end foreach my $result (@results...)
220  
221 0 return $self;
222 } ## end sub new
223  
224 1 1;
↑ Summary PLS/Parser/Document.pm »