Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix closure to have storage bug in codeAction #7368

Merged
merged 1 commit into from Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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