Skip to content

Commit

Permalink
CM-35347 - Use relative paths in the tree view
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshalX committed May 6, 2024
1 parent 968d70b commit d5ad9a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/providers/tree-view/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {AnyDetection, IacDetection, SastDetection, ScaDetection, SecretDetection
import {FileScanResult} from './provider';
import {SeverityFirstLetter, TreeView, TreeViewDisplayedData} from './types';
import {ScanType, SEVERITY_PRIORITIES} from '../../constants';
import {cliService} from '../../services/CliService';

interface RefreshTreeViewDataArgs {
detections: AnyDetection[];
Expand All @@ -27,11 +28,14 @@ export function refreshTreeViewData(
return;
}

const projectRoot = cliService.getProjectRootDirectory();

const {provider} = treeView;
const affectedFiles: FileScanResult[] = [];
const detectionsMapped = mapDetectionsByFileName(detections, scanType);
detectionsMapped.forEach((vulnerabilities, fullFilePath) => {
affectedFiles.push(new FileScanResult(fullFilePath, fullFilePath, vulnerabilities));
const projectRelativePath = path.relative(projectRoot, fullFilePath);
affectedFiles.push(new FileScanResult(projectRelativePath, fullFilePath, vulnerabilities));
});
provider.refresh(affectedFiles, scanType);
}
Expand Down
6 changes: 5 additions & 1 deletion src/services/scanners/IacScanner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from 'vscode';
import * as path from 'path';
import {extensionOutput} from '../../logging/extension-output';
import {cliWrapper} from '../../cli-wrapper/cli-wrapper';
import statusBar from '../../utils/status-bar';
Expand Down Expand Up @@ -162,8 +163,11 @@ const detectionsToDiagnostics = async (

let message = `Severity: ${detection.severity}\n`;
message += `Description: ${detection.message}\n`;

message += `IaC Provider: ${detection.detection_details.infra_provider}\n`;
message += `In file: ${detection.detection_details.file_name}\n`;

const fileName = path.basename(detection.detection_details.file_name);
message += `In file: ${fileName}\n`;

const diagnostic = new vscode.Diagnostic(
document.lineAt(detection_details.line_in_file - 1).range,
Expand Down

0 comments on commit d5ad9a6

Please sign in to comment.