File Coverage

blib/lib/Perl/LanguageServer/Methods.pm
Criterion Covered Total %
statement 12 38 31.5
branch 0 16 0.0
condition n/a
subroutine 4 9 44.4
pod n/a
total 16 63 25.4


line stmt bran cond sub pod time code
1             package Perl::LanguageServer::Methods ;
2              
3 1     1   846 use Moose::Role ;
  1         3  
  1         14  
4 1     1   6103 use JSON ;
  1         2  
  1         11  
5 1     1   158 use Data::Dump qw{pp} ;
  1         6  
  1         73  
6              
7 1     1   6 no warnings 'uninitialized' ;
  1         3  
  1         635  
8              
9             # ---------------------------------------------------------------------------
10              
11             sub _rpcreq_initialize
12             {
13 0     0     my ($self, $workspace, $req) = @_ ;
14              
15             #print STDERR "Call initialize\n" ;
16 0 0         $self -> logger ("initialize ", $Perl::LanguageServer::jsonpretty -> encode ($req -> params), "\n")
17             if ($Perl::LanguageServer::debug1) ;
18              
19 0           $Perl::LanguageServer::workspace = Perl::LanguageServer::Workspace -> new ({ config => $req -> params }) ;
20              
21 0           my $caps =
22             {
23             # Defines how text documents are synced. Is either a detailed structure defining each notification or
24             # for backwards compatibility the TextDocumentSyncKind number. If omitted it defaults to `TextDocumentSyncKind.None`.
25             textDocumentSync => 1, # full
26              
27             # The server provides hover support.
28             #hoverProvider?: boolean;
29              
30             # The server provides completion support.
31             #completionProvider?: CompletionOptions;
32              
33             # The server provides signature help support.
34             #signatureHelpProvider?: SignatureHelpOptions;
35             signatureHelpProvider =>
36             {
37             triggerCharacters => ['('],
38             },
39              
40             # The server provides goto definition support.
41             #definitionProvider?: boolean;
42             definitionProvider => JSON::true,
43              
44             # The server provides Goto Type Definition support.
45             # Since 3.6.0
46             #typeDefinitionProvider?: boolean | (TextDocumentRegistrationOptions & StaticRegistrationOptions);
47              
48             # The server provides Goto Implementation support.
49             # Since 3.6.0
50             #implementationProvider?: boolean | (TextDocumentRegistrationOptions & StaticRegistrationOptions);
51              
52             # The server provides find references support.
53             referencesProvider => JSON::true,
54              
55             # The server provides document highlight support.
56             #documentHighlightProvider?: boolean;
57              
58             # The server provides document symbol support.
59             #documentSymbolProvider?: boolean;
60             documentSymbolProvider => JSON::true,
61              
62             # The server provides workspace symbol support.
63             workspaceSymbolProvider => JSON::true,
64              
65             # The server provides code actions.
66             #codeActionProvider?: boolean;
67              
68             # The server provides code lens.
69             #codeLensProvider?: CodeLensOptions;
70              
71             # The server provides document formatting.
72             #documentFormattingProvider?: boolean;
73             #documentFormattingProvider => JSON::true,
74              
75             # The server provides document range formatting.
76             #documentRangeFormattingProvider?: boolean;
77             documentRangeFormattingProvider => JSON::true,
78              
79             # The server provides document formatting on typing.
80             #documentOnTypeFormattingProvider?: DocumentOnTypeFormattingOptions;
81              
82             # The server provides rename support.
83             #renameProvider?: boolean;
84              
85             # The server provides document link support.
86             #documentLinkProvider?: DocumentLinkOptions;
87              
88             # The server provides color provider support.
89             # Since 3.6.0
90             #colorProvider?: boolean | ColorProviderOptions | (ColorProviderOptions & TextDocumentRegistrationOptions & StaticRegistrationOptions);
91              
92             # The server provides execute command support.
93             #executeCommandProvider?: ExecuteCommandOptions;
94              
95             # The server provides selection range support.
96             # @since 3.15.0
97             # selectionRangeProvider?: boolean | SelectionRangeOptions | SelectionRangeRegistrationOptions;
98              
99             #selectionRangeProvider => JSON::true,
100              
101             # Workspace specific server capabilities
102             workspace => {
103              
104             # The server supports workspace folder.
105             # Since 3.6.0
106             workspaceFolders => {
107              
108             # The server has support for workspace folders
109             supported => JSON::true,
110              
111             # * Whether the server wants to receive workspace folder
112             # * change notifications.
113             # *
114             # * If a strings is provided the string is treated as a ID
115             # * under which the notification is registered on the client
116             # * side. The ID can be used to unregister for these events
117             # * using the `client/unregisterCapability` request.
118             # */
119             changeNotifications => JSON::true,
120             }
121             }
122              
123             # Experimental server capabilities.
124             #experimental?: any;
125             } ;
126              
127 0           return { capabilities => $caps } ;
128             }
129              
130              
131             # ---------------------------------------------------------------------------
132              
133             sub _rpcnot_initialized
134             {
135 0     0     my ($self, $workspace, $req) = @_ ;
136              
137 0 0         return if (!$Perl::LanguageServer::client_version) ;
138              
139 0 0         if ($Perl::LanguageServer::client_version ne $Perl::LanguageServer::VERSION)
140             {
141 0           my $msg = "Version of IDE/Editor plugin is $Perl::LanguageServer::client_version\nVersion of Perl::LanguageServer is $Perl::LanguageServer::VERSION\nPlease make sure you run matching versions of the plugin and the Perl::LanguageServer module\nUse 'cpan Perl::LanguageServer' to install the newest version of the Perl::LanguageServer module\n" ;
142 0           $self -> logger ("\n$msg\n") ;
143             }
144 0           return ;
145             }
146              
147              
148             # ---------------------------------------------------------------------------
149              
150             sub _rpcnot_cancelRequest
151             {
152 0     0     my ($self, $workspace, $req) = @_ ;
153              
154 0           my $cancel_id = $req -> params -> {id} ;
155 0 0         return if (!$cancel_id) ;
156 0 0         return if (!exists $Perl::LanguageServer::running_req{$cancel_id}) ;
157 0           $Perl::LanguageServer::running_req{$cancel_id} -> cancel_req ;
158              
159 0           return ;
160             }
161              
162             # ---------------------------------------------------------------------------
163              
164             sub _rpcreq_shutdown
165             {
166 0     0     my ($self, $workspace, $req) = @_ ;
167              
168 0 0         return if (!$workspace) ;
169              
170 0           $workspace -> shutdown ;
171             }
172              
173             # ---------------------------------------------------------------------------
174              
175             sub _rpcnot_exit
176             {
177 0     0     my ($self, $workspace, $req) = @_ ;
178              
179 0           print STDERR "Exit\n" ;
180              
181 0 0         exit (1) if (!$workspace) ;
182 0 0         exit (1) if (!$workspace -> is_shutdown) ;
183 0           exit (0) ;
184 0           return ;
185             }
186              
187             # ---------------------------------------------------------------------------
188              
189             1 ;