Skip to content

Commit

Permalink
Merge pull request #7368 from tm1000/bugfix/crash-in-codeAction-4x
Browse files Browse the repository at this point in the history
Fix closure to have storage bug in codeAction
  • Loading branch information
orklah committed Jan 11, 2022
2 parents af37af7 + 0eb00e8 commit 00ab5b7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/Psalm/Internal/LanguageServer/LanguageServer.php
Expand Up @@ -103,6 +103,11 @@ class LanguageServer extends Dispatcher
*/
protected $onchange_paths_to_analyze = [];

/**
* @var array<string, list<IssueData>>
*/
protected $current_issues = [];

public function __construct(
ProtocolReader $reader,
ProtocolWriter $writer,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -560,4 +566,14 @@ public static function uriToPath(string $uri): string

return $filepath;
}

/**
* Get the value of current_issues
*
* @return array<string, list<IssueData>>
*/
public function getCurrentIssues(): array
{
return $this->current_issues;
}
}
11 changes: 8 additions & 3 deletions src/Psalm/Internal/LanguageServer/Server/TextDocument.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 00ab5b7

Please sign in to comment.