Skip to content

Commit e547efe

Browse files
committed
Fix versioning in tester
1 parent d166de0 commit e547efe

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/Test/LanguageServerTester/TextDocumentTester.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@
1010
use Phpactor\LanguageServerProtocol\DidOpenTextDocumentParams;
1111
use Phpactor\LanguageServerProtocol\DidOpenTextDocumentNotification;
1212
use Phpactor\LanguageServer\Test\LanguageServerTester;
13+
use RuntimeException;
1314

1415
class TextDocumentTester
1516
{
17+
/**
18+
* @var array<string,int>
19+
*/
20+
private static $versions = [];
21+
1622
/**
1723
* @var LanguageServerTester
1824
*/
@@ -25,15 +31,23 @@ public function __construct(LanguageServerTester $tester)
2531

2632
public function open(string $url, string $content): void
2733
{
34+
self::$versions[$url] = 1;
2835
$this->tester->notifyAndWait(DidOpenTextDocumentNotification::METHOD, new DidOpenTextDocumentParams(
2936
ProtocolFactory::textDocumentItem($url, $content)
3037
));
3138
}
3239

3340
public function update(string $uri, string $newText): void
3441
{
42+
if (!isset(self::$versions[$uri])) {
43+
throw new RuntimeException(sprintf(
44+
'Cannot update document that has not been opened: %s',
45+
$uri
46+
));
47+
}
48+
self::$versions[$uri]++;
3549
$this->tester->notifyAndWait(DidChangeTextDocumentNotification::METHOD, new DidChangeTextDocumentParams(
36-
ProtocolFactory::versionedTextDocumentIdentifier($uri, 1),
50+
ProtocolFactory::versionedTextDocumentIdentifier($uri, self::$versions[$uri]),
3751
[
3852
[
3953
'text' => $newText

0 commit comments

Comments
 (0)