@@ -266,25 +266,29 @@ async function runCppcheckOnFileXML(
266266
267267 const errors = result . results ?. errors ?. [ 0 ] ?. error || [ ] ;
268268 const diagnostics : vscode . Diagnostic [ ] = [ ] ;
269-
270269 for ( const e of errors ) {
270+ const isCriticalError = criticalWarningTypes . includes ( e . $ . id ) ;
271271 const locations = e . location || [ ] ;
272272 if ( ! locations . length ) {
273273 continue ;
274274 }
275275
276276 const mainLoc = locations [ locations . length - 1 ] . $ ;
277- console . log ( 'error id ' , e . $ . id , 'error' , e ) ;
277+
278278 // If main location is not current file, then skip displaying warning unless it is critical
279- if ( ! filePath . endsWith ( mainLoc . file ) && ! criticalWarningTypes . includes ( e . $ . id ) ) {
279+ if ( ! isCriticalError && ! filePath . endsWith ( mainLoc . file ) ) {
280280 continue ;
281281 }
282282
283283 // Cppcheck line number is 1-indexed, while VS Code uses 0-indexing
284- const line = Number ( mainLoc . line ) - 1 ;
284+ let line = Number ( mainLoc . line ) - 1 ;
285285 // Invalid line number usually means non-analysis output
286286 if ( isNaN ( line ) || line < 0 || line >= document . lineCount ) {
287- continue ;
287+ if ( isCriticalError ) {
288+ line = 0 ;
289+ } else {
290+ continue ;
291+ }
288292 }
289293
290294 // Cppcheck col number is 1-indexed, while VS Code uses 0-indexing
@@ -294,15 +298,14 @@ async function runCppcheckOnFileXML(
294298 }
295299
296300 const severity = parseSeverity ( e . $ . severity ) ;
297- if ( severityToNumber ( severity ) < minSevNum ) {
301+ if ( ! isCriticalError && severityToNumber ( severity ) < minSevNum ) {
298302 continue ;
299303 }
300304
301305 const range = new vscode . Range ( line , col , line , document . lineAt ( line ) . text . length ) ;
302306 const diagnostic = new vscode . Diagnostic ( range , e . $ . msg , severity ) ;
303307 diagnostic . source = "cppcheck" ;
304308 diagnostic . code = e . $ . id ;
305-
306309 // Related Information
307310 const relatedInfos : vscode . DiagnosticRelatedInformation [ ] = [ ] ;
308311 for ( let i = 1 ; i <= locations . length ; i ++ ) {
0 commit comments