@@ -196,7 +196,8 @@ async function runCppcheckOnFileXML(
196196 // Clear existing diagnostics for this file
197197 diagnosticCollection . delete ( document . uri ) ;
198198
199- const filePath = document . fileName ;
199+ // Replace backslashes (used in paths in Windows environment)
200+ const filePath = document . fileName . replaceAll ( '\\' , '/' ) ;
200201 const minSevNum = parseMinSeverity ( minSevString ) ;
201202 const standardArg = standard !== "<none>" ? `--std=${ standard } ` : "" ;
202203
@@ -218,11 +219,13 @@ async function runCppcheckOnFileXML(
218219 '--suppress=unusedFunction' ,
219220 '--suppress=missingInclude' ,
220221 '--suppress=missingIncludeSystem' ,
221- `--file-filter=${ filePath . replace ( / \\ / g , '/' ) } ` ,
222+ `--file-filter=${ filePath } ` ,
222223 standardArg ,
223224 ...extraArgsParsed ,
224225 ] . filter ( Boolean ) ;
225- proc = cp . spawn ( commandPath , args ) ;
226+ proc = cp . spawn ( commandPath , args , {
227+ cwd : path . dirname ( document . fileName ) ,
228+ } ) ;
226229 } else {
227230 const args = [
228231 '--enable=all' ,
@@ -233,9 +236,11 @@ async function runCppcheckOnFileXML(
233236 '--suppress=missingIncludeSystem' ,
234237 standardArg ,
235238 ...extraArgsParsed ,
236- filePath . replace ( / \\ / g , '/' )
239+ filePath ,
237240 ] . filter ( Boolean ) ;
238- proc = cp . spawn ( commandPath , args ) ;
241+ proc = cp . spawn ( commandPath , args , {
242+ cwd : path . dirname ( document . fileName ) ,
243+ } ) ;
239244 }
240245
241246 // if spawn fails (e.g. ENOENT or permission denied)
0 commit comments