-
Notifications
You must be signed in to change notification settings - Fork 668
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'hub/master' into fix_intersection_scanning
- Loading branch information
Showing
19 changed files
with
1,032 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/Psalm/Internal/LanguageServer/Client/Progress/LegacyProgress.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace Psalm\Internal\LanguageServer\Client\Progress; | ||
|
||
use LanguageServerProtocol\LogMessage; | ||
use LanguageServerProtocol\MessageType; | ||
use LogicException; | ||
use Psalm\Internal\LanguageServer\ClientHandler; | ||
|
||
/** @internal */ | ||
final class LegacyProgress implements ProgressInterface | ||
{ | ||
private const STATUS_INACTIVE = 'inactive'; | ||
private const STATUS_ACTIVE = 'active'; | ||
private const STATUS_FINISHED = 'finished'; | ||
|
||
private string $status = self::STATUS_INACTIVE; | ||
|
||
private ClientHandler $handler; | ||
private ?string $title = null; | ||
|
||
public function __construct(ClientHandler $handler) | ||
{ | ||
$this->handler = $handler; | ||
} | ||
|
||
public function begin(string $title, ?string $message = null, ?int $percentage = null): void | ||
{ | ||
|
||
if ($this->status === self::STATUS_ACTIVE) { | ||
throw new LogicException('Progress has already been started'); | ||
} | ||
|
||
if ($this->status === self::STATUS_FINISHED) { | ||
throw new LogicException('Progress has already been finished'); | ||
} | ||
|
||
$this->title = $title; | ||
|
||
$this->notify($message); | ||
|
||
$this->status = self::STATUS_ACTIVE; | ||
} | ||
|
||
public function update(?string $message = null, ?int $percentage = null): void | ||
{ | ||
if ($this->status === self::STATUS_FINISHED) { | ||
throw new LogicException('Progress has already been finished'); | ||
} | ||
|
||
if ($this->status === self::STATUS_INACTIVE) { | ||
throw new LogicException('Progress has not been started yet'); | ||
} | ||
|
||
$this->notify($message); | ||
} | ||
|
||
public function end(?string $message = null): void | ||
{ | ||
if ($this->status === self::STATUS_FINISHED) { | ||
throw new LogicException('Progress has already been finished'); | ||
} | ||
|
||
if ($this->status === self::STATUS_INACTIVE) { | ||
throw new LogicException('Progress has not been started yet'); | ||
} | ||
|
||
$this->notify($message); | ||
|
||
$this->status = self::STATUS_FINISHED; | ||
} | ||
|
||
private function notify(?string $message): void | ||
{ | ||
$this->handler->notify( | ||
'telemetry/event', | ||
new LogMessage( | ||
MessageType::INFO, | ||
$this->title . (empty($message) ? '' : (': ' . $message)), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.