diff --git a/src/services/filesService.ts b/src/services/filesService.ts index 8eb9196..34a93f2 100644 --- a/src/services/filesService.ts +++ b/src/services/filesService.ts @@ -1,4 +1,7 @@ import * as vscode from 'vscode'; +import logger from '../logger'; +import { CheckovResult } from '../types'; +import { formatWindowsAbsoluteFilePath, isWindows } from '../utils'; export class FilesService { private static context: vscode.ExtensionContext; @@ -7,13 +10,20 @@ export class FilesService { FilesService.context = context; } - public static async openFile(file: string, line: number = 1) { + public static async openResult(result: CheckovResult, line: number = 1) { if (line < 1) { line = 1; } if (!vscode.window.activeTextEditor) { vscode.commands.executeCommand('workbench.action.previousEditor'); } - return vscode.window.showTextDocument(vscode.Uri.file(file), { selection: new vscode.Range(line - 1, 0, line - 1, 0) }); + let filePath; + if (isWindows()) { + filePath = formatWindowsAbsoluteFilePath(result.file_abs_path); + } else { + filePath = result.file_abs_path; + } + logger.info(`Opening file at ${filePath}`); + return vscode.window.showTextDocument(vscode.Uri.file(filePath), { selection: new vscode.Range(line - 1, 0, line - 1, 0) }); } } diff --git a/src/utils/index.ts b/src/utils/index.ts index d96a991..bf2d5cf 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -24,6 +24,12 @@ export const formatWindowsFilePath = (path: string): string => { return path.replace(':', '').replace(/\\/g, '/'); }; +export const formatWindowsAbsoluteFilePath = (path: string): string => { + const splitPath = path.replace(/\\/g, '/').replace(/^\/+/g, '').split('/'); + splitPath[0] = splitPath[0].toLocaleUpperCase() + ':'; + return splitPath.join('/'); +}; + export const getOsNameAndVersion = async () => { const operatingSystem = os.type(); if ("Darwin" === operatingSystem) { diff --git a/src/views/interface/checkovResult/messages/focusString.ts b/src/views/interface/checkovResult/messages/focusString.ts index 4fa0797..abde020 100644 --- a/src/views/interface/checkovResult/messages/focusString.ts +++ b/src/views/interface/checkovResult/messages/focusString.ts @@ -1,9 +1,10 @@ import { FilesService } from '../../../../services'; +import { CheckovResult } from '../../../../types'; export class FocusString { - public static async handle({ fileAbsPath, row }: { fileAbsPath: string, row: number }) { - if (fileAbsPath && row) { - await FilesService.openFile(fileAbsPath, row); + public static async handle({ result, row }: { result: CheckovResult, row: number }) { + if (result && row) { + await FilesService.openResult(result, row); return; } diff --git a/src/views/interface/checkovResult/webviewPanel.ts b/src/views/interface/checkovResult/webviewPanel.ts index 99169ed..c039a24 100644 --- a/src/views/interface/checkovResult/webviewPanel.ts +++ b/src/views/interface/checkovResult/webviewPanel.ts @@ -309,7 +309,7 @@ export class CheckovResultWebviewPanel { private static getDataFlowItemString(dataFlow: DataFlow, result: CheckovResult): string { const splitPath = dataFlow.path.split('/'); return `