-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathTextDocumentTester.php
More file actions
58 lines (51 loc) · 1.99 KB
/
TextDocumentTester.php
File metadata and controls
58 lines (51 loc) · 1.99 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
<?php
namespace Phpactor\LanguageServer\Test\LanguageServerTester;
use Phpactor\LanguageServerProtocol\DidChangeTextDocumentNotification;
use Phpactor\LanguageServerProtocol\DidChangeTextDocumentParams;
use Phpactor\LanguageServerProtocol\DidSaveTextDocumentNotification;
use Phpactor\LanguageServerProtocol\DidSaveTextDocumentParams;
use Phpactor\LanguageServerProtocol\TextDocumentContentChangeFullEvent;
use Phpactor\LanguageServer\Test\ProtocolFactory;
use Phpactor\LanguageServerProtocol\DidOpenTextDocumentParams;
use Phpactor\LanguageServerProtocol\DidOpenTextDocumentNotification;
use Phpactor\LanguageServer\Test\LanguageServerTester;
use RuntimeException;
class TextDocumentTester
{
/**
* @var array<string,int>
*/
private static array $versions = [];
public function __construct(private LanguageServerTester $tester)
{
}
public function open(string $url, string $content): void
{
self::$versions[$url] = 1;
$this->tester->notifyAndWait(DidOpenTextDocumentNotification::METHOD, new DidOpenTextDocumentParams(
ProtocolFactory::textDocumentItem($url, $content)
));
}
public function update(string $uri, string $newText): void
{
if (!isset(self::$versions[$uri])) {
throw new RuntimeException(sprintf(
'Cannot update document that has not been opened: %s',
$uri
));
}
self::$versions[$uri]++;
$this->tester->notifyAndWait(DidChangeTextDocumentNotification::METHOD, new DidChangeTextDocumentParams(
ProtocolFactory::versionedTextDocumentIdentifier($uri, self::$versions[$uri]),
[
new TextDocumentContentChangeFullEvent($newText),
]
));
}
public function save(string $uri): void
{
$this->tester->notifyAndWait(DidSaveTextDocumentNotification::METHOD, new DidSaveTextDocumentParams(
ProtocolFactory::versionedTextDocumentIdentifier($uri, 1)
));
}
}