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              
2             use strict;
3 9     9   53 use warnings;
  9         18  
  9         224  
4 9     9   37  
  9         18  
  9         176  
5             use PLS::Server::State;
6 9     9   37 use PLS::Server::Request::Initialize;
  9         10  
  9         144  
7 9     9   3481 use PLS::Server::Request::Initialized;
  9         19  
  9         249  
8 9     9   3426 use PLS::Server::Request::CancelRequest;
  9         18  
  9         225  
9 9     9   3359 use PLS::Server::Request::Shutdown;
  9         18  
  9         233  
10 9     9   3079 use PLS::Server::Request::Exit;
  9         26  
  9         225  
11 9     9   3541 use PLS::Server::Response::ServerNotInitialized;
  9         18  
  9         233  
12 9     9   3293 use PLS::Server::Response::InvalidRequest;
  9         27  
  9         233  
13 9     9   3803  
  9         19  
  9         1872  
14             =head1 NAME
15              
16             PLS::Server::Method::ServerMethod
17              
18             =head1 DESCRIPTION
19              
20             This module redirects requests that the server must handle to the appropriate
21             subclass of L<PLS::Server::Request>.
22              
23             It will also return the appropriate error if the client is attempting to make a
24             request before the server has been initialized (L<PLS::Server::Response::ServerNotInitialized>).
25              
26             If a shutdown request has been sent and another request is sent that is not an exit
27             request, the appropriate error will be returned (L<PLS::Server::Response::InvalidRequest>).
28              
29             Requests currently implemented:
30              
31             =over
32              
33             =item initialize - L<https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize>
34              
35             L<PLS::Server::Request::Initialize>
36              
37             =item initialized - L<https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialized>
38              
39             L<PLS::Server::Request::Initialized>
40              
41             =item $/cancelRequest - L<https://microsoft.github.io/language-server-protocol/specifications/specification-current/#cancelRequest>
42              
43             L<PLS::Server::Request::CancelRequest>
44              
45             =item shutdown - L<https://microsoft.github.io/language-server-protocol/specifications/specification-current/#shutdown>
46              
47             L<PLS::Server::Request::Shutdown>
48              
49             =item exit - L<https://microsoft.github.io/language-server-protocol/specifications/specification-current/#exit>
50              
51             L<PLS::Server::Request::Exit>
52              
53              
54             =back
55              
56             =cut
57              
58             {
59             my ($request) = @_;
60              
61 16     16 0 52 my $method = $request->{method};
62              
63 16         40 if ($method eq 'exit')
64             {
65 16 100       101 return PLS::Server::Request::Exit->new($request);
66             }
67 2         110  
68             return PLS::Server::Response::InvalidRequest->new($request) if $PLS::Server::State::SHUTDOWN;
69              
70 14 100       83 if ($method eq 'initialize')
71             {
72 13 100       77 return PLS::Server::Request::Initialize->new($request);
73             }
74 5         502  
75             return PLS::Server::Response::ServerNotInitialized->new($request) unless $PLS::Server::State::INITIALIZED;
76              
77 8 100       65 if ($method eq 'initialized')
78             {
79 7 100       72 return PLS::Server::Request::Initialized->new($request);
80             }
81 5         78  
82             if ($method eq '$/cancelRequest')
83             {
84 2 100       13 return PLS::Server::Request::CancelRequest->new($request);
85             }
86 1         50  
87             if ($method eq 'shutdown')
88             {
89 1 50       10 return PLS::Server::Request::Shutdown->new($request);
90             }
91 1         40  
92             return;
93             } ## end sub get_request
94 0         0  
95             {
96             my ($method) = @_;
97              
98             return 1 if ($method eq 'initialize');
99 19     19 0 70 return 1 if ($method eq 'initialized');
100             return 1 if ($method eq 'shutdown');
101 19 100       155 return 1 if ($method eq 'exit');
102 14 100       95 return 1 if ($method eq '$');
103 8 100       55 return 0;
104 7 100       54 } ## end sub is_server_method
105 5 100       46  
106 4         123 1;