diff --git a/package.json b/package.json index 625b0f611..1973c61d8 100644 --- a/package.json +++ b/package.json @@ -346,6 +346,19 @@ } } }, + { + "title": "Code Coverage", + "properties": { + "swift.excludeFromCodeCoverage": { + "description": "A list of paths to exclude from code coverage reports. Paths can be absolute or relative to the workspace root.", + "type": "array", + "items": { + "type": "string" + }, + "default": [] + } + } + }, { "title": "User Interface", "properties": { diff --git a/src/configuration.ts b/src/configuration.ts index 6ab2c52e7..e80e7a78f 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -154,7 +154,12 @@ const configuration = { }, }; }, - + /** Files and directories to exclude from the code coverage. */ + get excludeFromCodeCoverage(): string[] { + return vscode.workspace + .getConfiguration("swift") + .get("excludeFromCodeCoverage", []); + }, /** Files and directories to exclude from the Package Dependencies view. */ get excludePathsFromPackageDependencies(): string[] { return vscode.workspace diff --git a/src/coverage/LcovResults.ts b/src/coverage/LcovResults.ts index 95108ee48..7878180a6 100644 --- a/src/coverage/LcovResults.ts +++ b/src/coverage/LcovResults.ts @@ -198,11 +198,17 @@ export class TestCoverage { private ignoredFilenamesRegex(): string { const basePath = this.folderContext.folder.path; const buildFolder = path.join(basePath, ".build"); + const snippetsFolder = path.join(basePath, "Snippets"); + const pluginsFolder = path.join(basePath, "Plugins"); const testTargets = this.folderContext.swiftPackage .getTargets(TargetType.test) .map(target => path.join(basePath, target.path)); - return [buildFolder, ...testTargets].join("|"); + const excluded = configuration.excludeFromCodeCoverage.map(target => + path.isAbsolute(target) ? target : path.join(basePath, target) + ); + + return [buildFolder, snippetsFolder, pluginsFolder, ...testTargets, ...excluded].join("|"); } private async loadLcov(lcovContents: string): Promise {