@@ -9,8 +9,8 @@ import { looksLikePath, resolvePath, findWorkspaceRoot } from './util/path';
99
1010// To keep track of document changes we save hashed versions of their content to this record
1111let documentHashMemory : Record < string , string > = { } ;
12- // To keep track of header warnings created from analysis of source file we save their relations to headerSourceFileRelationMap
13- let headerSourceFileRelationMap : Record < string , Set < string > > = { } ;
12+ // To keep track of warnings for files created from analysis of other files we save their relations to fileRelationMap
13+ let fileRelationMap : Record < string , Set < string > > = { } ;
1414
1515let previewAnalysisTimer : NodeJS . Timeout | undefined ;
1616let previewedDocument : vscode . TextDocument | undefined ;
@@ -117,14 +117,15 @@ export async function activate(context: vscode.ExtensionContext) {
117117 context . subscriptions . push ( diagnosticCollection ) ;
118118
119119 function clearDiagnosticForDoc ( doc : vscode . TextDocument ) : void {
120- diagnosticCollection . delete ( doc . uri ) ;
121- // If we are displaying header errors generated from analysing doc (and only from this), clear these
122- for ( const headerUri of Object . keys ( headerSourceFileRelationMap ) ) {
123- if ( headerSourceFileRelationMap [ headerUri ] . has ( doc . uri . toString ( ) ) ) {
124- if ( headerSourceFileRelationMap [ headerUri ] . size === 1 ) {
125- diagnosticCollection . delete ( vscode . Uri . parse ( headerUri ) ) ;
120+ // Any file who was warnings generated from (and only from) the closed doc have their diagnostics cleared
121+ // NOTE: This includes the closed doc - its diagnostics will only be cleared if its warnings only come from analysis of it itself
122+ for ( const fileUri of Object . keys ( fileRelationMap ) ) {
123+ if ( fileRelationMap [ fileUri ] . has ( doc . uri . toString ( ) ) ) {
124+ if ( fileRelationMap [ fileUri ] . size <= 1 ) {
125+ diagnosticCollection . delete ( vscode . Uri . parse ( fileUri ) ) ;
126+ fileRelationMap [ fileUri ] . clear ( ) ;
126127 } else {
127- headerSourceFileRelationMap [ headerUri ] . delete ( doc . uri . toString ( ) ) ;
128+ fileRelationMap [ fileUri ] . delete ( doc . uri . toString ( ) ) ;
128129 }
129130 }
130131 }
@@ -443,12 +444,11 @@ async function runCppcheckOnFileXML(
443444 const sourceDocumentUri = document . uri . toString ( ) ;
444445 for ( const uri of Object . keys ( diagnostics ) ) {
445446 diagnosticCollection . set ( vscode . Uri . parse ( uri ) , diagnostics [ uri ] ) ;
446- if ( uri !== sourceDocumentUri ) {
447- if ( headerSourceFileRelationMap [ uri ] === null || headerSourceFileRelationMap [ uri ] === undefined ) {
448- headerSourceFileRelationMap [ uri ] = new Set ;
449- }
450- headerSourceFileRelationMap [ uri ] . add ( sourceDocumentUri ) ;
447+ if ( fileRelationMap [ uri ] === null || fileRelationMap [ uri ] === undefined ) {
448+ fileRelationMap [ uri ] = new Set ;
451449 }
450+ // NOTE: uri can be the same as sourceDocumentUri
451+ fileRelationMap [ uri ] . add ( sourceDocumentUri ) ;
452452 }
453453 } ) ;
454454
0 commit comments