@@ -179,7 +179,8 @@ async function runCppcheckOnFileXML(
179179 // Clear existing diagnostics for this file
180180 diagnosticCollection . delete ( document . uri ) ;
181181
182- const filePath = document . fileName ;
182+ // Replace backslashes (used in paths in Windows environment)
183+ const filePath = document . fileName . replaceAll ( '\\' , '/' ) ;
183184 const minSevNum = parseMinSeverity ( minSevString ) ;
184185 const standardArg = standard !== "<none>" ? `--std=${ standard } ` : "" ;
185186
@@ -201,11 +202,13 @@ async function runCppcheckOnFileXML(
201202 '--suppress=unusedFunction' ,
202203 '--suppress=missingInclude' ,
203204 '--suppress=missingIncludeSystem' ,
204- `--file-filter=${ filePath . replace ( / \\ / g , '/' ) } ` ,
205+ `--file-filter=${ filePath } ` ,
205206 standardArg ,
206207 ...extraArgsParsed ,
207208 ] . filter ( Boolean ) ;
208- proc = cp . spawn ( commandPath , args ) ;
209+ proc = cp . spawn ( commandPath , args , {
210+ cwd : path . dirname ( document . fileName ) ,
211+ } ) ;
209212 } else {
210213 const args = [
211214 '--enable=all' ,
@@ -216,9 +219,11 @@ async function runCppcheckOnFileXML(
216219 '--suppress=missingIncludeSystem' ,
217220 standardArg ,
218221 ...extraArgsParsed ,
219- filePath . replace ( / \\ / g , '/' )
222+ filePath ,
220223 ] . filter ( Boolean ) ;
221- proc = cp . spawn ( commandPath , args ) ;
224+ proc = cp . spawn ( commandPath , args , {
225+ cwd : path . dirname ( document . fileName ) ,
226+ } ) ;
222227 }
223228
224229 // if spawn fails (e.g. ENOENT or permission denied)
0 commit comments