1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #3024 - replay errors in --diff --diff-methods mode

This commit is contained in:
Brown 2020-03-26 14:22:06 -04:00
parent 971ae50bea
commit 4ced26bec2
4 changed files with 33 additions and 8 deletions

View File

@ -465,7 +465,7 @@ class Codebase
public function addFilesToAnalyze(array $files_to_analyze)
{
$this->scanner->addFilesToDeepScan($files_to_analyze);
$this->analyzer->addFiles($files_to_analyze);
$this->analyzer->addFilesToAnalyze($files_to_analyze);
}
/**

View File

@ -487,7 +487,7 @@ class ProjectAnalyzer
|| $deleted_files === null
|| count($diff_files) > 200
) {
$this->codebase->analyzer->addFiles($this->project_files);
$this->codebase->analyzer->addFilesToAnalyze($this->project_files);
$this->config->initializePlugins($this);
@ -498,6 +498,8 @@ class ProjectAnalyzer
$this->progress->debug(count($diff_files) . ' changed files: ' . "\n");
$this->progress->debug(' ' . implode("\n ", $diff_files) . "\n");
$this->codebase->analyzer->addFilesToShowResults($this->project_files);
if ($diff_files || $this->codebase->find_unused_code) {
$file_list = $this->getReferencedFilesFromDiff($diff_files);

View File

@ -113,6 +113,14 @@ class Analyzer
*/
private $files_to_analyze = [];
/**
* We can show analysis results on more files than we analyze
* because the results can be cached
*
* @var array<string, string>
*/
private $files_with_analysis_results = [];
/**
* We may update fewer files than we analyse (i.e. for dead code detection)
*
@ -167,9 +175,20 @@ class Analyzer
*
* @return void
*/
public function addFiles(array $files_to_analyze)
public function addFilesToAnalyze(array $files_to_analyze)
{
$this->files_to_analyze += $files_to_analyze;
$this->files_with_analysis_results += $files_to_analyze;
}
/**
* @param array<string, string> $files_to_analyze
*
* @return void
*/
public function addFilesToShowResults(array $files_to_analyze)
{
$this->files_with_analysis_results += $files_to_analyze;
}
/**
@ -189,7 +208,7 @@ class Analyzer
*/
public function canReportIssues($file_path)
{
return isset($this->files_to_analyze[$file_path]);
return isset($this->files_with_analysis_results[$file_path]);
}
/**
@ -576,9 +595,7 @@ class Analyzer
{
$codebase = $project_analyzer->getCodebase();
if ($codebase->diff_methods
&& (!$codebase->collect_references || $codebase->server_mode)
) {
if ($codebase->diff_methods) {
$this->analyzed_methods = $codebase->file_reference_provider->getAnalyzedMethods();
$this->existing_issues = $codebase->file_reference_provider->getExistingIssues();
$file_maps = $codebase->file_reference_provider->getFileMaps();
@ -771,6 +788,12 @@ class Analyzer
}
}
foreach (array_diff_key($this->files_with_analysis_results, $this->files_to_analyze) as $file_path) {
if (isset($this->existing_issues[$file_path])) {
IssueBuffer::addIssues([$file_path => $this->existing_issues[$file_path]]);
}
}
$method_references_to_class_members = array_filter(
$method_references_to_class_members
);

View File

@ -308,7 +308,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
}
$all_file_paths_to_analyze = array_keys($all_files_to_analyze);
$codebase->analyzer->addFiles(array_combine($all_file_paths_to_analyze, $all_file_paths_to_analyze));
$codebase->analyzer->addFilesToAnalyze(array_combine($all_file_paths_to_analyze, $all_file_paths_to_analyze));
$codebase->analyzer->analyzeFiles($this->project_analyzer, 1, false);
$this->emitIssues($all_files_to_analyze);