diff --git a/vscode/src/cliConfig.ts b/vscode/src/cliConfig.ts index ddd2b90..9d2cbbf 100644 --- a/vscode/src/cliConfig.ts +++ b/vscode/src/cliConfig.ts @@ -70,6 +70,15 @@ export async function usedSegments(): Promise { */ export async function activeSegments(): Promise { const modality = toolPath("modality"); + + const segmentUseRes = await execFile(modality, ["segment", "use", "--format", "json"], { encoding: "utf8" }); + const segmentUseJson = JSON.parse(segmentUseRes.stdout); + if (segmentUseJson == "All") { + const segmentListRes = await execFile(modality, ["segment", "list", "--detailed", "--format", "json"], { encoding: "utf8" }); + const mds = JSON.parse(segmentListRes.stdout).segments as api.WorkspaceSegmentMetadata[]; + return mds; + } + try { const res = await execFile(modality, ["segment", "inspect", "--format", "json"], { encoding: "utf8" }); return JSON.parse(res.stdout).segments as api.WorkspaceSegmentMetadata[]; diff --git a/vscode/src/mutators.ts b/vscode/src/mutators.ts index a75ca17..1d4feed 100644 --- a/vscode/src/mutators.ts +++ b/vscode/src/mutators.ts @@ -87,6 +87,7 @@ export class MutatorsTreeDataProvider implements vscode.TreeDataProvider { this.createMutation(itemData); }), + this.wss.onDidChangeActiveWorkspace(() => this.refresh()), this.wss.onDidChangeUsedSegments(() => this.refresh()) ); @@ -94,6 +95,8 @@ export class MutatorsTreeDataProvider implements vscode.TreeDataProvider 0 && coverage.coverage_aggregates.n_behaviors_executed > 0) { - percentageBehaviorsCovered = 100.0 - coverage.coverage_aggregates.percentage_behaviors_vacuous; + const conform = toolPath("conform"); + var args = ["spec", "coverage", "--format", "html"]; + + var segmentationRule = undefined; + for (const seg of params.segmentIds) { + if (segmentationRule) { + if (seg.rule_name != segmentationRule) { + throw new Error("Cannot create a coverage report for segments originating from different segmentation rules"); + } + } else { + segmentationRule = seg.rule_name; + } + args.push("--segment") + args.push(seg.segment_name) } - const html = this.template({ - designUnit: 8, - borderWidth: 1, - cornerRadius: 0, - header: { - percentageSpecsExecuted: coverage.coverage_aggregates.percentage_specs_executed, - percentageSpecsPassing: coverage.coverage_aggregates.percentage_specs_passing, - percentageBehaviorsCovered, - percentageCasesEverMatched: coverage.coverage_aggregates.percentage_cases_ever_matched, - }, - specs: coverage.spec_coverages.map(specViewModel).sort((a, b) => a.name.localeCompare(b.name)), - params, - percentageBehaviorsCovered, - }); + if (segmentationRule) { + args.push("--segmentation-rule", segmentationRule); + } + + var specFilters = []; + if (params.specNames) { + for (const name of params.specNames) { + specFilters.push(`_.name='${name}'`) + } + } + + if (params.specVersions) { + for (const version of params.specVersions) { + specFilters.push(`_.spec.version_id = "${version}"`) + } + } + + // TODO what about params.specResultIds? + if (specFilters.length > 0) { + args.push("--spec-filter"); + args.push(specFilters.join(" or ")); + } + + const coverageRes = await execFile(conform, args, { encoding: "utf8" }); + + // const coverage = await this.apiClient + // .segment(params.segmentId) + // .specCoverage( + // params.specNames, + // params.specVersions, + // params.specResultIds, + // params.specFilter, + // params.caseFilter + // ); + + // let percentageBehaviorsCovered = 0.0; + // if (coverage.coverage_aggregates.n_behaviors > 0 && coverage.coverage_aggregates.n_behaviors_executed > 0) { + // percentageBehaviorsCovered = 100.0 - coverage.coverage_aggregates.percentage_behaviors_vacuous; + // } + + // const html = this.template({ + // designUnit: 8, + // borderWidth: 1, + // cornerRadius: 0, + // header: { + // percentageSpecsExecuted: coverage.coverage_aggregates.percentage_specs_executed, + // percentageSpecsPassing: coverage.coverage_aggregates.percentage_specs_passing, + // percentageBehaviorsCovered, + // percentageCasesEverMatched: coverage.coverage_aggregates.percentage_cases_ever_matched, + // }, + // specs: coverage.spec_coverages.map(specViewModel).sort((a, b) => a.name.localeCompare(b.name)), + // params, + // percentageBehaviorsCovered, + // }); + const panel = vscode.window.createWebviewPanel( "auxon.specCoverageView", - `Coverage Report: ${params.segmentId.segment_name}`, + "Coverage Report", // TODO formatted version + //`Coverage Report: ${params.segmentId.segment_name}`, vscode.ViewColumn.One, {} ); - panel.webview.html = html; + panel.webview.html = coverageRes.stdout; } } diff --git a/vscode/src/specs.ts b/vscode/src/specs.ts index 8fcde2c..1dac615 100644 --- a/vscode/src/specs.ts +++ b/vscode/src/specs.ts @@ -247,14 +247,12 @@ export class SpecsTreeDataProvider implements vscode.TreeDataProvider 1) { - throw new Error("Can't currently show coverage for multiple segments at once"); - } else if (activeSegments.length == 0) { + if (activeSegments.length == 0) { throw new Error("No segments are active"); } const params: specCoverage.SpecCoverageParams = { - segmentId: activeSegments[0].id, + segmentIds: activeSegments.map(seg => seg.id) }; // consider the clicked item to be part of the selection for diff --git a/vscode/src/workspaceState.ts b/vscode/src/workspaceState.ts index 0a086de..e3819c2 100644 --- a/vscode/src/workspaceState.ts +++ b/vscode/src/workspaceState.ts @@ -23,7 +23,8 @@ export class WorkspaceAndSegmentState { public activeWorkspaceName: string, public activeWorkspaceVersionId: string, public usedSegmentConfig: cliConfig.ContextSegment, - public activeSegments: ActiveSegments + public activeSegments: ActiveSegments, + public mutatorGroupingAttrs: string[], ) {} static async create(apiClient: api.Client): Promise { @@ -96,6 +97,7 @@ export class WorkspaceAndSegmentState { } } } + if (resetToLatestWorkspace) { vscode.window.showWarningMessage(`Active segment is for a different workspace; reverting to latest.`); await _useLatestSegment(); @@ -106,12 +108,16 @@ export class WorkspaceAndSegmentState { }; } + let ws_def = await apiClient.workspace(activeWorkspaceVersionId).definition(); + let mutatorGroupingAttrs = ws_def.mutator_grouping_attrs; + return new WorkspaceAndSegmentState( apiClient, activeWorkspaceName, activeWorkspaceVersionId, usedSegmentConfig, - activeSegments + activeSegments, + mutatorGroupingAttrs ); }