Skip to content

Commit bf9e917

Browse files
committed
Use concurrency in loading GNATcoverage report
1 parent b61d6d9 commit bf9e917

File tree

1 file changed

+53
-33
lines changed

1 file changed

+53
-33
lines changed

integration/vscode/ada/src/gnatcov.ts

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -292,40 +292,60 @@ export async function addCoverageData(run: vscode.TestRun, covDir: string) {
292292
const array = data.coverage_report.coverage_summary!.file;
293293
let done: number = 0;
294294
const totalFiles = array.length;
295-
for (const file of array) {
296-
if (token.isCancellationRequested) {
297-
throw new vscode.CancellationError();
298-
}
299-
300-
const found = await vscode.workspace.findFiles(`**/${file['@_name']!}`, null, 1);
301-
if (found.length == 0) continue;
302-
303-
const srcUri = found[0];
304-
const total = file.metric.find((m) => m['@_kind'] == 'total_lines_of_relevance')![
305-
'@_count'
306-
];
307-
const covered = file.metric.find((m) => m['@_kind'] == 'fully_covered')!['@_count'];
308-
309-
const fileReportBasename = data.coverage_report.sources!['xi:include'].find(
310-
(inc) => inc['@_href'] == `${file['@_name']!}.xml`,
311-
)!['@_href'];
312-
const fileReportPath = path.join(covDir, fileReportBasename);
313-
314-
if (covered > total) {
315-
throw Error(
316-
`Got ${covered} covered lines for a` +
317-
` total of ${total} in ${file['@_name']!}`,
318-
);
319-
}
320-
321-
const fileCov = new GnatcovFileCoverage(fileReportPath, srcUri, { covered, total });
322-
run.addCoverage(fileCov);
295+
const fileCovs = (
296+
await Promise.all(
297+
array.map(async (file) => {
298+
if (token.isCancellationRequested) {
299+
throw new vscode.CancellationError();
300+
}
323301

324-
progress.report({
325-
message: `${++done} / ${totalFiles} source files`,
326-
increment: (100 * 1) / totalFiles,
327-
});
328-
}
302+
const found = await vscode.workspace.findFiles(
303+
`**/${file['@_name']!}`,
304+
null,
305+
1,
306+
);
307+
if (found.length == 0) {
308+
return undefined;
309+
}
310+
311+
const srcUri = found[0];
312+
const total = file.metric.find(
313+
(m) => m['@_kind'] == 'total_lines_of_relevance',
314+
)!['@_count'];
315+
const covered = file.metric.find((m) => m['@_kind'] == 'fully_covered')![
316+
'@_count'
317+
];
318+
319+
const fileReportBasename = data.coverage_report.sources!['xi:include'].find(
320+
(inc) => inc['@_href'] == `${file['@_name']!}.xml`,
321+
)!['@_href'];
322+
const fileReportPath = path.join(covDir, fileReportBasename);
323+
324+
if (covered > total) {
325+
throw Error(
326+
`Got ${covered} covered lines for a` +
327+
` total of ${total} in ${file['@_name']!}`,
328+
);
329+
}
330+
331+
const fileCov = new GnatcovFileCoverage(fileReportPath, srcUri, {
332+
covered,
333+
total,
334+
});
335+
336+
progress.report({
337+
message: `${++done} / ${totalFiles} source files`,
338+
increment: (100 * 1) / totalFiles,
339+
});
340+
341+
return fileCov;
342+
}),
343+
)
344+
).filter((v) => !!v);
345+
fileCovs.map((fileCov) => {
346+
run.addCoverage(fileCov);
347+
});
348+
await Promise.all(fileCovs);
329349
},
330350
);
331351
}

0 commit comments

Comments
 (0)