diff --git a/src/SharpIDE.Application/Features/Events/GlobalEvents.cs b/src/SharpIDE.Application/Features/Events/GlobalEvents.cs index 20d9a13..de24e19 100644 --- a/src/SharpIDE.Application/Features/Events/GlobalEvents.cs +++ b/src/SharpIDE.Application/Features/Events/GlobalEvents.cs @@ -17,6 +17,9 @@ public class GlobalEvents public FileSystemWatcherInternal FileSystemWatcherInternal { get; } = new(); } +/// +/// All file system events for files we have filtered for, e.g. excluding bin/obj folders. Does not filter out events triggered by us +/// public class FileSystemWatcherInternal { public EventWrapper DirectoryCreated { get; } = new(_ => Task.CompletedTask); diff --git a/src/SharpIDE.Application/Features/FileWatching/IdeFileChangeHandler.cs b/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs similarity index 59% rename from src/SharpIDE.Application/Features/FileWatching/IdeFileChangeHandler.cs rename to src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs index c681ff0..aeec7b6 100644 --- a/src/SharpIDE.Application/Features/FileWatching/IdeFileChangeHandler.cs +++ b/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs @@ -1,12 +1,14 @@ -using SharpIDE.Application.Features.Events; +using SharpIDE.Application.Features.Analysis; +using SharpIDE.Application.Features.Evaluation; +using SharpIDE.Application.Features.Events; using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; namespace SharpIDE.Application.Features.FileWatching; -public class IdeFileChangeHandler +public class IdeFileExternalChangeHandler { public SharpIdeSolutionModel SolutionModel { get; set; } = null!; - public IdeFileChangeHandler() + public IdeFileExternalChangeHandler() { GlobalEvents.Instance.FileSystemWatcherInternal.FileChanged.Subscribe(OnFileChanged); } @@ -27,5 +29,18 @@ public class IdeFileChangeHandler } Console.WriteLine($"IdeFileChangeHandler: Changed - {filePath}"); await sharpIdeFile.FileContentsChangedExternallyFromDisk.InvokeParallelAsync(); + if (sharpIdeFile.IsCsprojFile) + { + await HandleCsprojChanged(filePath); + } + } + + private async Task HandleCsprojChanged(string filePath) + { + var project = SolutionModel.AllProjects.SingleOrDefault(p => p.FilePath == filePath); + if (project is null) return; + await ProjectEvaluation.ReloadProject(filePath); + await RoslynAnalysis.ReloadProject(project); + await RoslynAnalysis.UpdateSolutionDiagnostics(); } } diff --git a/src/SharpIDE.Godot/IdeRoot.cs b/src/SharpIDE.Godot/IdeRoot.cs index 3a769ff..a355c73 100644 --- a/src/SharpIDE.Godot/IdeRoot.cs +++ b/src/SharpIDE.Godot/IdeRoot.cs @@ -50,7 +50,7 @@ public partial class IdeRoot : Control Singletons.FileWatcher?.Dispose(); Singletons.FileWatcher = new IdeFileWatcher(); Singletons.FileManager = new IdeFileManager(); - Singletons.FileChangeHandler = new IdeFileChangeHandler(); + Singletons.FileExternalChangeHandler = new IdeFileExternalChangeHandler(); } public override void _Ready() @@ -127,7 +127,7 @@ public partial class IdeRoot : Control _bottomPanelManager.Solution = solutionModel; _searchWindow.Solution = solutionModel; _searchAllFilesWindow.Solution = solutionModel; - Singletons.FileChangeHandler.SolutionModel = solutionModel; + Singletons.FileExternalChangeHandler.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 0ffb6c4..acbf811 100644 --- a/src/SharpIDE.Godot/Singletons.cs +++ b/src/SharpIDE.Godot/Singletons.cs @@ -12,6 +12,6 @@ public static class Singletons public static BuildService BuildService { get; set; } = null!; public static IdeFileWatcher FileWatcher { get; set; } = null!; public static IdeFileManager FileManager { get; set; } = null!; - public static IdeFileChangeHandler FileChangeHandler { get; set; } = null!; + public static IdeFileExternalChangeHandler FileExternalChangeHandler { get; set; } = null!; public static AppState AppState { get; set; } = null!; } \ No newline at end of file