PLS/Parser/DocumentSymbols.pm

filter: Statementstmt 32.8% 25 / 76 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 72.7% 8 / 11 Podpod 0.0% 0 / 2 totaltotal 22.7% 33 / 145 CC 22 SCAR 48.3
CC
22
Cov
20%
_get_all_document_symbols
240.0
get_all_document_symbols
56.0
get_all_document_symbols_async
6.0
CRAP 125.4
« PLS/Server/Response/Resolve.pm ↑ Summary PLS/Server/Response/Completion.pm »
1 package PLS::Parser::DocumentSymbols;
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 9 ▶use IO::Async::Function;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use IO::Async::Loop;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 9 ▶use PLS::Parser::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 use constant {
15 9 PACKAGE => 4,
16 FUNCTION => 12,
17 VARIABLE => 13,
18 CONSTANT => 14
19 9 ▶ };
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 =head1 NAME
22  
23 PLS::Parser::DocumentSymbols
24  
25 =head1 DESCRIPTION
26  
27 This class parses a document to find all symbols.
28 It returns a hierachy of the symbols, so that a tree structure can be displayed.
29  
30 =cut
31  
32 sub get_all_document_symbols_async
33 {
34 0 ▶ my ($class, $uri) = @_;
Subroutine get_all_document_symbols_async: not called CC=2 SCAR=17.9
Pod undocumented
35  
36 0 state $function;
37  
38 0 ▶ if (ref $function ne 'IO::Async::Function')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $function ne "IO::Async::Function") 0 0 0
39 {
40 0 $function = IO::Async::Function->new(code => \&get_all_document_symbols);
41 0 IO::Async::Loop->new->add($function);
42 }
43  
44 0 my $text = PLS::Parser::Document->text_from_uri($uri);
45 0 return $function->call(args => [$class, $uri, $text]);
46 } ## end sub get_all_document_symbols_async
47  
48 sub get_all_document_symbols
49 {
50 0 ▶ my ($class, $uri, $text) = @_;
Subroutine get_all_document_symbols: not called CC=7 SCAR=40.3
Pod undocumented
51  
52 0 my $document = PLS::Parser::Document->new(uri => $uri, text => $text);
53 0 ▶ return [] if (ref $document ne 'PLS::Parser::Document');
Branch: 1 branch
BranchTrueFalseTotal
if ref $document ne "PLS::Parser::Document" 0 0 0
54  
55 0 my @roots;
56 0 $class->_get_all_document_symbols($document, $document->{document}, \@roots);
57  
58 0 my @package_roots;
59  
60 0 my $packages = $document->get_packages();
61  
62 0 foreach my $index (0 .. $#{$packages})
63 {
64 0 my $line_start = $packages->[$index]->lsp_line_number;
65 0 ▶ my $line_end = $index == $#{$packages} ? undef : $packages->[$index + 1]->lsp_line_number;
Branch: 1 branch
BranchTrueFalseTotal
$index == $#{$packages;} ? : 0 0 0
66 0 my $range = $packages->[$index]->range();
67  
68 push @package_roots,
69 {
70 name => $packages->[$index]->name,
71 kind => PACKAGE,
72 range => $range,
73 selectionRange => $range,
74 0 ▶ children => [grep { $_->{range}{start}{line} > $line_start and (not defined $line_end or $_->{range}{end}{line} < $line_end) } @roots]
Branch: 1 branch
BranchTrueFalseTotal
$_->{"range"}{"start"}{"line"} > $line_start and !defined($line_end) || $_->{"range"}{"end"}{"line"} < $line_end 0 0 0
Condition0%0/6
$_->{'range'}{'start'}{'line'} > $line_start && (!defined($line_end) || $_->{'range'}{'end'}{'line'} < $line_end)
!ll&&!rl&&r
000
not defined $line_end or $_->{"range"}{"end"}{"line"} < $line_end
l!l&&r!l&&!r
000
MC/DC0%0/3
$_->{'range'}{'start'}{'line'} > $line_start && (!defined($line_end) || $_->{'range'}{'end'}{'line'} < $line_end)
$_->{'range'}{'start'}{'line'} > $line_start not defined $line_end $_->{"range"}{"end"}{"line"} < $line_end
Truth table0%0/4
A && not(B) or C
A= $_->{'range'}{'start'}{'line'} > $line_startB= not defined $line_endC= $_->{"range"}{"end"}{"line"} < $line_end
ABCresult
0XX0
1000
11X1
1011
75 };
76 } ## end foreach my $index (0 .. $#{...})
77  
78 0 ▶ unless (scalar @package_roots)
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @package_roots) 0 0 0
79 {
80 0 my $range = PLS::Parser::Element->new(element => $document->{document})->range();
81  
82 0 push @package_roots,
83 {
84 name => 'main',
85 kind => PACKAGE,
86 range => $range,
87 selectionRange => $range,
88 children => \@roots
89 };
90 } ## end unless (scalar @package_roots...)
91  
92 0 return \@package_roots;
93 } ## end sub get_all_document_symbols
94  
95 sub _get_all_document_symbols
96 {
97 0 ▶ my ($class, $document, $scope, $roots, $current) = @_;
Subroutine _get_all_document_symbols: not called CC=15 SCAR=54.8
98  
99 0 ▶ my $array = ref $current eq 'HASH' ? $current->{children} : $roots;
Branch: 1 branch
BranchTrueFalseTotal
ref $current eq 'HASH' ? : 0 0 0
100 0 ▶ return unless blessed($scope);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($scope) 0 0 0
101  
102 0 ▶ if ($scope->isa('PPI::Document') or $scope->isa('PPI::Structure::Block'))
Branch: 4 branches
BranchTrueFalseTotal
if ($scope->isa('PPI::Document') or $scope->isa('PPI::Structure::Block')) { } 0 0 0
elsif ($scope->isa('PPI::Statement::Sub') or $scope->isa('PPI::Statement::Scheduled')) { } 0 0 0
elsif ($scope->isa('PPI::Statement::Variable')) { } 0 0 0
elsif ($scope->isa('PPI::Statement::Include') and $scope->type eq 'use' and $scope->pragma eq 'constant') { } 0 0 0
Condition0%0/3
$scope->isa("PPI::Document") or $scope->isa("PPI::Structure::Block")
l!l&&r!l&&!r
000
MC/DC0%0/2
$scope->isa("PPI::Document") or $scope->isa("PPI::Structure::Block")
$scope->isa("PPI::Document") $scope->isa("PPI::Structure::Block")
Truth table0%0/3
A or B
A= $scope->isa("PPI::Document")B= $scope->isa("PPI::Structure::Block")
ABresult
1X1
011
000
103 {
104 0 foreach my $child ($scope->children)
105 {
106 0 $class->_get_all_document_symbols($document, $child, $roots, $current);
107 }
108 } ## end if ($scope->isa('PPI::Document'...))
109 ▶ elsif ($scope->isa('PPI::Statement::Sub') or $scope->isa('PPI::Statement::Scheduled'))
Condition0%0/3
$scope->isa("PPI::Statement::Sub") or $scope->isa("PPI::Statement::Scheduled")
l!l&&r!l&&!r
000
MC/DC0%0/2
$scope->isa("PPI::Statement::Sub") or $scope->isa("PPI::Statement::Scheduled")
$scope->isa("PPI::Statement::Sub") $scope->isa("PPI::Statement::Scheduled")
Truth table0%0/3
A or B
A= $scope->isa("PPI::Statement::Sub")B= $scope->isa("PPI::Statement::Scheduled")
ABresult
1X1
011
000
110 {
111 # Don't show subroutine forward declarations
112 0 ▶ return unless blessed($scope->block);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($scope->block) 0 0 0
113 0 ▶ return unless $scope->block->isa('PPI::Structure::Block');
Branch: 1 branch
BranchTrueFalseTotal
unless $scope->block->isa("PPI::Structure::Block") 0 0 0
114 0 my $range = PLS::Parser::Element->new(element => $scope)->range();
115  
116 0 ▶ $current = {
Branch: 1 branch
BranchTrueFalseTotal
$scope->isa('PPI::Statement::Sub') ? : 0 0 0
117 name => $scope->isa('PPI::Statement::Sub') ? $scope->name : $scope->type,
118 kind => FUNCTION,
119 range => $range,
120 selectionRange => $range,
121 children => []
122 };
123  
124 0 push @{$array}, $current;
125  
126 0 $class->_get_all_document_symbols($document, $scope->block, $roots, $current);
127 } ## end elsif ($scope->isa('PPI::Statement::Sub'...))
128 elsif ($scope->isa('PPI::Statement::Variable'))
129 {
130 0 push @{$array}, map {
131 0 my $range = $_->range();
132  
133 {
134 0 name => $_->name,
135 kind => VARIABLE,
136 range => $range,
137 selectionRange => $range
138 }
139 0 } map { @{$_->symbols} } @{$document->get_variable_statements($scope)};
140 } ## end elsif ($scope->isa('PPI::Statement::Variable'...))
141 ▶ elsif ($scope->isa('PPI::Statement::Include') and $scope->type eq 'use' and $scope->pragma eq 'constant')
Condition0%0/6
$scope->isa("PPI::Statement::Include") and $scope->type eq "use" and $scope->pragma eq "constant"
!ll&&!rl&&r
000
$scope->isa("PPI::Statement::Include") and $scope->type eq "use"
!ll&&!rl&&r
000
MC/DC0%0/3
$scope->isa("PPI::Statement::Include") and $scope->type eq "use" and $scope->pragma eq "constant"
$scope->isa("PPI::Statement::Include") $scope->type eq "use" $scope->pragma eq "constant"
Truth table0%0/4
A and B and C
A= $scope->isa("PPI::Statement::Include")B= $scope->type eq "use"C= $scope->pragma eq "constant"
ABCresult
0XX0
10X0
1100
1111
142 {
143 0 push @{$array}, map {
144 0 my $range = $_->range();
145  
146 {
147 0 name => $_->name,
148 kind => CONSTANT,
149 range => $range,
150 selectionRange => $range
151 }
152 0 } @{$document->get_constants($scope)};
153 } ## end elsif ($scope->isa('PPI::Statement::Include'...))
154 } ## end sub _get_all_document_symbols
155  
156 9 1;
« PLS/Server/Response/Resolve.pm ↑ Summary PLS/Server/Response/Completion.pm »