Repository navigation
Expand file tree
/
Copy pathServerCapabilities.php
More file actions
455 lines (405 loc) · 17.9 KB
/
Copy pathServerCapabilities.php
File metadata and controls
455 lines (405 loc) · 17.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
<?php // Auto-generated from vscode-languageserver-protocol (typescript)
namespace Phpactor\LanguageServerProtocol;
use DTL\Invoke\Invoke;
use Exception;
use RuntimeException;
/**
* Defines the capabilities provided by a language
* server.
*/
class ServerCapabilities
{
/**
* The position encoding the server picked from the encodings offered
* by the client via the client capability `general.positionEncodings`.
*
* If the client didn't provide any position encodings the only valid
* value that a server can return is 'utf-16'.
*
* If omitted it defaults to 'utf-16'.
*
* @var string|null
*/
public $positionEncoding;
/**
* Defines how text documents are synced. Is either a detailed structure
* defining each notification or for backwards compatibility the
* TextDocumentSyncKind number.
*
* @var TextDocumentSyncOptions|TextDocumentSyncKind::*|null
*/
public $textDocumentSync;
/**
* Defines how notebook documents are synced.
*
* @var mixed|mixed|null
*/
public $notebookDocumentSync;
/**
* The server provides completion support.
*
* @var CompletionOptions|null
*/
public $completionProvider;
/**
* The server provides hover support.
*
* @var bool|HoverOptions|null
*/
public $hoverProvider;
/**
* The server provides signature help support.
*
* @var SignatureHelpOptions|null
*/
public $signatureHelpProvider;
/**
* The server provides Goto Declaration support.
*
* @var bool|DeclarationOptions|DeclarationRegistrationOptions|null
*/
public $declarationProvider;
/**
* The server provides goto definition support.
*
* @var bool|DefinitionOptions|null
*/
public $definitionProvider;
/**
* The server provides Goto Type Definition support.
*
* @var bool|TypeDefinitionOptions|TypeDefinitionRegistrationOptions|null
*/
public $typeDefinitionProvider;
/**
* The server provides Goto Implementation support.
*
* @var bool|ImplementationOptions|ImplementationRegistrationOptions|null
*/
public $implementationProvider;
/**
* The server provides find references support.
*
* @var bool|ReferenceOptions|null
*/
public $referencesProvider;
/**
* The server provides document highlight support.
*
* @var bool|DocumentHighlightOptions|null
*/
public $documentHighlightProvider;
/**
* The server provides document symbol support.
*
* @var bool|DocumentSymbolOptions|null
*/
public $documentSymbolProvider;
/**
* The server provides code actions. CodeActionOptions may only be
* specified if the client states that it supports
* `codeActionLiteralSupport` in its initial `initialize` request.
*
* @var bool|CodeActionOptions|null
*/
public $codeActionProvider;
/**
* The server provides code lens.
*
* @var CodeLensOptions|null
*/
public $codeLensProvider;
/**
* The server provides document link support.
*
* @var DocumentLinkOptions|null
*/
public $documentLinkProvider;
/**
* The server provides color provider support.
*
* @var bool|DocumentColorOptions|DocumentColorRegistrationOptions|null
*/
public $colorProvider;
/**
* The server provides workspace symbol support.
*
* @var bool|WorkspaceSymbolOptions|null
*/
public $workspaceSymbolProvider;
/**
* The server provides document formatting.
*
* @var bool|DocumentFormattingOptions|null
*/
public $documentFormattingProvider;
/**
* The server provides document range formatting.
*
* @var bool|DocumentRangeFormattingOptions|null
*/
public $documentRangeFormattingProvider;
/**
* The server provides document formatting on typing.
*
* @var DocumentOnTypeFormattingOptions|null
*/
public $documentOnTypeFormattingProvider;
/**
* The server provides rename support. RenameOptions may only be
* specified if the client states that it supports
* `prepareSupport` in its initial `initialize` request.
*
* @var bool|RenameOptions|null
*/
public $renameProvider;
/**
* The server provides folding provider support.
*
* @var bool|FoldingRangeOptions|FoldingRangeRegistrationOptions|null
*/
public $foldingRangeProvider;
/**
* The server provides selection range support.
*
* @var bool|SelectionRangeOptions|SelectionRangeRegistrationOptions|null
*/
public $selectionRangeProvider;
/**
* The server provides execute command support.
*
* @var ExecuteCommandOptions|null
*/
public $executeCommandProvider;
/**
* The server provides call hierarchy support.
*
* @var bool|CallHierarchyOptions|CallHierarchyRegistrationOptions|null
*/
public $callHierarchyProvider;
/**
* The server provides linked editing range support.
*
* @var bool|mixed|mixed|null
*/
public $linkedEditingRangeProvider;
/**
* The server provides semantic tokens support.
*
* @var mixed|mixed|null
*/
public $semanticTokensProvider;
/**
* The server provides moniker support.
*
* @var bool|mixed|mixed|null
*/
public $monikerProvider;
/**
* The server provides type hierarchy support.
*
* @var bool|mixed|mixed|null
*/
public $typeHierarchyProvider;
/**
* The server provides inline values.
*
* @var bool|WorkDoneProgressOptions|InlineValueRegistrationOptions|null
*/
public $inlineValueProvider;
/**
* The server provides inlay hints.
*
* @var bool|InlayHintOptions|InlayHintRegistrationOptions|null
*/
public $inlayHintProvider;
/**
* The server has support for pull model diagnostics.
*
* @var mixed|mixed|null
*/
public $diagnosticProvider;
/**
* Workspace specific server capabilities.
*
* @var array{workspaceFolders:WorkspaceFoldersServerCapabilities,fileOperations:FileOperationOptions}|null
*/
public $workspace;
/**
* Experimental server capabilities.
*
* @var mixed|null
*/
public $experimental;
/**
* @param string|null $positionEncoding
* @param TextDocumentSyncOptions|TextDocumentSyncKind::*|null $textDocumentSync
* @param mixed|mixed|null $notebookDocumentSync
* @param CompletionOptions|null $completionProvider
* @param bool|HoverOptions|null $hoverProvider
* @param SignatureHelpOptions|null $signatureHelpProvider
* @param bool|DeclarationOptions|DeclarationRegistrationOptions|null $declarationProvider
* @param bool|DefinitionOptions|null $definitionProvider
* @param bool|TypeDefinitionOptions|TypeDefinitionRegistrationOptions|null $typeDefinitionProvider
* @param bool|ImplementationOptions|ImplementationRegistrationOptions|null $implementationProvider
* @param bool|ReferenceOptions|null $referencesProvider
* @param bool|DocumentHighlightOptions|null $documentHighlightProvider
* @param bool|DocumentSymbolOptions|null $documentSymbolProvider
* @param bool|CodeActionOptions|null $codeActionProvider
* @param CodeLensOptions|null $codeLensProvider
* @param DocumentLinkOptions|null $documentLinkProvider
* @param bool|DocumentColorOptions|DocumentColorRegistrationOptions|null $colorProvider
* @param bool|WorkspaceSymbolOptions|null $workspaceSymbolProvider
* @param bool|DocumentFormattingOptions|null $documentFormattingProvider
* @param bool|DocumentRangeFormattingOptions|null $documentRangeFormattingProvider
* @param DocumentOnTypeFormattingOptions|null $documentOnTypeFormattingProvider
* @param bool|RenameOptions|null $renameProvider
* @param bool|FoldingRangeOptions|FoldingRangeRegistrationOptions|null $foldingRangeProvider
* @param bool|SelectionRangeOptions|SelectionRangeRegistrationOptions|null $selectionRangeProvider
* @param ExecuteCommandOptions|null $executeCommandProvider
* @param bool|CallHierarchyOptions|CallHierarchyRegistrationOptions|null $callHierarchyProvider
* @param bool|mixed|mixed|null $linkedEditingRangeProvider
* @param mixed|mixed|null $semanticTokensProvider
* @param bool|mixed|mixed|null $monikerProvider
* @param bool|mixed|mixed|null $typeHierarchyProvider
* @param bool|WorkDoneProgressOptions|InlineValueRegistrationOptions|null $inlineValueProvider
* @param bool|InlayHintOptions|InlayHintRegistrationOptions|null $inlayHintProvider
* @param mixed|mixed|null $diagnosticProvider
* @param array{workspaceFolders:WorkspaceFoldersServerCapabilities,fileOperations:FileOperationOptions}|null $workspace
* @param mixed|null $experimental
*/
public function __construct(?string $positionEncoding = null, $textDocumentSync = null, $notebookDocumentSync = null, ?CompletionOptions $completionProvider = null, $hoverProvider = null, ?SignatureHelpOptions $signatureHelpProvider = null, $declarationProvider = null, $definitionProvider = null, $typeDefinitionProvider = null, $implementationProvider = null, $referencesProvider = null, $documentHighlightProvider = null, $documentSymbolProvider = null, $codeActionProvider = null, ?CodeLensOptions $codeLensProvider = null, ?DocumentLinkOptions $documentLinkProvider = null, $colorProvider = null, $workspaceSymbolProvider = null, $documentFormattingProvider = null, $documentRangeFormattingProvider = null, ?DocumentOnTypeFormattingOptions $documentOnTypeFormattingProvider = null, $renameProvider = null, $foldingRangeProvider = null, $selectionRangeProvider = null, ?ExecuteCommandOptions $executeCommandProvider = null, $callHierarchyProvider = null, $linkedEditingRangeProvider = null, $semanticTokensProvider = null, $monikerProvider = null, $typeHierarchyProvider = null, $inlineValueProvider = null, $inlayHintProvider = null, $diagnosticProvider = null, ?array $workspace = null, $experimental = null)
{
$this->positionEncoding = $positionEncoding;
$this->textDocumentSync = $textDocumentSync;
$this->notebookDocumentSync = $notebookDocumentSync;
$this->completionProvider = $completionProvider;
$this->hoverProvider = $hoverProvider;
$this->signatureHelpProvider = $signatureHelpProvider;
$this->declarationProvider = $declarationProvider;
$this->definitionProvider = $definitionProvider;
$this->typeDefinitionProvider = $typeDefinitionProvider;
$this->implementationProvider = $implementationProvider;
$this->referencesProvider = $referencesProvider;
$this->documentHighlightProvider = $documentHighlightProvider;
$this->documentSymbolProvider = $documentSymbolProvider;
$this->codeActionProvider = $codeActionProvider;
$this->codeLensProvider = $codeLensProvider;
$this->documentLinkProvider = $documentLinkProvider;
$this->colorProvider = $colorProvider;
$this->workspaceSymbolProvider = $workspaceSymbolProvider;
$this->documentFormattingProvider = $documentFormattingProvider;
$this->documentRangeFormattingProvider = $documentRangeFormattingProvider;
$this->documentOnTypeFormattingProvider = $documentOnTypeFormattingProvider;
$this->renameProvider = $renameProvider;
$this->foldingRangeProvider = $foldingRangeProvider;
$this->selectionRangeProvider = $selectionRangeProvider;
$this->executeCommandProvider = $executeCommandProvider;
$this->callHierarchyProvider = $callHierarchyProvider;
$this->linkedEditingRangeProvider = $linkedEditingRangeProvider;
$this->semanticTokensProvider = $semanticTokensProvider;
$this->monikerProvider = $monikerProvider;
$this->typeHierarchyProvider = $typeHierarchyProvider;
$this->inlineValueProvider = $inlineValueProvider;
$this->inlayHintProvider = $inlayHintProvider;
$this->diagnosticProvider = $diagnosticProvider;
$this->workspace = $workspace;
$this->experimental = $experimental;
}
/**
* @param array<string,mixed> $array
* @return self
*/
public static function fromArray(array $array, bool $allowUnknownKeys = false)
{
$map = [
'positionEncoding' => ['names' => [], 'iterable' => false],
'textDocumentSync' => ['names' => [TextDocumentSyncOptions::class], 'iterable' => false],
'notebookDocumentSync' => ['names' => [], 'iterable' => false],
'completionProvider' => ['names' => [CompletionOptions::class], 'iterable' => false],
'hoverProvider' => ['names' => [HoverOptions::class], 'iterable' => false],
'signatureHelpProvider' => ['names' => [SignatureHelpOptions::class], 'iterable' => false],
'declarationProvider' => ['names' => [DeclarationOptions::class, DeclarationRegistrationOptions::class], 'iterable' => false],
'definitionProvider' => ['names' => [DefinitionOptions::class], 'iterable' => false],
'typeDefinitionProvider' => ['names' => [TypeDefinitionOptions::class, TypeDefinitionRegistrationOptions::class], 'iterable' => false],
'implementationProvider' => ['names' => [ImplementationOptions::class, ImplementationRegistrationOptions::class], 'iterable' => false],
'referencesProvider' => ['names' => [ReferenceOptions::class], 'iterable' => false],
'documentHighlightProvider' => ['names' => [DocumentHighlightOptions::class], 'iterable' => false],
'documentSymbolProvider' => ['names' => [DocumentSymbolOptions::class], 'iterable' => false],
'codeActionProvider' => ['names' => [CodeActionOptions::class], 'iterable' => false],
'codeLensProvider' => ['names' => [CodeLensOptions::class], 'iterable' => false],
'documentLinkProvider' => ['names' => [DocumentLinkOptions::class], 'iterable' => false],
'colorProvider' => ['names' => [DocumentColorOptions::class, DocumentColorRegistrationOptions::class], 'iterable' => false],
'workspaceSymbolProvider' => ['names' => [WorkspaceSymbolOptions::class], 'iterable' => false],
'documentFormattingProvider' => ['names' => [DocumentFormattingOptions::class], 'iterable' => false],
'documentRangeFormattingProvider' => ['names' => [DocumentRangeFormattingOptions::class], 'iterable' => false],
'documentOnTypeFormattingProvider' => ['names' => [DocumentOnTypeFormattingOptions::class], 'iterable' => false],
'renameProvider' => ['names' => [RenameOptions::class], 'iterable' => false],
'foldingRangeProvider' => ['names' => [FoldingRangeOptions::class, FoldingRangeRegistrationOptions::class], 'iterable' => false],
'selectionRangeProvider' => ['names' => [SelectionRangeOptions::class, SelectionRangeRegistrationOptions::class], 'iterable' => false],
'executeCommandProvider' => ['names' => [ExecuteCommandOptions::class], 'iterable' => false],
'callHierarchyProvider' => ['names' => [CallHierarchyOptions::class, CallHierarchyRegistrationOptions::class], 'iterable' => false],
'linkedEditingRangeProvider' => ['names' => [], 'iterable' => false],
'semanticTokensProvider' => ['names' => [], 'iterable' => false],
'monikerProvider' => ['names' => [], 'iterable' => false],
'typeHierarchyProvider' => ['names' => [], 'iterable' => false],
'inlineValueProvider' => ['names' => [InlineValueRegistrationOptions::class], 'iterable' => false],
'inlayHintProvider' => ['names' => [InlayHintOptions::class, InlayHintRegistrationOptions::class], 'iterable' => false],
'diagnosticProvider' => ['names' => [], 'iterable' => false],
'workspace' => ['names' => [], 'iterable' => false],
'experimental' => ['names' => [], 'iterable' => false],
];
foreach ($array as $key => &$value) {
if (!isset($map[$key])) {
if ($allowUnknownKeys) {
unset($array[$key]);
continue;
}
throw new RuntimeException(sprintf(
'Parameter "%s" on class "%s" not known, known parameters: "%s"',
$key,
self::class,
implode('", "', array_keys($map))
));
}
// from here we only care about arrays that can be transformed into
// objects
if (!is_array($value)) {
continue;
}
if (empty($map[$key]['names'])) {
continue;
}
if ($map[$key]['iterable']) {
$value = array_map(function ($object) use ($map, $key, $allowUnknownKeys) {
if (!is_array($object)) {
return $object;
}
return self::invokeFromNames($map[$key]['names'], $object, $allowUnknownKeys) ?: $object;
}, $value);
continue;
}
$names = $map[$key]['names'];
$value = self::invokeFromNames($names, $value, $allowUnknownKeys) ?: $value;
}
return Invoke::new(self::class, $array);
}
/**
* @param array<string> $classNames
* @param array<string,mixed> $object
*/
private static function invokeFromNames(array $classNames, array $object, bool $allowUnknownKeys): ?object
{
$lastException = null;
foreach ($classNames as $className) {
try {
// @phpstan-ignore-next-line
return call_user_func_array($className . '::fromArray', [$object, $allowUnknownKeys]);
} catch (Exception $exception) {
$lastException = $exception;
continue;
}
}
throw $lastException;
}
}