diff --git a/src/classes/FileReader.ts b/src/classes/FileReader.ts index 51cbff2..46fec43 100644 --- a/src/classes/FileReader.ts +++ b/src/classes/FileReader.ts @@ -99,6 +99,7 @@ export class FileReader { return []; } + // TODO: Try using workspace.findFiles(...) instead of node fs methods let files = fs.readdirSync(root); let names = []; for (let i = 0; i < files.length; i++) { @@ -125,7 +126,12 @@ export class FileReader { private static readFileFromNames(uris_or_strings): Promise { return new Promise(function (resolve, reject) { let docs: FileType[] = []; - let count = 0; + // Count of successfully opened files + let openedCount = 0; + // Count of files which failed to load + let failedCount = 0; + + function totalCount() { return openedCount + failedCount; } for (let uri of uris_or_strings) { let docPrm = workspace.openTextDocument(uri); @@ -134,14 +140,23 @@ export class FileReader { if(doc) // File maybe corrupted docs.push(new FileType(doc)); - count++; + openedCount++; // Detect and end the function early - if (count == uris_or_strings.length) { + if (totalCount() == uris_or_strings.length) { resolve(docs); } }, function (reason) { - reject(reason); + // Keep going, try other files. + failedCount++; + // Detect and end the function early + if (failedCount == uris_or_strings.length) { + // All files failed to open, so we reject + reject("No file has been read successfully."); + } + else if (totalCount() == uris_or_strings.length) { + resolve(docs); + } }); } if (uris_or_strings.length == 0) diff --git a/src/types/CommandType.ts b/src/types/CommandType.ts index 3433292..4b851fa 100644 --- a/src/types/CommandType.ts +++ b/src/types/CommandType.ts @@ -45,7 +45,7 @@ export class ParseAllFilesCommand implements CommandType { let results = [], errors = []; FileReader.readProjectFiles( (files: FileType[], progress, error) => { - if (!error) { + if (files.length > 0) { files = FileFilter.filter(files); let todos = Parser.parse(files); results = results.concat(todos); @@ -53,7 +53,9 @@ export class ParseAllFilesCommand implements CommandType { StatusBarManager.getInstance().setWorking(`${WORKING_ICON} ${progress}%`, "Click to cancel"); totalFiles += todos.length; } - else { + // We could have files available, but still have an error + // because some of them failed to load. + if (error) { errors.push(error); } },