/
TextDocument.php
83 lines (72 loc) · 2.17 KB
/
TextDocument.php
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
<?php
declare(strict_types=1);
namespace Psalm\Internal\LanguageServer\Client;
use Amp\Promise;
use Generator;
use JsonMapper;
use LanguageServerProtocol\Diagnostic;
use LanguageServerProtocol\TextDocumentIdentifier;
use LanguageServerProtocol\TextDocumentItem;
use Psalm\Internal\LanguageServer\ClientHandler;
use function Amp\call;
/**
* Provides method handlers for all textDocument/* methods
*
* @internal
*/
class TextDocument
{
/**
* @var ClientHandler
*/
private $handler;
/**
* @var JsonMapper
*/
private $mapper;
public function __construct(ClientHandler $handler, JsonMapper $mapper)
{
$this->handler = $handler;
$this->mapper = $mapper;
}
/**
* Diagnostics notification are sent from the server to the client to signal results of validation runs.
*
* @param Diagnostic[] $diagnostics
*/
public function publishDiagnostics(string $uri, array $diagnostics): void
{
$this->handler->notify('textDocument/publishDiagnostics', [
'uri' => $uri,
'diagnostics' => $diagnostics,
]);
}
/**
* The content request is sent from a server to a client
* to request the current content of a text document identified by the URI
*
* @param TextDocumentIdentifier $textDocument The document to get the content for
*
* @return Promise<TextDocumentItem> The document's current content
*
* @psalm-suppress MixedReturnTypeCoercion due to Psalm bug
*/
public function xcontent(TextDocumentIdentifier $textDocument): Promise
{
return call(
/**
* @return Generator<int, Promise<object>, object, TextDocumentItem>
*/
static function () use ($textDocument) {
/** @var Promise<object> */
$promise = $this->handler->request(
'textDocument/xcontent',
['textDocument' => $textDocument]
);
$result = yield $promise;
/** @var TextDocumentItem */
return $this->mapper->map($result, new TextDocumentItem);
}
);
}
}