From 1a7c2acbd972154cae77b8cc015d55930f6d5388 Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Sun, 19 Oct 2025 13:52:21 +1000 Subject: [PATCH] cancel old solution diagnostics updates --- .../Features/FileWatching/FileChangedService.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/SharpIDE.Application/Features/FileWatching/FileChangedService.cs b/src/SharpIDE.Application/Features/FileWatching/FileChangedService.cs index d25839d..b329f86 100644 --- a/src/SharpIDE.Application/Features/FileWatching/FileChangedService.cs +++ b/src/SharpIDE.Application/Features/FileWatching/FileChangedService.cs @@ -61,20 +61,29 @@ public class FileChangedService(RoslynAnalysis roslynAnalysis, IdeOpenTabsFileMa await afterSaveTask; } + private CancellationTokenSource _updateSolutionDiagnosticsCts = new(); private async Task HandleCsprojChanged(SharpIdeFile file) { var project = SolutionModel.AllProjects.SingleOrDefault(p => p.FilePath == file.Path); if (project is null) return; + var newCts = new CancellationTokenSource(); + var oldCts = Interlocked.Exchange(ref _updateSolutionDiagnosticsCts, newCts); + await oldCts.CancelAsync(); + oldCts.Dispose(); await ProjectEvaluation.ReloadProject(file.Path); - await _roslynAnalysis.ReloadProject(project); + await _roslynAnalysis.ReloadProject(project, CancellationToken.None); GlobalEvents.Instance.SolutionAltered.InvokeParallelFireAndForget(); - await _roslynAnalysis.UpdateSolutionDiagnostics(); + await _roslynAnalysis.UpdateSolutionDiagnostics(newCts.Token); } private async Task HandleWorkspaceFileChanged(SharpIdeFile file, string newContents) { + var newCts = new CancellationTokenSource(); + var oldCts = Interlocked.Exchange(ref _updateSolutionDiagnosticsCts, newCts); + await oldCts.CancelAsync(); + oldCts.Dispose(); await _roslynAnalysis.UpdateDocument(file, newContents); GlobalEvents.Instance.SolutionAltered.InvokeParallelFireAndForget(); - await _roslynAnalysis.UpdateSolutionDiagnostics(); + await _roslynAnalysis.UpdateSolutionDiagnostics(newCts.Token); } }