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:
parent
147505c806
commit
f2343ed2e1
@ -317,6 +317,7 @@ final class Scanner
|
|||||||
$pool_size = 1;
|
$pool_size = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->progress->expand(count($files_to_scan));
|
||||||
if ($pool_size > 1) {
|
if ($pool_size > 1) {
|
||||||
$process_file_paths = [];
|
$process_file_paths = [];
|
||||||
|
|
||||||
@ -355,7 +356,6 @@ final class Scanner
|
|||||||
*/
|
*/
|
||||||
function () {
|
function () {
|
||||||
$this->progress->debug('Collecting data from forked scanner process' . PHP_EOL);
|
$this->progress->debug('Collecting data from forked scanner process' . PHP_EOL);
|
||||||
|
|
||||||
$project_analyzer = ProjectAnalyzer::getInstance();
|
$project_analyzer = ProjectAnalyzer::getInstance();
|
||||||
$codebase = $project_analyzer->getCodebase();
|
$codebase = $project_analyzer->getCodebase();
|
||||||
$statements_provider = $codebase->statements_provider;
|
$statements_provider = $codebase->statements_provider;
|
||||||
@ -377,6 +377,9 @@ final class Scanner
|
|||||||
'taint_data' => $codebase->taint_flow_graph,
|
'taint_data' => $codebase->taint_flow_graph,
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
function (): void {
|
||||||
|
$this->progress->taskDone(0);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// Wait for all tasks to complete and collect the results.
|
// Wait for all tasks to complete and collect the results.
|
||||||
@ -427,6 +430,7 @@ final class Scanner
|
|||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
foreach ($files_to_scan as $file_path => $_) {
|
foreach ($files_to_scan as $file_path => $_) {
|
||||||
|
$this->progress->taskDone(0);
|
||||||
$this->scanAPath($i, $file_path);
|
$this->scanAPath($i, $file_path);
|
||||||
++$i;
|
++$i;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ class DefaultProgress extends LongProgress
|
|||||||
|
|
||||||
public function taskDone(int $level): void
|
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;
|
++$this->progress;
|
||||||
|
|
||||||
// Source for rate limiting:
|
// Source for rate limiting:
|
||||||
|
@ -25,6 +25,8 @@ class LongProgress extends Progress
|
|||||||
|
|
||||||
protected bool $print_infos = false;
|
protected bool $print_infos = false;
|
||||||
|
|
||||||
|
protected bool $fixed_size = true;
|
||||||
|
|
||||||
public function __construct(bool $print_errors = true, bool $print_infos = true)
|
public function __construct(bool $print_errors = true, bool $print_infos = true)
|
||||||
{
|
{
|
||||||
$this->print_errors = $print_errors;
|
$this->print_errors = $print_errors;
|
||||||
@ -33,16 +35,19 @@ class LongProgress extends Progress
|
|||||||
|
|
||||||
public function startScanningFiles(): void
|
public function startScanningFiles(): void
|
||||||
{
|
{
|
||||||
|
$this->fixed_size = false;
|
||||||
$this->write('Scanning files...' . "\n");
|
$this->write('Scanning files...' . "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function startAnalyzingFiles(): void
|
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
|
public function startAlteringFiles(): void
|
||||||
{
|
{
|
||||||
|
$this->fixed_size = true;
|
||||||
$this->write('Altering files...' . "\n");
|
$this->write('Altering files...' . "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,8 +62,30 @@ class LongProgress extends Progress
|
|||||||
$this->progress = 0;
|
$this->progress = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function expand(int $number_of_tasks): void
|
||||||
|
{
|
||||||
|
$this->number_of_tasks += $number_of_tasks;
|
||||||
|
}
|
||||||
|
|
||||||
public function taskDone(int $level): void
|
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) {
|
if ($level === 0 || ($level === 1 && !$this->print_infos) || !$this->print_errors) {
|
||||||
$this->write(self::doesTerminalSupportUtf8() ? '░' : '_');
|
$this->write(self::doesTerminalSupportUtf8() ? '░' : '_');
|
||||||
} elseif ($level === 1) {
|
} elseif ($level === 1) {
|
||||||
@ -67,7 +94,6 @@ class LongProgress extends Progress
|
|||||||
$this->write('E');
|
$this->write('E');
|
||||||
}
|
}
|
||||||
|
|
||||||
++$this->progress;
|
|
||||||
|
|
||||||
if (($this->progress % self::NUMBER_OF_COLUMNS) !== 0) {
|
if (($this->progress % self::NUMBER_OF_COLUMNS) !== 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -46,6 +46,10 @@ abstract class Progress
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function expand(int $number_of_tasks): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public function taskDone(int $level): void
|
public function taskDone(int $level): void
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user