Skip to content

Commit

Permalink
Remove redundant versioning checks
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech committed Mar 3, 2024
1 parent 844bcee commit c46e883
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
23 changes: 10 additions & 13 deletions lib/Core/Diagnostics/DiagnosticsEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ class DiagnosticsEngine
*/
private array $diagnostics = [];

/**
* @var array<int|string,int|string>
*/
private array $versions = [];

/**
* @var array<string,Deferred<bool>>
*/
Expand Down Expand Up @@ -78,9 +73,14 @@ public function run(CancellationToken $token): Promise

yield $this->awaitNextDocument();

$beforeDocument = $this->waiting;
$gracePeriod = abs($this->sleepTime - ((microtime(true) - $this->lastUpdatedAt) * 1000));
yield delay(intval($gracePeriod));

if ($beforeDocument !== $this->waiting) {
continue;
}

$textDocument = $this->waiting;
$this->waiting = null;
// allow the next document update to resolve
Expand All @@ -99,8 +99,6 @@ public function run(CancellationToken $token): Promise
);
$this->diagnostics[$textDocument->uri] = [];

$this->versions[$textDocument->uri] = $textDocument->version;

$crashedProviders = [];

foreach ($this->providers as $providerId => $provider) {
Expand Down Expand Up @@ -144,15 +142,14 @@ public function run(CancellationToken $token): Promise

$elapsed = (int)round((microtime(true) - $start) / 1000);

$this->diagnostics[$textDocument->uri] = array_merge(
$this->diagnostics[$textDocument->uri] ?? [],
$diagnostics
);

if (!$this->isDocumentCurrent($textDocument)) {
return;
}

$this->diagnostics[$textDocument->uri] = array_merge(
$this->diagnostics[$textDocument->uri] ?? [],
$diagnostics
);

$this->clientApi->diagnostics()->publishDiagnostics(
$textDocument->uri,
Expand Down Expand Up @@ -188,7 +185,7 @@ public function enqueue(TextDocumentItem $textDocument): void

private function isDocumentCurrent(TextDocumentItem $textDocument): bool
{
return $textDocument->version === ($this->versions[$textDocument->uri] ?? -1);
return $this->waiting === null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Core/Diagnostics/DiagnosticsEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testOnlyPublishesForMostRecentFile(): Generator
$engine->enqueue(ProtocolFactory::textDocumentItem('file:///barfoo', 'foobar'));
$engine->enqueue(ProtocolFactory::textDocumentItem('file:///bazbar', 'foobar'));

yield new Delayed(0);
yield new Delayed(1);

$token->cancel();

Expand Down

0 comments on commit c46e883

Please sign in to comment.