@@ -23,7 +23,7 @@ import * as fsUtils from '../utils/fs-utils';
2323import { getFileNameFromPath } from '../utils/path-utils' ;
2424import { stripTwoExtensions } from '../utils/string-utils' ;
2525import { getWorkspaceFolder } from '../utils/vscode-utils' ;
26- import { SolutionManager } from './solution-manager' ;
26+ import { SolutionLoadStateChangeEvent , SolutionManager } from './solution-manager' ;
2727import { ConvertResultData , SolutionEventHub } from './solution-event-hub' ;
2828
2929export const toolsPrefixPatterns = {
@@ -108,6 +108,10 @@ export interface SolutionProblems {
108108export class SolutionProblemsImpl implements SolutionProblems {
109109
110110 private readonly diagnosticCollection : vscode . DiagnosticCollection = vscode . languages . createDiagnosticCollection ( 'csolution' ) ;
111+ /**
112+ * source files for diagnostics mapping
113+ */
114+ private readonly sourceFiles : Map < string , string > = new Map < string , string > ( ) ;
111115
112116 private readonly queryActionPatterns : ReadonlyArray < { pattern : RegExp ; action : 'components-packs' | 'find-in-files' } > = [
113117 { pattern : / d e p e n d e n c y v a l i d a t i o n f o r c o n t e x t ' ( [ ^ ' ] + ) ' f a i l e d : / , action : 'components-packs' } ,
@@ -126,6 +130,7 @@ export class SolutionProblemsImpl implements SolutionProblems {
126130 public async activate ( context : vscode . ExtensionContext ) : Promise < void > {
127131 context . subscriptions . push (
128132 this . eventHub . onDidConvertCompleted ( this . handleConvertCompleted , this ) ,
133+ this . solutionManager . onDidChangeLoadState ( this . handleLoadStateChanged , this ) ,
129134 this . diagnosticCollection ,
130135 ) ;
131136 }
@@ -135,6 +140,12 @@ export class SolutionProblemsImpl implements SolutionProblems {
135140 await this . updateDiagnostics ( data . logMessages ) ;
136141 }
137142
143+ private handleLoadStateChanged ( data : SolutionLoadStateChangeEvent ) : void {
144+ if ( data . previousState . solutionPath !== data . newState . solutionPath ) {
145+ this . clearDiagnostics ( ) ;
146+ }
147+ }
148+
138149 /**
139150 * log message regex in the format <filename>:<line>:<column> - <message>
140151 * regex named groups:
@@ -195,10 +206,17 @@ export class SolutionProblemsImpl implements SolutionProblems {
195206 return true ;
196207 }
197208
198- private async updateDiagnostics ( messages : LogMessages ) : Promise < void > {
199- // clear previous diagnostics
209+ /**
210+ * Clear diagnostic and collected files
211+ */
212+ private clearDiagnostics ( ) : void {
200213 this . diagnosticCollection . clear ( ) ;
201214 this . collectYmlFiles ( ) ;
215+ }
216+
217+ private async updateDiagnostics ( messages : LogMessages ) : Promise < void > {
218+ // clear previous diagnostics
219+ this . clearDiagnostics ( ) ;
202220 let diagnostics = false ;
203221
204222 // iterate through log messages and set diagnostics
@@ -216,11 +234,6 @@ export class SolutionProblemsImpl implements SolutionProblems {
216234 }
217235 }
218236
219- /**
220- * source files for diagnostics mapping
221- */
222- private readonly sourceFiles : Map < string , string > = new Map < string , string > ( ) ;
223-
224237 private addFile ( file : string ) : void {
225238 if ( file . length > 0 ) {
226239 this . sourceFiles . set ( getFileNameFromPath ( file ) , file ) ;
0 commit comments