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