PLS/Parser/DocumentSymbols.pm

filter: Statementstmt 25.0% 16 / 64 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 3 totaltotal 16.1% 21 / 130 CC 21 SCAR 48.9
CC
21
Cov
15%
_get_all_document_symbols
240.0
get_all_document_symbols
42.0
new
6.0
CRAP 133.5
« PLS/Server/Response/Resolve.pm ↑ Summary PLS/Parser/Pod/Subroutine.pm »
1 package PLS::Parser::DocumentSymbols;
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 Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use PLS::Parser::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 use constant {
11 1 PACKAGE => 4,
12 FUNCTION => 12,
13 VARIABLE => 13,
14 CONSTANT => 14
15 1 ▶ };
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 NAME
18  
19 PLS::Parser::DocumentSymbols
20  
21 =head1 DESCRIPTION
22  
23 This class parses a document to find all symbols.
24 It returns a hierachy of the symbols, so that a tree structure can be displayed.
25  
26 =cut
27  
28 sub new
29 {
30 0 ▶ my ($class, $uri) = @_;
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
31  
32 0 my $document = PLS::Parser::Document->new(uri => $uri);
33 0 ▶ return unless (ref $document eq 'PLS::Parser::Document');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $document eq "PLS::Parser::Document" 0 0 0
34 0 return bless {document => $document}, $class;
35 } ## end sub new
36  
37 sub get_all_document_symbols
38 {
39 0 ▶ my ($self) = @_;
Subroutine get_all_document_symbols: not called CC=6 SCAR=37.4
Pod undocumented
40  
41 0 my @roots;
42 0 $self->_get_all_document_symbols($self->document->{document}, \@roots);
43  
44 0 my @package_roots;
45  
46 0 my $packages = $self->document->get_packages();
47  
48 0 foreach my $index (0 .. $#{$packages})
49 {
50 0 my $line_start = $packages->[$index]->lsp_line_number;
51 0 ▶ my $line_end = $index == $#{$packages} ? undef : $packages->[$index + 1]->lsp_line_number;
Branch: 1 branch
BranchTrueFalseTotal
$index == $#{$packages;} ? : 0 0 0
52 0 my $range = $packages->[$index]->range();
53  
54 push @package_roots,
55 {
56 name => $packages->[$index]->name,
57 kind => PACKAGE,
58 range => $range,
59 selectionRange => $range,
60 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
61 };
62 } ## end foreach my $index (0 .. $#{...})
63  
64 0 ▶ unless (scalar @package_roots)
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @package_roots) 0 0 0
65 {
66 0 my $range = PLS::Parser::Element->new(element => $self->document->{document})->range();
67  
68 0 push @package_roots,
69 {
70 name => 'main',
71 kind => PACKAGE,
72 range => $range,
73 selectionRange => $range,
74 children => \@roots
75 };
76 } ## end unless (scalar @package_roots...)
77  
78 0 return \@package_roots;
79 } ## end sub get_all_document_symbols
80  
81 sub _get_all_document_symbols
82 {
83 0 ▶ my ($self, $scope, $roots, $current) = @_;
Subroutine _get_all_document_symbols: not called CC=15 SCAR=54.8
84  
85 0 ▶ my $array = ref $current eq 'HASH' ? $current->{children} : $roots;
Branch: 1 branch
BranchTrueFalseTotal
ref $current eq 'HASH' ? : 0 0 0
86 0 ▶ return unless blessed($scope);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($scope) 0 0 0
87  
88 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
89 {
90 0 foreach my $child ($scope->children)
91 {
92 0 $self->_get_all_document_symbols($child, $roots, $current);
93 }
94 } ## end if ($scope->isa('PPI::Document'...))
95 ▶ 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
96 {
97 # Don't show subroutine forward declarations
98 0 ▶ return unless blessed($scope->block);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($scope->block) 0 0 0
99 0 ▶ return unless $scope->block->isa('PPI::Structure::Block');
Branch: 1 branch
BranchTrueFalseTotal
unless $scope->block->isa("PPI::Structure::Block") 0 0 0
100 0 my $range = PLS::Parser::Element->new(element => $scope)->range();
101  
102 0 ▶ $current = {
Branch: 1 branch
BranchTrueFalseTotal
$scope->isa('PPI::Statement::Sub') ? : 0 0 0
103 name => $scope->isa('PPI::Statement::Sub') ? $scope->name : $scope->type,
104 kind => FUNCTION,
105 range => $range,
106 selectionRange => $range,
107 children => []
108 };
109  
110 0 push @{$array}, $current;
111  
112 0 $self->_get_all_document_symbols($scope->block, $roots, $current);
113 } ## end elsif ($scope->isa('PPI::Statement::Sub'...))
114 elsif ($scope->isa('PPI::Statement::Variable'))
115 {
116 0 push @{$array}, map {
117 0 my $range = $_->range();
118  
119 {
120 0 name => $_->name,
121 kind => VARIABLE,
122 range => $range,
123 selectionRange => $range
124 }
125 0 } map { @{$_->symbols} } @{$self->document->get_variable_statements($scope)};
126 } ## end elsif ($scope->isa('PPI::Statement::Variable'...))
127 ▶ 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
128 {
129 0 push @{$array}, map {
130 0 my $range = $_->range();
131  
132 {
133 0 name => $_->name,
134 kind => CONSTANT,
135 range => $range,
136 selectionRange => $range
137 }
138 0 } @{$self->document->get_constants($scope)};
139 } ## end elsif ($scope->isa('PPI::Statement::Include'...))
140 } ## end sub _get_all_document_symbols
141  
142 sub document
143 {
144 0 ▶ my ($self) = @_;
Subroutine document: not called CC=1 SCAR=6.9
Pod undocumented
145  
146 0 return $self->{document};
147 }
148  
149 1 1;
« PLS/Server/Response/Resolve.pm ↑ Summary PLS/Parser/Pod/Subroutine.pm »