File Coverage

blib/lib/PLS/Server/Request/TextDocument/DidChange.pm
Criterion Covered Total %
statement 27 44 61.3
branch 0 4 0.0
condition n/a
subroutine 9 11 81.8
pod 0 1 0.0
total 36 60 60.0


line stmt bran cond sub pod time code
1              
2             use strict;
3 9     9   54 use warnings;
  9         18  
  9         328  
4 9     9   45  
  9         18  
  9         197  
5             use parent 'PLS::Server::Request';
6 9     9   44  
  9         10  
  9         37  
7             use feature 'state';
8 9     9   539  
  9         18  
  9         516  
9             use IO::Async::Loop;
10 9     9   54 use IO::Async::Timer::Countdown;
  9         10  
  9         154  
11 9     9   36  
  9         24  
  9         265  
12             use PLS::Parser::Document;
13 9     9   52 use PLS::Parser::Index;
  9         10  
  9         258  
14 9     9   45 use PLS::Server::Request::TextDocument::PublishDiagnostics;
  9         18  
  9         153  
15 9     9   3524  
  9         200  
  9         5645  
16             =head1 NAME
17              
18             PLS::Server::Request::TextDocument::DidChange
19              
20             =head1 DESCRIPTION
21              
22             This is a notification from the client to the server that
23             a text document was changed.
24              
25             =cut
26              
27             {
28             my ($self, $server) = @_;
29              
30 0     0 0   return unless (ref $self->{params}{contentChanges} eq 'ARRAY');
31             PLS::Parser::Document->update_file(
32 0 0         uri => $self->{params}{textDocument}{uri},
33             changes => $self->{params}{contentChanges},
34             version => $self->{params}{textDocument}{version}
35             );
36              
37 0           state %timers;
38              
39 0           my $uri = $self->{params}{textDocument}{uri};
40              
41 0           if (ref $timers{$uri} eq 'IO::Async::Timer::Countdown')
42             {
43 0 0         # If we get another change before the timer goes off, reset the timer.
44             # This will allow us to limit the diagnostics to a time one second after the user stopped typing.
45             $timers{$uri}->reset();
46             } ## end if (ref $timers{$uri} ...)
47 0           else
48             {
49             $timers{$uri} = IO::Async::Timer::Countdown->new(
50             delay => 2,
51             on_expire => sub {
52             my $index = PLS::Parser::Index->new();
53             $index->index_files($uri)->then(sub { Future->wait_all(@_) })->retain();
54 0     0      
55 0           $server->send_server_request(PLS::Server::Request::TextDocument::PublishDiagnostics->new(uri => $uri));
  0            
56             delete $timers{$uri};
57 0           },
58 0           remove_on_expire => 1
59             );
60 0            
61             my $loop = IO::Async::Loop->new();
62             $loop->add($timers{$uri});
63 0           $timers{$uri}->start();
64 0           } ## end else [ if (ref $timers{$uri} ...)]
65 0            
66             return;
67             } ## end sub service
68 0            
69             1;