Refresh files on external change

This commit is contained in:
Matt Parker
2025-10-09 00:56:45 +10:00
parent e30a0761ac
commit e57fe03348
8 changed files with 98 additions and 21 deletions

View File

@@ -0,0 +1,21 @@
using SharpIDE.Application.Features.Events;
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
namespace SharpIDE.Application.Features.FileWatching;
public class IdeFileChangeHandler
{
public SharpIdeSolutionModel SolutionModel { get; set; } = null!;
public IdeFileChangeHandler()
{
GlobalEvents.Instance.FileSystemWatcherInternal.FileChanged.Subscribe(OnFileChanged);
}
private async Task OnFileChanged(string arg)
{
var sharpIdeFile = SolutionModel.AllFiles.SingleOrDefault(f => f.Path == arg);
if (sharpIdeFile is null) return;
// TODO: Suppress if SharpIDE changed the file
await sharpIdeFile.FileContentsChangedExternallyFromDisk.InvokeParallelAsync();
}
}

View File

@@ -1,5 +1,6 @@
using FileWatcherEx;
using Microsoft.Extensions.FileSystemGlobbing;
using SharpIDE.Application.Features.Events;
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
namespace SharpIDE.Application.Features.FileWatching;
@@ -62,7 +63,6 @@ public sealed class IdeFileWatcher : IDisposable
private void HandleRenamed(string? oldFullPath, string fullPath)
{
Console.WriteLine($"FileSystemWatcher: Renamed - {oldFullPath}, {fullPath}");
}
@@ -83,8 +83,8 @@ public sealed class IdeFileWatcher : IDisposable
private void HandleChanged(string fullPath)
{
if (Path.HasExtension(fullPath) is false) return;
// TODO: Handle updating the content of open files in editors
Console.WriteLine($"FileSystemWatcher: Changed - {fullPath}");
GlobalEvents.Instance.FileSystemWatcherInternal.FileChanged.InvokeParallelFireAndForget(fullPath);
}
public void Dispose()