diff --git a/src/extension.ts b/src/extension.ts index 06269a2..047b2d0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -5,7 +5,7 @@ import * as xml2js from 'xml2js'; import { documentationLinkMap } from './util/documentation'; import { runCommand } from './util/scripts'; -import { resolvePath, findWorkspaceRoot } from './util/path'; +import { looksLikePath, resolvePath, findWorkspaceRoot } from './util/path'; enum SeverityNumber { Info = 0, @@ -30,6 +30,14 @@ const criticalWarningTypes = [ 'unknownMacro' ]; +const pathVariableArgs = [ + '--project', + '--addon', + '--suppressions-list', + '--include', + '--rule-file', +]; + function parseSeverity(str: string): vscode.DiagnosticSeverity { const lower = str.toLowerCase(); if (lower.includes("error")) { @@ -187,7 +195,9 @@ async function runCppcheckOnFileXML( // Resolve paths for arguments where applicable const argsParsed = processedArgs.split(" ").map((arg) => { - if (arg.startsWith('--project')) { + const isPathArgument = pathVariableArgs.some(a => arg.startsWith(a)); + // Some arguments such as addon may be either a path or the name of a built in addon + if (isPathArgument && looksLikePath(arg)) { const splitArg = arg.split('='); return `${splitArg[0]}=${resolvePath(splitArg[1])}`; } diff --git a/src/util/path.ts b/src/util/path.ts index fca6082..08602e9 100644 --- a/src/util/path.ts +++ b/src/util/path.ts @@ -2,6 +2,18 @@ import * as path from "path"; import * as os from "os"; import * as vscode from 'vscode'; +export function looksLikePath(arg: string): boolean { + if ( + arg.includes('/') + || arg.includes('\\') + || arg.startsWith('.') + || /\.[^/\\]+$/.test(arg) // filename with extension + ) { + return true; + } + return false; +} + export function findWorkspaceRoot(): string { const folders = vscode.workspace.workspaceFolders; const workspaceRoot = folders && folders.length > 0