Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")) {
Expand Down Expand Up @@ -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])}`;
}
Expand Down
12 changes: 12 additions & 0 deletions src/util/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading