From 062954dd1825cf1a807f21b0bc8adf2c4e211150 Mon Sep 17 00:00:00 2001 From: davidramnero Date: Sat, 13 Dec 2025 14:37:28 +0100 Subject: [PATCH] fix #27 include headers problem and issue with checked file path comparision in windows --- src/extension.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 65b6144..60a08a5 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -179,7 +179,8 @@ async function runCppcheckOnFileXML( // Clear existing diagnostics for this file diagnosticCollection.delete(document.uri); - const filePath = document.fileName; + // Replace backslashes (used in paths in Windows environment) + const filePath = document.fileName.replaceAll('\\', '/'); const minSevNum = parseMinSeverity(minSevString); const standardArg = standard !== "" ? `--std=${standard}` : ""; @@ -201,11 +202,13 @@ async function runCppcheckOnFileXML( '--suppress=unusedFunction', '--suppress=missingInclude', '--suppress=missingIncludeSystem', - `--file-filter=${filePath.replace(/\\/g, '/')}`, + `--file-filter=${filePath}`, standardArg, ...extraArgsParsed, ].filter(Boolean); - proc = cp.spawn(commandPath, args); + proc = cp.spawn(commandPath, args, { + cwd: path.dirname(document.fileName), + }); } else { const args = [ '--enable=all', @@ -216,9 +219,11 @@ async function runCppcheckOnFileXML( '--suppress=missingIncludeSystem', standardArg, ...extraArgsParsed, - filePath.replace(/\\/g, '/') + filePath, ].filter(Boolean); - proc = cp.spawn(commandPath, args); + proc = cp.spawn(commandPath, args, { + cwd: path.dirname(document.fileName), + }); } // if spawn fails (e.g. ENOENT or permission denied)