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