blib/lib/PLS/Util.pm

filter: Statementstmt 81.4% 22 / 27 Branchbran 40.0% 4 / 10 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 57.1% 32 / 56 CC 10 SCAR 28.1
CC
10
Cov
61%
resolve_workspace_relative_path
19.8
BEGIN
1.0
BEGIN
1.0
CRAP 16.7
« blib/lib/PLS/Server/Request/TextDocument/PublishDiagnostics.pm ↑ Summary blib/lib/PLS/Server/Method/TextDocument.pm »
1 package PLS::Util;
2  
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 PLS::Util
9  
10 =head1 DESCRIPTION
11  
12 Utility functions for PLS
13  
14 =head1 FUNCTIONS
15  
16 =head2 resolve_workspace_relative_path
17  
18 Given a path, potentially with ${workspaceFolder} or $ROOT_PATH,
19 returns a list of paths with those variables resolved to an actual workspace folder.
20 Additionally, any needed globbing will be performed.
21  
22 The returned list will only contain paths that exist.
23  
24 =head3 PARAMETERS
25  
26 =over
27  
28 =item path
29  
30 The path from user configuration that needs to be resolved.
31  
32 =item workspace_folders
33  
34 An array of the workspace folders. If empty or not passed, this list will
35 be queried from L<PLS::Parser::Index>.
36  
37 =item no_glob
38  
39 If true, no globbing will be performed against the path.
40  
41 =back
42  
43 =cut
44  
45 sub resolve_workspace_relative_path
46 4 ▶{
Subroutine resolve_workspace_relative_path: called CC=10 SCAR=29.9
Pod documented
47 4 my ($path, $workspace_folders, $no_glob) = @_;
48  
49 4 ▶ if (not length $path)
Branch: 1 branch
BranchTrueFalseTotal
unless (length $path) 0 4 4
50 {
51 0 return;
52 }
53  
54 0 ▶ if (ref $workspace_folders ne 'ARRAY' or not scalar @{$workspace_folders})
Branch: 1 branch
BranchTrueFalseTotal
if (ref $workspace_folders ne "ARRAY" or not scalar @{$workspace_folders;}) 4 0 4
Condition33%1/3
ref $workspace_folders ne "ARRAY" or not scalar @{$workspace_folders;}
l!l&&r!l&&!r
400
MC/DC0%0/2
ref $workspace_folders ne "ARRAY" or not scalar @{$workspace_folders;}
ref $workspace_folders ne "ARRAY" not scalar @{$workspace_folders;}
Truth table33%1/3
A or not(B)
A= ref $workspace_folders ne "ARRAY"B= not scalar @{$workspace_folders;}
ABresult
1X1
011
000
55 {
56 4 require PLS::Parser::Index;
57 4 $workspace_folders = PLS::Parser::Index->new->workspace_folders;
58 }
59  
60 4 my @resolved;
61  
62 4 foreach my $workspace_folder (@{$workspace_folders})
63 {
64 4 my $resolved = $path =~ s/\$ROOT_PATH/$workspace_folder/r;
65 4 $resolved =~ s/\$\{workspaceFolder\}/$workspace_folder/;
66  
67 4 ▶ if (not length $resolved)
Branch: 1 branch
BranchTrueFalseTotal
unless (length $resolved) 0 4 4
68 {
69 0 next;
70 }
71  
72 4 ▶ if ($no_glob)
Branch: 1 branch
BranchTrueFalseTotal
if ($no_glob) { } 0 4 4
73 {
74 0 ▶ if (length $resolved and -e $resolved)
Branch: 1 branch
BranchTrueFalseTotal
if (length $resolved and -e $resolved) 0 0 0
Condition0%0/3
length $resolved and -e $resolved
!ll&&!rl&&r
000
MC/DC0%0/2
length $resolved and -e $resolved
length $resolved -e $resolved
Truth table0%0/3
A and B
A= length $resolvedB= -e $resolved
ABresult
0X0
100
111
75 {
76 0 push @resolved, $resolved;
77 }
78 } ## end if ($no_glob)
79 else
80 {
81 4 ▶ push @resolved, grep { length and -e } glob $resolved;
Condition33%1/3
length $_ && -e $_
!ll&&!rl&&r
040
MC/DC0%0/2
length $_ && -e $_
length $_ -e $_
Truth table33%1/3
A && B
A= length $_B= -e $_
ABresult
0X0
100
111
82 }
83 } ## end foreach my $workspace_folder...
84  
85 4 return @resolved;
86 } ## end sub resolve_workspace_relative_path
87  
88 15 1;
« blib/lib/PLS/Server/Request/TextDocument/PublishDiagnostics.pm ↑ Summary blib/lib/PLS/Server/Method/TextDocument.pm »