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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Counting files before error message #9087

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/pyright-internal/src/analyzer/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1323,15 +1323,18 @@ export class AnalyzerService {
const results: Uri[] = [];
const startTime = Date.now();
const longOperationLimitInSec = 10;
const nFilesToSuggestSubfolder = 50;

let loggedLongOperationError = false;
let nFilesVisited = 0;

const visitDirectoryUnchecked = (absolutePath: Uri, includeRegExp: RegExp, hasDirectoryWildcard: boolean) => {
if (!loggedLongOperationError) {
const secondsSinceStart = (Date.now() - startTime) * 0.001;

// If this is taking a long time, log an error to help the user
// diagnose and mitigate the problem.
if (secondsSinceStart >= longOperationLimitInSec) {
if (secondsSinceStart >= longOperationLimitInSec && nFilesVisited >= nFilesToSuggestSubfolder) {
this._console.error(
`Enumeration of workspace source files is taking longer than ${longOperationLimitInSec} seconds.\n` +
'This may be because:\n' +
Expand Down Expand Up @@ -1368,6 +1371,7 @@ export class AnalyzerService {

for (const filePath of files) {
if (FileSpec.matchIncludeFileSpec(includeRegExp, exclude, filePath)) {
nFilesVisited++;
results.push(filePath);
}
}
Expand Down
Loading