forked from phpactor/language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandlerMethodResolver.php
More file actions
36 lines (29 loc) · 1.08 KB
/
HandlerMethodResolver.php
File metadata and controls
36 lines (29 loc) · 1.08 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
<?php
namespace Phpactor\LanguageServer\Core\Handler;
use RuntimeException;
final class HandlerMethodResolver
{
public function resolveHandlerMethod(Handler $handler, string $languageServerMethod): string
{
$handlerMap = $handler->methods();
if (!array_key_exists($languageServerMethod, $handlerMap)) {
throw new RuntimeException(sprintf(
'Resolved handler "%s" has not declared support for LSP method "%s", it declared support for "%s"',
$handler::class,
$languageServerMethod,
implode('", "', $handlerMap)
));
}
$method = $handlerMap[$languageServerMethod];
if (!method_exists($handler, $method)) {
throw new RuntimeException(sprintf(
'Handler "%s" for method "%s" does not have the "%s" method defined, it has "%s"',
$handler::class,
$languageServerMethod,
$method,
implode('", "', get_class_methods($handler))
));
}
return $method;
}
}