File Coverage

blib/lib/PLS/Server/Request/Workspace/DidChangeWatchedFiles.pm
Criterion Covered Total %
statement 21 40 52.5
branch 0 14 0.0
condition n/a
subroutine 7 9 77.7
pod 0 1 0.0
total 28 64 43.7


line stmt bran cond sub pod time code
1              
2             use strict;
3 9     9   60 use warnings;
  9         20  
  9         217  
4 9     9   37  
  9         18  
  9         302  
5             use parent 'PLS::Server::Request';
6 9     9   52  
  9         74  
  9         43  
7             use List::Util qw(any uniq);
8 9     9   683 use Path::Tiny;
  9         17  
  9         1132  
9 9     9   62  
  9         24  
  9         1133  
10             use PLS::Parser::Index;
11 9     9   63 use PLS::Server::Request::TextDocument::PublishDiagnostics;
  9         9  
  9         234  
12 9     9   46  
  9         17  
  9         3532  
13             =head1 NAME
14              
15             PLS::Server::Request::Workspace::DidChangeWatchedFiles
16              
17             =head1 DESCRIPTION
18              
19             This is a notification from the client to the server indicating
20             that one or more files that the server watched have changed.
21              
22             The server queues up these files to be re-indexed.
23              
24             =cut
25              
26             {
27             my ($self, $server) = @_;
28              
29 0     0 0   return if (ref $self->{params}{changes} ne 'ARRAY');
30              
31 0 0         my $index = PLS::Parser::Index->new();
32              
33 0           my @changed_files;
34              
35 0           foreach my $change (@{$self->{params}{changes}})
36             {
37 0           my $file = URI->new($change->{uri});
  0            
38             next if (ref $file ne 'URI::file');
39 0            
40 0 0         if ($change->{type} == 3)
41             {
42 0 0         $index->cleanup_file($file->file);
43             next;
44 0           }
45 0            
46             next if ($file->file =~ /\/\.pls-tmp-[^\/]*$/);
47              
48 0 0         next unless $index->is_perl_file($file->file);
49             next if $index->is_ignored($file->file);
50 0 0          
51 0 0         push @changed_files, $change->{uri};
52             } ## end foreach my $change (@{$self...})
53 0            
54             @changed_files = uniq @changed_files;
55             $index->index_files(@changed_files)->then(sub { Future->wait_all(@_) })->retain() if (scalar @changed_files);
56 0            
57 0 0   0     return;
  0            
58             } ## end sub service
59 0            
60             1;