File Coverage

blib/lib/PLS/Server/Response/SignatureHelp.pm
Criterion Covered Total %
statement 15 31 48.3
branch 0 6 0.0
condition 0 9 0.0
subroutine 5 6 83.3
pod 0 1 0.0
total 20 53 37.7


line stmt bran cond sub pod time code
1             package PLS::Server::Response::SignatureHelp;
2              
3 11     11   110 use strict;
  11         181  
  11         638  
4 11     11   259 use warnings;
  11         278  
  11         1071  
5              
6 11     11   229 use parent q(PLS::Server::Response);
  11         180  
  11         316  
7              
8 11     11   1428 use Scalar::Util qw(blessed);
  11         184  
  11         4297  
9              
10 11     11   217 use PLS::Parser::Document;
  11         144  
  11         6673  
11              
12             =head1 NAME
13              
14             PLS::Server::Response::SignatureHelp
15              
16             =head1 DESCRIPTION
17              
18             This is a message from the server to the client with information about the
19             parameters of the current function.
20              
21             =cut
22              
23             sub new
24             {
25 0     0 0   my ($class, $request) = @_;
26              
27             my $self = bless {
28             id => $request->{id},
29 0           result => undef
30             }, $class;
31              
32 0           my ($line, $character) = @{$request->{params}{position}}{qw(line character)};
  0            
33 0           my $document = PLS::Parser::Document->new(uri => $request->{params}{textDocument}{uri}, line => $line);
34 0 0         return $self if (ref $document ne 'PLS::Parser::Document');
35              
36 0           my $list = $document->find_current_list($line, $character);
37 0           my ($results, $sub_call) = $document->go_to_definition_of_closest_subroutine($list, $line, $character);
38 0           my @signatures = map { $_->{signature} } @{$results};
  0            
  0            
39 0           my $active_parameter = $document->get_list_index($list, $request->{params}{position}{line}, $request->{params}{position}{character});
40              
41             # If this is a method call, then we should skip the first parameter.
42 0 0 0       if ( blessed($sub_call)
      0        
      0        
43             and blessed($sub_call->previous_sibling)
44             and $sub_call->previous_sibling->type eq 'PPI::Token::Operator'
45             and $sub_call->previous_sibling->name eq '->')
46             {
47 0           $active_parameter++;
48             } ## end if (blessed($sub_call)...)
49              
50 0 0         $self->{result} = {signatures => \@signatures, activeParameter => $active_parameter} if (scalar @signatures);
51              
52 0           return $self;
53             } ## end sub new
54              
55             1;