@@ -15,6 +15,7 @@ namespace Microsoft.DotNet.Watch;
1515internal sealed class IncrementalMSBuildWorkspace : Workspace
1616{
1717 private readonly ILogger _logger ;
18+ private int _solutionUpdateId ;
1819
1920 public IncrementalMSBuildWorkspace ( ILogger logger )
2021 : base ( MSBuildMefHostServices . DefaultServices , WorkspaceKind . MSBuild )
@@ -35,6 +36,9 @@ public IncrementalMSBuildWorkspace(ILogger logger)
3536
3637 public async Task UpdateProjectConeAsync ( string rootProjectPath , CancellationToken cancellationToken )
3738 {
39+ _logger . LogInformation ( "Loading projects ..." ) ;
40+
41+ var stopwatch = Stopwatch . StartNew ( ) ;
3842 var oldSolution = CurrentSolution ;
3943
4044 var loader = new MSBuildProjectLoader ( this ) ;
@@ -94,9 +98,11 @@ public async Task UpdateProjectConeAsync(string rootProjectPath, CancellationTok
9498 . WithCompilationOutputInfo ( newProjectInfo . CompilationOutputInfo ) ) ;
9599 }
96100
97- await ReportSolutionFilesAsync ( SetCurrentSolution ( newSolution ) , cancellationToken ) ;
101+ await UpdateSolutionAsync ( newSolution , operationDisplayName : "project update" , cancellationToken ) ;
98102 UpdateReferencesAfterAdd ( ) ;
99103
104+ _logger . LogInformation ( "Projects loaded in {Time}ms." , stopwatch . ElapsedMilliseconds ) ;
105+
100106 ProjectReference MapProjectReference ( ProjectReference pr )
101107 // Only C# and VB projects are loaded by the MSBuildProjectLoader, so some references might be missing.
102108 // When a new project is added along with a new project reference the old project id is also null.
@@ -154,6 +160,8 @@ public async ValueTask UpdateFileContentAsync(IEnumerable<ChangedFile> changedFi
154160
155161 var newText = await GetSourceTextAsync ( changedFile . FilePath , oldText . Encoding , oldText . ChecksumAlgorithm , cancellationToken ) ;
156162
163+ _logger . LogDebug ( "Updating document text of '{FilePath}'." , changedFile . FilePath ) ;
164+
157165 updatedSolution = textDocument switch
158166 {
159167 Document document => document . WithText ( newText ) . Project . Solution ,
@@ -166,7 +174,7 @@ public async ValueTask UpdateFileContentAsync(IEnumerable<ChangedFile> changedFi
166174
167175 updatedSolution = RemoveDocuments ( updatedSolution , documentsToRemove ) ;
168176
169- await ReportSolutionFilesAsync ( SetCurrentSolution ( updatedSolution ) , cancellationToken ) ;
177+ await UpdateSolutionAsync ( updatedSolution , operationDisplayName : "document update" , cancellationToken ) ;
170178 }
171179
172180 private static Solution RemoveDocuments ( Solution solution , IEnumerable < DocumentId > ids )
@@ -217,9 +225,19 @@ private static async ValueTask<SourceText> GetSourceTextAsync(string filePath, E
217225 return null ;
218226 }
219227
220- public async Task ReportSolutionFilesAsync ( Solution solution , CancellationToken cancellationToken )
228+ private Task UpdateSolutionAsync ( Solution newSolution , string operationDisplayName , CancellationToken cancellationToken )
229+ => ReportSolutionFilesAsync ( SetCurrentSolution ( newSolution ) , Interlocked . Increment ( ref _solutionUpdateId ) , operationDisplayName , cancellationToken ) ;
230+
231+ private async Task ReportSolutionFilesAsync ( Solution solution , int updateId , string operationDisplayName , CancellationToken cancellationToken )
221232 {
222- _logger . LogDebug ( "Solution: {Path}" , solution . FilePath ) ;
233+ //if (!_logger.IsEnabled(LogLevel.Debug))
234+ //{
235+ // return;
236+ //}
237+
238+ var stopwatch = Stopwatch . StartNew ( ) ;
239+
240+ _logger . LogDebug ( "Solution after {Operation}: v{Version}" , operationDisplayName , updateId ) ;
223241 foreach ( var project in solution . Projects )
224242 {
225243 _logger . LogDebug ( " Project: {Path}" , project . FilePath ) ;
@@ -240,6 +258,8 @@ public async Task ReportSolutionFilesAsync(Solution solution, CancellationToken
240258 }
241259 }
242260
261+ _logger . LogInformation ( "Solution reported in {Time}ms." , stopwatch . ElapsedMilliseconds ) ;
262+
243263 async ValueTask InspectDocumentAsync ( TextDocument document , string kind )
244264 {
245265 var text = await document . GetTextAsync ( cancellationToken ) ;
0 commit comments