blib/lib/PLS/Server/Request/TextDocument/DidChange.pm

filter: Statementstmt 62.2% 28 / 45 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 9 / 12 Podpod 0.0% 0 / 1 totaltotal 59.6% 37 / 62 CC 3 SCAR 12.5
CC
3
Cov
57%
service
12.0
__ANON__
2.0
__ANON__
2.0
CRAP 3.5
« blib/lib/PLS/Server/Method/ServerMethod.pm ↑ Summary blib/lib/PLS/Server.pm »
1 package PLS::Server::Request::TextDocument::DidChange;
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 parent 'PLS::Server::Request';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 13 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 13 ▶use IO::Async::Loop;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use IO::Async::Timer::Countdown;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 13 ▶use PLS::Parser::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 13 ▶use PLS::Parser::Index;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 13 ▶use PLS::Server::Request::TextDocument::PublishDiagnostics;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 NAME
18  
19 PLS::Server::Request::TextDocument::DidChange
20  
21 =head1 DESCRIPTION
22  
23 This is a notification from the client to the server that
24 a text document was changed.
25  
26 =cut
27  
28 sub service
29 0 ▶{
Subroutine service: not called CC=3 SCAR=24.8
Pod undocumented
30 0 my ($self, $server) = @_;
31  
32 0 ▶ return unless (ref $self->{params}{contentChanges} eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"params"}{"contentChanges"} eq "ARRAY" 0 0 0
33 PLS::Parser::Document->update_file(
34 uri => $self->{params}{textDocument}{uri},
35 changes => $self->{params}{contentChanges},
36 version => $self->{params}{textDocument}{version}
37 0 );
38  
39 0 state %timers;
40  
41 0 my $uri = $self->{params}{textDocument}{uri};
42  
43 0 ▶ if (ref $timers{$uri} eq 'IO::Async::Timer::Countdown')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $timers{$uri} eq 'IO::Async::Timer::Countdown') { } 0 0 0
44 {
45 # If we get another change before the timer goes off, reset the timer.
46 # This will allow us to limit the diagnostics to a time one second after the user stopped typing.
47 0 $timers{$uri}->reset();
48 } ## end if (ref $timers{$uri} ...)
49 else
50 {
51 $timers{$uri} = IO::Async::Timer::Countdown->new(
52 delay => 2,
53 0 ▶ on_expire => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
54 0 my $index = PLS::Parser::Index->new();
55 0 ▶ $index->index_files($uri)->then(sub { Future->wait_all(@_) })->retain();
Subroutine __ANON__: not called CC=1 SCAR=6.9
56  
57 0 $server->send_server_request(PLS::Server::Request::TextDocument::PublishDiagnostics->new(uri => $uri));
58 0 delete $timers{$uri};
59 },
60 0 remove_on_expire => 1
61 );
62  
63 0 my $loop = IO::Async::Loop->new();
64 0 $loop->add($timers{$uri});
65 0 $timers{$uri}->start();
66 } ## end else[ if (ref $timers{$uri} ...)]
67  
68 0 return;
69 } ## end sub service
70  
71 13 1;
« blib/lib/PLS/Server/Method/ServerMethod.pm ↑ Summary blib/lib/PLS/Server.pm »