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 9     9   46 use strict;
  9         17  
  9         218  
4 9     9   36 use warnings;
  9         19  
  9         172  
5              
6 9     9   36 use PLS::Server::State;
  9         18  
  9         130  
7 9     9   3293 use PLS::Server::Request::Initialize;
  9         19  
  9         252  
8 9     9   3132 use PLS::Server::Request::Initialized;
  9         18  
  9         245  
9 9     9   3096 use PLS::Server::Request::CancelRequest;
  9         18  
  9         228  
10 9     9   3144 use PLS::Server::Request::Shutdown;
  9         10  
  9         242  
11 9     9   2903 use PLS::Server::Request::Exit;
  9         26  
  9         234  
12 9     9   3798 use PLS::Server::Response::ServerNotInitialized;
  9         26  
  9         236  
13 9     9   3149 use PLS::Server::Response::InvalidRequest;
  9         18  
  9         1923  
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 47 my ($request) = @_;
62              
63 16         71 my $method = $request->{method};
64              
65 16 100       217 if ($method eq 'exit')
66             {
67 2         84 return PLS::Server::Request::Exit->new($request);
68             }
69              
70 14 100       76 return PLS::Server::Response::InvalidRequest->new($request) if $PLS::Server::State::SHUTDOWN;
71              
72 13 100       82 if ($method eq 'initialize')
73             {
74 5         374 return PLS::Server::Request::Initialize->new($request);
75             }
76              
77 8 100       115 return PLS::Server::Response::ServerNotInitialized->new($request) unless $PLS::Server::State::INITIALIZED;
78              
79 7 100       51 if ($method eq 'initialized')
80             {
81 5         117 return PLS::Server::Request::Initialized->new($request);
82             }
83              
84 2 100       12 if ($method eq '$/cancelRequest')
85             {
86 1         42 return PLS::Server::Request::CancelRequest->new($request);
87             }
88              
89 1 50       5 if ($method eq 'shutdown')
90             {
91 1         35 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 147 my ($method) = @_;
100              
101 19 100       196 return 1 if ($method eq 'initialize');
102 14 100       114 return 1 if ($method eq 'initialized');
103 8 100       44 return 1 if ($method eq 'shutdown');
104 7 100       25 return 1 if ($method eq 'exit');
105 5 100       20 return 1 if ($method eq '$');
106 4         116 return 0;
107             } ## end sub is_server_method
108              
109             1;