Skip to content

Commit 2d1aaf0

Browse files
authored
Fixed a recent regression that broke the "--threads" option in the CLI. (#10812)
1 parent 7b90e9e commit 2d1aaf0

File tree

2 files changed

+48
-46
lines changed

2 files changed

+48
-46
lines changed

packages/pyright-internal/src/analyzer/service.ts

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,52 @@ export class AnalyzerService {
505505
this._backgroundAnalysisProgram.restart();
506506
}
507507

508+
// Attempts to make progress on source file enumeration if there is an active
509+
// source enumerator associated with the service. Returns true if complete.
510+
enumerateSourceFiles(maxSourceEnumeratorTime: number): boolean {
511+
// If there is no active source enumerator, we're done.
512+
if (!this._sourceEnumerator) {
513+
return true;
514+
}
515+
516+
let fileMap: Map<string, Uri>;
517+
518+
if (this._executionRootUri.isEmpty()) {
519+
// No user files for default workspace.
520+
fileMap = new Map<string, Uri>();
521+
} else {
522+
const enumerator = this._sourceEnumerator;
523+
const enumResults = timingStats.findFilesTime.timeOperation(() =>
524+
enumerator.enumerate(maxSourceEnumeratorTime)
525+
);
526+
527+
if (!enumResults.isComplete) {
528+
return false;
529+
}
530+
531+
// Update the config options to include the auto-excluded directories.
532+
const excludes = this.options.configOptions?.exclude;
533+
if (enumResults.autoExcludedDirs && excludes) {
534+
enumResults.autoExcludedDirs.forEach((excludedDir) => {
535+
if (!FileSpec.isInPath(excludedDir, excludes)) {
536+
excludes.push(getFileSpec(this._configOptions.projectRoot, `${excludedDir}/**`));
537+
}
538+
});
539+
this._backgroundAnalysisProgram.setConfigOptions(this._configOptions);
540+
}
541+
542+
fileMap = enumResults.matches;
543+
544+
const fileList = this._getTrackedFileList(fileMap);
545+
this._backgroundAnalysisProgram.setTrackedFiles(fileList);
546+
547+
// Source file enumeration is complete. Proceed with analysis.
548+
this._sourceEnumerator = undefined;
549+
}
550+
551+
return true;
552+
}
553+
508554
protected runAnalysis(token: CancellationToken) {
509555
// In pull diagnostics mode, the service doesn't perform analysis on its own.
510556
// Instead the client deliberately asks for diagnostics on a file-by-file basis.
@@ -574,52 +620,6 @@ export class AnalyzerService {
574620
}, timeUntilNextAnalysisInMs);
575621
}
576622

577-
// Attempts to make progress on source file enumeration if there is an active
578-
// source enumerator associated with the service. Returns true if complete.
579-
protected enumerateSourceFiles(maxSourceEnumeratorTime: number): boolean {
580-
// If there is no active source enumerator, we're done.
581-
if (!this._sourceEnumerator) {
582-
return true;
583-
}
584-
585-
let fileMap: Map<string, Uri>;
586-
587-
if (this._executionRootUri.isEmpty()) {
588-
// No user files for default workspace.
589-
fileMap = new Map<string, Uri>();
590-
} else {
591-
const enumerator = this._sourceEnumerator;
592-
const enumResults = timingStats.findFilesTime.timeOperation(() =>
593-
enumerator.enumerate(maxSourceEnumeratorTime)
594-
);
595-
596-
if (!enumResults.isComplete) {
597-
return false;
598-
}
599-
600-
// Update the config options to include the auto-excluded directories.
601-
const excludes = this.options.configOptions?.exclude;
602-
if (enumResults.autoExcludedDirs && excludes) {
603-
enumResults.autoExcludedDirs.forEach((excludedDir) => {
604-
if (!FileSpec.isInPath(excludedDir, excludes)) {
605-
excludes.push(getFileSpec(this._configOptions.projectRoot, `${excludedDir}/**`));
606-
}
607-
});
608-
this._backgroundAnalysisProgram.setConfigOptions(this._configOptions);
609-
}
610-
611-
fileMap = enumResults.matches;
612-
613-
const fileList = this._getTrackedFileList(fileMap);
614-
this._backgroundAnalysisProgram.setTrackedFiles(fileList);
615-
616-
// Source file enumeration is complete. Proceed with analysis.
617-
this._sourceEnumerator = undefined;
618-
}
619-
620-
return true;
621-
}
622-
623623
protected applyConfigOptions(host: Host) {
624624
// Indicate that we are about to reanalyze because of this config change.
625625
if (this.options.onInvalidated) {

packages/pyright-internal/src/pyright.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ async function runSingleThreaded(
545545

546546
// This will trigger the analyzer.
547547
service.setOptions(options);
548+
service.enumerateSourceFiles(0);
548549

549550
return await exitStatus.promise;
550551
}
@@ -568,6 +569,7 @@ async function runMultiThreaded(
568569

569570
// This will trigger discovery of files in the project.
570571
service.setOptions(options);
572+
service.enumerateSourceFiles(0);
571573
const program = service.backgroundAnalysisProgram.program;
572574

573575
// Get the list of "tracked" source files -- those that will be type checked.

0 commit comments

Comments
 (0)