| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
$_->{'range'}{'start'}{'line'} > $line_start && (!defined($line_end) || $_->{'range'}{'end'}{'line'} < $line_end)
not defined $line_end or $_->{"range"}{"end"}{"line"} < $line_end
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
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 76 | } ## end foreach my $index (0 .. $#{...}) | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | unless (scalar @package_roots) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | return unless blessed($scope); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ($scope->isa('PPI::Document') or $scope->isa('PPI::Structure::Block')) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/3
$scope->isa("PPI::Document") or $scope->isa("PPI::Structure::Block")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | # Don't show subroutine forward declarations | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | return unless blessed($scope->block); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | return unless $scope->block->isa('PPI::Structure::Block'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $range = PLS::Parser::Element->new(element => $scope)->range(); | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | $current = { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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"
$scope->isa("PPI::Statement::Include") and $scope->type eq "use"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||||||