From 0eb00e8ae2b0552dd8910aef13c40926cd3fcf54 Mon Sep 17 00:00:00 2001 From: Andrew Nagy Date: Mon, 10 Jan 2022 23:27:18 +0000 Subject: [PATCH] Fix closure to have storage bug in codeAction --- .../Internal/LanguageServer/LanguageServer.php | 16 ++++++++++++++++ .../LanguageServer/Server/TextDocument.php | 11 ++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Internal/LanguageServer/LanguageServer.php b/src/Psalm/Internal/LanguageServer/LanguageServer.php index 6716f2024ac..b78e41d3a30 100644 --- a/src/Psalm/Internal/LanguageServer/LanguageServer.php +++ b/src/Psalm/Internal/LanguageServer/LanguageServer.php @@ -103,6 +103,11 @@ class LanguageServer extends Dispatcher */ protected $onchange_paths_to_analyze = []; + /** + * @var array> + */ + protected $current_issues = []; + public function __construct( ProtocolReader $reader, ProtocolWriter $writer, @@ -365,6 +370,7 @@ public function doAnalysis(): void public function emitIssues(array $uris): void { $data = IssueBuffer::clear(); + $this->current_issues = $data; foreach ($uris as $file_path => $uri) { $diagnostics = array_map( @@ -560,4 +566,14 @@ public static function uriToPath(string $uri): string return $filepath; } + + /** + * Get the value of current_issues + * + * @return array> + */ + public function getCurrentIssues(): array + { + return $this->current_issues; + } } diff --git a/src/Psalm/Internal/LanguageServer/Server/TextDocument.php b/src/Psalm/Internal/LanguageServer/Server/TextDocument.php index fecbc070cb0..b98b5161638 100644 --- a/src/Psalm/Internal/LanguageServer/Server/TextDocument.php +++ b/src/Psalm/Internal/LanguageServer/Server/TextDocument.php @@ -24,7 +24,6 @@ use Psalm\Exception\UnanalyzedFileException; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\LanguageServer\LanguageServer; -use Psalm\IssueBuffer; use UnexpectedValueException; use function array_combine; @@ -365,9 +364,15 @@ public function codeAction(TextDocumentIdentifier $textDocument, Range $range): $this->codebase->analyzer->addFilesToAnalyze( array_combine($all_file_paths_to_analyze, $all_file_paths_to_analyze) ); - $this->codebase->analyzer->analyzeFiles($this->project_analyzer, 1, false); - $issues = IssueBuffer::clear(); + try { + $this->codebase->analyzer->analyzeFiles($this->project_analyzer, 1, false); + } catch (UnexpectedValueException $e) { + error_log('codeAction errored on file ' . $file_path. ', Reason: '.$e->getMessage()); + return new Success(null); + } + + $issues = $this->server->getCurrentIssues(); if (empty($issues[$file_path])) { return new Success(null);