File Coverage

blib/lib/PLS/Server/Method/ServerMethod.pm
Criterion Covered Total %
statement 51 52 98.0
branch 23 24 95.8
condition n/a
subroutine 12 12 100.0
pod 0 2 0.0
total 86 90 95.5


line stmt bran cond sub pod time code
1             package PLS::Server::Method::ServerMethod;
2              
3 11     11   56 use strict;
  11         23  
  11         355  
4 11     11   40 use warnings;
  11         27  
  11         456  
5              
6 11     11   41 use PLS::Server::State;
  11         38  
  11         245  
7 11     11   4868 use PLS::Server::Request::Initialize;
  11         41  
  11         560  
8 11     11   5072 use PLS::Server::Request::Initialized;
  11         61  
  11         488  
9 11     11   6659 use PLS::Server::Request::CancelRequest;
  11         42  
  11         519  
10 11     11   9466 use PLS::Server::Request::Shutdown;
  11         35  
  11         467  
11 11     11   8779 use PLS::Server::Request::Exit;
  11         44  
  11         503  
12 11     11   140941 use PLS::Server::Response::ServerNotInitialized;
  11         44  
  11         387  
13 11     11   65388 use PLS::Server::Response::InvalidRequest;
  11         51  
  11         4141  
14              
15             =head1 NAME
16              
17             PLS::Server::Method::ServerMethod
18              
19             =head1 DESCRIPTION
20              
21             This module redirects requests that the server must handle to the appropriate
22             subclass of L<PLS::Server::Request>.
23              
24             It will also return the appropriate error if the client is attempting to make a
25             request before the server has been initialized (L<PLS::Server::Response::ServerNotInitialized>).
26              
27             If a shutdown request has been sent and another request is sent that is not an exit
28             request, the appropriate error will be returned (L<PLS::Server::Response::InvalidRequest>).
29              
30             Requests currently implemented:
31              
32             =over
33              
34             =item initialize - L<https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize>
35              
36             L<PLS::Server::Request::Initialize>
37              
38             =item initialized - L<https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialized>
39              
40             L<PLS::Server::Request::Initialized>
41              
42             =item $/cancelRequest - L<https://microsoft.github.io/language-server-protocol/specifications/specification-current/#cancelRequest>
43              
44             L<PLS::Server::Request::CancelRequest>
45              
46             =item shutdown - L<https://microsoft.github.io/language-server-protocol/specifications/specification-current/#shutdown>
47              
48             L<PLS::Server::Request::Shutdown>
49              
50             =item exit - L<https://microsoft.github.io/language-server-protocol/specifications/specification-current/#exit>
51              
52             L<PLS::Server::Request::Exit>
53              
54              
55             =back
56              
57             =cut
58              
59             sub get_request
60             {
61 16     16 0 118 my ($request) = @_;
62              
63 16         119 my $method = $request->{method};
64              
65 16 100       164 if ($method eq 'exit')
66             {
67 2         118 return PLS::Server::Request::Exit->new($request);
68             }
69              
70 14 100       184 return PLS::Server::Response::InvalidRequest->new($request) if $PLS::Server::State::SHUTDOWN;
71              
72 13 100       136 if ($method eq 'initialize')
73             {
74 5         9865 return PLS::Server::Request::Initialize->new($request);
75             }
76              
77 8 100       136 return PLS::Server::Response::ServerNotInitialized->new($request) unless $PLS::Server::State::INITIALIZED;
78              
79 7 100       192 if ($method eq 'initialized')
80             {
81 5         423 return PLS::Server::Request::Initialized->new($request);
82             }
83              
84 2 100       19 if ($method eq '$/cancelRequest') ## no critic (RequireInterpolationOfMetachars)
85             {
86 1         77 return PLS::Server::Request::CancelRequest->new($request);
87             }
88              
89 1 50       10 if ($method eq 'shutdown')
90             {
91 1         54 return PLS::Server::Request::Shutdown->new($request);
92             }
93              
94 0         0 return;
95             } ## end sub get_request
96              
97             sub is_server_method
98             {
99 19     19 0 81 my ($method) = @_;
100              
101 19 100       315 return 1 if ($method eq 'initialize');
102 14 100       164 return 1 if ($method eq 'initialized');
103 8 100       110 return 1 if ($method eq 'shutdown');
104 7 100       139 return 1 if ($method eq 'exit');
105 5 100       65 return 1 if ($method eq '$');
106 4         198 return 0;
107             } ## end sub is_server_method
108              
109             1;