| 1 | package PLS::Parser::DocumentSymbols; | ||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use feature 'state'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use IO::Async::Function; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use IO::Async::Loop; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 10 | 13 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 13 | 13 | PACKAGE => 4, | |||||||||||||||||||||||||||||||||||||||
| 14 | FUNCTION => 12, | ||||||||||||||||||||||||||||||||||||||||
| 15 | VARIABLE => 13, | ||||||||||||||||||||||||||||||||||||||||
| 16 | CONSTANT => 14 | ||||||||||||||||||||||||||||||||||||||||
| 17 | 13 | }; | |||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||
| 21 | PLS::Parser::DocumentSymbols | ||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||
| 25 | This class parses a document to find all symbols. | ||||||||||||||||||||||||||||||||||||||||
| 26 | It returns a hierachy of the symbols, so that a tree structure can be displayed. | ||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||
| 30 | sub get_all_document_symbols_async | ||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_all_document_symbols_async: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my ($class, $uri) = @_; | |||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | state $function; | |||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if (ref $function ne 'IO::Async::Function') | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $function = IO::Async::Function->new(code => \&get_all_document_symbols); | |||||||||||||||||||||||||||||||||||||||
| 39 | 0 | IO::Async::Loop->new->add($function); | |||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | require PLS::Parser::Document; | |||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $text = PLS::Parser::Document->text_from_uri($uri); | |||||||||||||||||||||||||||||||||||||||
| 44 | 0 | return $function->call(args => [$class, $uri, $text]); | |||||||||||||||||||||||||||||||||||||||
| 45 | } ## end sub get_all_document_symbols_async | ||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||
| 47 | sub get_all_document_symbols | ||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_all_document_symbols: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my ($class, $uri, $text) = @_; | |||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | require PLS::Parser::Document; | |||||||||||||||||||||||||||||||||||||||
| 52 | 0 | require PLS::Parser::Element; | |||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $document = PLS::Parser::Document->new(uri => $uri, text => $text); | |||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return [] if (ref $document ne 'PLS::Parser::Document'); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my @roots; | |||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $class->_get_all_document_symbols($document, $document->{document}, \@roots); | |||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my @package_roots; | |||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $packages = $document->get_packages(); | |||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | foreach my $index (0 .. $#{$packages}) | |||||||||||||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my $line_start = $packages->[$index]->lsp_line_number; | |||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my $line_end = $index == $#{$packages} ? undef : $packages->[$index + 1]->lsp_line_number; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my $range = $packages->[$index]->range(); | |||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||
| 70 | push @package_roots, | ||||||||||||||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||||||||||||||
| 72 | name => $packages->[$index]->name, | ||||||||||||||||||||||||||||||||||||||||
| 73 | kind => PACKAGE, | ||||||||||||||||||||||||||||||||||||||||
| 74 | range => $range, | ||||||||||||||||||||||||||||||||||||||||
| 75 | selectionRange => $range, | ||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | children => [grep { $_->{range}{start}{line} > $line_start and (not defined $line_end or $_->{range}{end}{line} < $line_end) } @roots] | ||||||||||||||||||||||||||||||||||||||
|
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
| |||||||||||||||||||||||||||||||||||||||||
| 77 | }; | ||||||||||||||||||||||||||||||||||||||||
| 78 | } ## end foreach my $index (0 .. $#{...}) | ||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if (not scalar @package_roots) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $range = PLS::Parser::Element->new(element => $document->{document})->range(); | |||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | push @package_roots, | |||||||||||||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||||||||||||||
| 86 | name => 'main', | ||||||||||||||||||||||||||||||||||||||||
| 87 | kind => PACKAGE, | ||||||||||||||||||||||||||||||||||||||||
| 88 | range => $range, | ||||||||||||||||||||||||||||||||||||||||
| 89 | selectionRange => $range, | ||||||||||||||||||||||||||||||||||||||||
| 90 | children => \@roots | ||||||||||||||||||||||||||||||||||||||||
| 91 | }; | ||||||||||||||||||||||||||||||||||||||||
| 92 | } ## end if (not scalar @package_roots...) | ||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | return \@package_roots; | |||||||||||||||||||||||||||||||||||||||
| 95 | } ## end sub get_all_document_symbols | ||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||
| 97 | sub _get_all_document_symbols | ||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_all_document_symbols: not called CC=18 SCAR=58.3
| |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my ($class, $document, $scope, $roots, $current) = @_; | |||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | require PLS::Parser::Element; | |||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | my $array = ref $current eq 'HASH' ? $current->{children} : $roots; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | return unless blessed($scope); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||
| 106 | 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")
| |||||||||||||||||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | foreach my $child ($scope->children) | |||||||||||||||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $class->_get_all_document_symbols($document, $child, $roots, $current); | |||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||
| 112 | } ## end if ($scope->isa('PPI::Document'...)) | ||||||||||||||||||||||||||||||||||||||||
| 113 | ▶ | 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")
| |||||||||||||||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||||||||||||||
| 115 | # Don't show subroutine forward declarations | ||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | return unless blessed($scope->block); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | return unless $scope->block->isa('PPI::Structure::Block'); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $range = PLS::Parser::Element->new(element => $scope)->range(); | |||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | $current = { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 121 | name => $scope->isa('PPI::Statement::Sub') ? $scope->name : $scope->type, | ||||||||||||||||||||||||||||||||||||||||
| 122 | kind => FUNCTION, | ||||||||||||||||||||||||||||||||||||||||
| 123 | range => $range, | ||||||||||||||||||||||||||||||||||||||||
| 124 | selectionRange => $range, | ||||||||||||||||||||||||||||||||||||||||
| 125 | children => [] | ||||||||||||||||||||||||||||||||||||||||
| 126 | }; | ||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | push @{$array}, $current; | |||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $class->_get_all_document_symbols($document, $scope->block, $roots, $current); | |||||||||||||||||||||||||||||||||||||||
| 131 | } ## end elsif ($scope->isa('PPI::Statement::Sub'...)) | ||||||||||||||||||||||||||||||||||||||||
| 132 | elsif ($scope->isa('PPI::Statement::Variable')) | ||||||||||||||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | foreach my $statement (@{$document->get_variable_statements($scope)}) | |||||||||||||||||||||||||||||||||||||||
| 135 | { | ||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | foreach my $symbol (@{$statement->symbols}) | |||||||||||||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $range = $symbol->range(); | |||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | push @{$array}, | |||||||||||||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||||||||||||||
| 142 | name => $symbol->name, | ||||||||||||||||||||||||||||||||||||||||
| 143 | kind => VARIABLE, | ||||||||||||||||||||||||||||||||||||||||
| 144 | range => $range, | ||||||||||||||||||||||||||||||||||||||||
| 145 | selectionRange => $range | ||||||||||||||||||||||||||||||||||||||||
| 146 | }; | ||||||||||||||||||||||||||||||||||||||||
| 147 | } ## end foreach my $symbol (@{$statement...}) | ||||||||||||||||||||||||||||||||||||||||
| 148 | } ## end foreach my $statement (@{$document...}) | ||||||||||||||||||||||||||||||||||||||||
| 149 | } ## end elsif ($scope->isa('PPI::Statement::Variable'...)) | ||||||||||||||||||||||||||||||||||||||||
| 150 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||
| 151 | { | ||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | foreach my $constant (@{$document->get_constants($scope)}) | |||||||||||||||||||||||||||||||||||||||
| 153 | { | ||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my $range = $constant->range(); | |||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | push @{$array}, | |||||||||||||||||||||||||||||||||||||||
| 157 | { | ||||||||||||||||||||||||||||||||||||||||
| 158 | name => $constant->name, | ||||||||||||||||||||||||||||||||||||||||
| 159 | kind => CONSTANT, | ||||||||||||||||||||||||||||||||||||||||
| 160 | range => $range, | ||||||||||||||||||||||||||||||||||||||||
| 161 | selectionRange => $range | ||||||||||||||||||||||||||||||||||||||||
| 162 | }; | ||||||||||||||||||||||||||||||||||||||||
| 163 | } ## end foreach my $constant (@{$document...}) | ||||||||||||||||||||||||||||||||||||||||
| 164 | } ## end elsif ($scope->isa('PPI::Statement::Include'...)) | ||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | return; | |||||||||||||||||||||||||||||||||||||||
| 167 | } ## end sub _get_all_document_symbols | ||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||
| 169 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||