From 882382bbd48a9902d8029ac62ac6ceacab5fd54f Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Fri, 17 Oct 2025 20:33:54 +1000 Subject: [PATCH] file change handling --- .../Features/Events/GlobalEvents.cs | 3 +-- .../Features/FilePersistence/IdeFileManager.cs | 2 ++ .../FileWatching/IdeFileExternalChangeHandler.cs | 3 ++- ...geHandler.cs => IdeFileSavedToDiskHandler.cs} | 16 ++++++++++++---- src/SharpIDE.Godot/IdeRoot.cs | 4 ++-- src/SharpIDE.Godot/Singletons.cs | 2 +- 6 files changed, 20 insertions(+), 10 deletions(-) rename src/SharpIDE.Application/Features/FileWatching/{IdeFileChangeHandler.cs => IdeFileSavedToDiskHandler.cs} (70%) diff --git a/src/SharpIDE.Application/Features/Events/GlobalEvents.cs b/src/SharpIDE.Application/Features/Events/GlobalEvents.cs index fece697..295385f 100644 --- a/src/SharpIDE.Application/Features/Events/GlobalEvents.cs +++ b/src/SharpIDE.Application/Features/Events/GlobalEvents.cs @@ -14,8 +14,7 @@ public class GlobalEvents public EventWrapper ProjectStartedRunning { get; } = new(_ => Task.CompletedTask); public EventWrapper ProjectStoppedRunning { get; } = new(_ => Task.CompletedTask); public EventWrapper DebuggerExecutionStopped { get; } = new(_ => Task.CompletedTask); - /// Meaning saved/persisted to disk - public EventWrapper IdeFileChanged { get; } = new(_ => Task.CompletedTask); + public EventWrapper IdeFileSavedToDisk { get; } = new(_ => Task.CompletedTask); public FileSystemWatcherInternal FileSystemWatcherInternal { get; } = new(); } diff --git a/src/SharpIDE.Application/Features/FilePersistence/IdeFileManager.cs b/src/SharpIDE.Application/Features/FilePersistence/IdeFileManager.cs index 0434ce1..5014920 100644 --- a/src/SharpIDE.Application/Features/FilePersistence/IdeFileManager.cs +++ b/src/SharpIDE.Application/Features/FilePersistence/IdeFileManager.cs @@ -1,5 +1,6 @@ using System.Collections.Concurrent; using SharpIDE.Application.Features.Analysis; +using SharpIDE.Application.Features.Events; using SharpIDE.Application.Features.SolutionDiscovery; namespace SharpIDE.Application.Features.FilePersistence; @@ -59,6 +60,7 @@ public class IdeFileManager var text = await GetFileTextAsync(file); await WriteAllText(file, text); file.IsDirty.Value = false; + GlobalEvents.Instance.IdeFileSavedToDisk.InvokeParallelFireAndForget(file); } public async Task UpdateInMemoryIfOpenAndSaveAsync(SharpIdeFile file, string newText) diff --git a/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs b/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs index 7a5676e..c2707bb 100644 --- a/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs +++ b/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs @@ -31,7 +31,8 @@ public class IdeFileExternalChangeHandler var file = SolutionModel.AllFiles.SingleOrDefault(f => f.Path == filePath); if (file is not null) { - await GlobalEvents.Instance.IdeFileChanged.InvokeParallelAsync(file); + await file.FileContentsChangedExternallyFromDisk.InvokeParallelAsync(); + await GlobalEvents.Instance.IdeFileSavedToDisk.InvokeParallelAsync(file); } } } diff --git a/src/SharpIDE.Application/Features/FileWatching/IdeFileChangeHandler.cs b/src/SharpIDE.Application/Features/FileWatching/IdeFileSavedToDiskHandler.cs similarity index 70% rename from src/SharpIDE.Application/Features/FileWatching/IdeFileChangeHandler.cs rename to src/SharpIDE.Application/Features/FileWatching/IdeFileSavedToDiskHandler.cs index e9d85cb..7ed3472 100644 --- a/src/SharpIDE.Application/Features/FileWatching/IdeFileChangeHandler.cs +++ b/src/SharpIDE.Application/Features/FileWatching/IdeFileSavedToDiskHandler.cs @@ -6,22 +6,25 @@ using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; namespace SharpIDE.Application.Features.FileWatching; -public class IdeFileChangeHandler +public class IdeFileSavedToDiskHandler { public SharpIdeSolutionModel SolutionModel { get; set; } = null!; - public IdeFileChangeHandler() + public IdeFileSavedToDiskHandler() { - GlobalEvents.Instance.IdeFileChanged.Subscribe(HandleIdeFileChanged); + GlobalEvents.Instance.IdeFileSavedToDisk.Subscribe(HandleIdeFileChanged); } private async Task HandleIdeFileChanged(SharpIdeFile file) { - await file.FileContentsChangedExternallyFromDisk.InvokeParallelAsync(); if (file.IsCsprojFile) { await HandleCsprojChanged(file); } + else if (file.IsRoslynWorkspaceFile) + { + await HandleWorkspaceFileChanged(file); + } } private async Task HandleCsprojChanged(SharpIdeFile file) @@ -32,4 +35,9 @@ public class IdeFileChangeHandler await RoslynAnalysis.ReloadProject(project); await RoslynAnalysis.UpdateSolutionDiagnostics(); } + + private async Task HandleWorkspaceFileChanged(SharpIdeFile file) + { + await RoslynAnalysis.UpdateSolutionDiagnostics(); + } } diff --git a/src/SharpIDE.Godot/IdeRoot.cs b/src/SharpIDE.Godot/IdeRoot.cs index 537baa8..51f7e03 100644 --- a/src/SharpIDE.Godot/IdeRoot.cs +++ b/src/SharpIDE.Godot/IdeRoot.cs @@ -51,7 +51,7 @@ public partial class IdeRoot : Control Singletons.FileWatcher = new IdeFileWatcher(); Singletons.FileManager = new IdeFileManager(); Singletons.FileExternalChangeHandler = new IdeFileExternalChangeHandler(); - Singletons.FileChangeHandler = new IdeFileChangeHandler(); + Singletons.FileSavedToDiskHandler = new IdeFileSavedToDiskHandler(); } public override void _Ready() @@ -129,7 +129,7 @@ public partial class IdeRoot : Control _searchWindow.Solution = solutionModel; _searchAllFilesWindow.Solution = solutionModel; Singletons.FileExternalChangeHandler.SolutionModel = solutionModel; - Singletons.FileChangeHandler.SolutionModel = solutionModel; + Singletons.FileSavedToDiskHandler.SolutionModel = solutionModel; Callable.From(_solutionExplorerPanel.RepopulateTree).CallDeferred(); RoslynAnalysis.StartSolutionAnalysis(solutionModel); Singletons.FileWatcher.StartWatching(solutionModel); diff --git a/src/SharpIDE.Godot/Singletons.cs b/src/SharpIDE.Godot/Singletons.cs index 1d1b7d2..65631ed 100644 --- a/src/SharpIDE.Godot/Singletons.cs +++ b/src/SharpIDE.Godot/Singletons.cs @@ -13,6 +13,6 @@ public static class Singletons public static IdeFileWatcher FileWatcher { get; set; } = null!; public static IdeFileManager FileManager { get; set; } = null!; public static IdeFileExternalChangeHandler FileExternalChangeHandler { get; set; } = null!; - public static IdeFileChangeHandler FileChangeHandler { get; set; } = null!; + public static IdeFileSavedToDiskHandler FileSavedToDiskHandler { get; set; } = null!; public static AppState AppState { get; set; } = null!; } \ No newline at end of file