1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-03 18:17:55 +01:00

Add progress for scanning stage

This commit is contained in:
robchett 2023-11-03 10:15:48 +00:00
parent 147505c806
commit f2343ed2e1
4 changed files with 38 additions and 4 deletions

View File

@ -317,6 +317,7 @@ final class Scanner
$pool_size = 1;
}
$this->progress->expand(count($files_to_scan));
if ($pool_size > 1) {
$process_file_paths = [];
@ -355,7 +356,6 @@ final class Scanner
*/
function () {
$this->progress->debug('Collecting data from forked scanner process' . PHP_EOL);
$project_analyzer = ProjectAnalyzer::getInstance();
$codebase = $project_analyzer->getCodebase();
$statements_provider = $codebase->statements_provider;
@ -377,6 +377,9 @@ final class Scanner
'taint_data' => $codebase->taint_flow_graph,
];
},
function (): void {
$this->progress->taskDone(0);
},
);
// Wait for all tasks to complete and collect the results.
@ -427,6 +430,7 @@ final class Scanner
$i = 0;
foreach ($files_to_scan as $file_path => $_) {
$this->progress->taskDone(0);
$this->scanAPath($i, $file_path);
++$i;
}

View File

@ -22,7 +22,7 @@ class DefaultProgress extends LongProgress
public function taskDone(int $level): void
{
if ($this->number_of_tasks > self::TOO_MANY_FILES) {
if ($this->fixed_size && $this->number_of_tasks > self::TOO_MANY_FILES) {
++$this->progress;
// Source for rate limiting:

View File

@ -25,6 +25,8 @@ class LongProgress extends Progress
protected bool $print_infos = false;
protected bool $fixed_size = true;
public function __construct(bool $print_errors = true, bool $print_infos = true)
{
$this->print_errors = $print_errors;
@ -33,16 +35,19 @@ class LongProgress extends Progress
public function startScanningFiles(): void
{
$this->fixed_size = false;
$this->write('Scanning files...' . "\n");
}
public function startAnalyzingFiles(): void
{
$this->write('Analyzing files...' . "\n\n");
$this->fixed_size = true;
$this->write("\n" . 'Analyzing files...' . "\n\n");
}
public function startAlteringFiles(): void
{
$this->fixed_size = true;
$this->write('Altering files...' . "\n");
}
@ -57,8 +62,30 @@ class LongProgress extends Progress
$this->progress = 0;
}
public function expand(int $number_of_tasks): void
{
$this->number_of_tasks += $number_of_tasks;
}
public function taskDone(int $level): void
{
if ($this->number_of_tasks === null) {
throw new LogicException('Progress::start() should be called before Progress::taskDone()');
}
++$this->progress;
if (!$this->fixed_size) {
if ($this->progress == 1 || $this->progress == $this->number_of_tasks || $this->progress % 10 == 0) {
$this->write(sprintf(
"\r%s / %s?",
$this->progress,
$this->number_of_tasks,
));
}
return;
}
if ($level === 0 || ($level === 1 && !$this->print_infos) || !$this->print_errors) {
$this->write(self::doesTerminalSupportUtf8() ? '░' : '_');
} elseif ($level === 1) {
@ -67,7 +94,6 @@ class LongProgress extends Progress
$this->write('E');
}
++$this->progress;
if (($this->progress % self::NUMBER_OF_COLUMNS) !== 0) {
return;

View File

@ -46,6 +46,10 @@ abstract class Progress
{
}
public function expand(int $number_of_tasks): void
{
}
public function taskDone(int $level): void
{
}