file change handling
This commit is contained in:
@@ -14,8 +14,7 @@ public class GlobalEvents
|
|||||||
public EventWrapper<SharpIdeProjectModel, Task> ProjectStartedRunning { get; } = new(_ => Task.CompletedTask);
|
public EventWrapper<SharpIdeProjectModel, Task> ProjectStartedRunning { get; } = new(_ => Task.CompletedTask);
|
||||||
public EventWrapper<SharpIdeProjectModel, Task> ProjectStoppedRunning { get; } = new(_ => Task.CompletedTask);
|
public EventWrapper<SharpIdeProjectModel, Task> ProjectStoppedRunning { get; } = new(_ => Task.CompletedTask);
|
||||||
public EventWrapper<ExecutionStopInfo, Task> DebuggerExecutionStopped { get; } = new(_ => Task.CompletedTask);
|
public EventWrapper<ExecutionStopInfo, Task> DebuggerExecutionStopped { get; } = new(_ => Task.CompletedTask);
|
||||||
/// Meaning saved/persisted to disk
|
public EventWrapper<SharpIdeFile, Task> IdeFileSavedToDisk { get; } = new(_ => Task.CompletedTask);
|
||||||
public EventWrapper<SharpIdeFile, Task> IdeFileChanged { get; } = new(_ => Task.CompletedTask);
|
|
||||||
|
|
||||||
public FileSystemWatcherInternal FileSystemWatcherInternal { get; } = new();
|
public FileSystemWatcherInternal FileSystemWatcherInternal { get; } = new();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using SharpIDE.Application.Features.Analysis;
|
using SharpIDE.Application.Features.Analysis;
|
||||||
|
using SharpIDE.Application.Features.Events;
|
||||||
using SharpIDE.Application.Features.SolutionDiscovery;
|
using SharpIDE.Application.Features.SolutionDiscovery;
|
||||||
|
|
||||||
namespace SharpIDE.Application.Features.FilePersistence;
|
namespace SharpIDE.Application.Features.FilePersistence;
|
||||||
@@ -59,6 +60,7 @@ public class IdeFileManager
|
|||||||
var text = await GetFileTextAsync(file);
|
var text = await GetFileTextAsync(file);
|
||||||
await WriteAllText(file, text);
|
await WriteAllText(file, text);
|
||||||
file.IsDirty.Value = false;
|
file.IsDirty.Value = false;
|
||||||
|
GlobalEvents.Instance.IdeFileSavedToDisk.InvokeParallelFireAndForget(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateInMemoryIfOpenAndSaveAsync(SharpIdeFile file, string newText)
|
public async Task UpdateInMemoryIfOpenAndSaveAsync(SharpIdeFile file, string newText)
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ public class IdeFileExternalChangeHandler
|
|||||||
var file = SolutionModel.AllFiles.SingleOrDefault(f => f.Path == filePath);
|
var file = SolutionModel.AllFiles.SingleOrDefault(f => f.Path == filePath);
|
||||||
if (file is not null)
|
if (file is not null)
|
||||||
{
|
{
|
||||||
await GlobalEvents.Instance.IdeFileChanged.InvokeParallelAsync(file);
|
await file.FileContentsChangedExternallyFromDisk.InvokeParallelAsync();
|
||||||
|
await GlobalEvents.Instance.IdeFileSavedToDisk.InvokeParallelAsync(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,22 +6,25 @@ using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
|||||||
|
|
||||||
namespace SharpIDE.Application.Features.FileWatching;
|
namespace SharpIDE.Application.Features.FileWatching;
|
||||||
|
|
||||||
public class IdeFileChangeHandler
|
public class IdeFileSavedToDiskHandler
|
||||||
{
|
{
|
||||||
public SharpIdeSolutionModel SolutionModel { get; set; } = null!;
|
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)
|
private async Task HandleIdeFileChanged(SharpIdeFile file)
|
||||||
{
|
{
|
||||||
await file.FileContentsChangedExternallyFromDisk.InvokeParallelAsync();
|
|
||||||
if (file.IsCsprojFile)
|
if (file.IsCsprojFile)
|
||||||
{
|
{
|
||||||
await HandleCsprojChanged(file);
|
await HandleCsprojChanged(file);
|
||||||
}
|
}
|
||||||
|
else if (file.IsRoslynWorkspaceFile)
|
||||||
|
{
|
||||||
|
await HandleWorkspaceFileChanged(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task HandleCsprojChanged(SharpIdeFile file)
|
private async Task HandleCsprojChanged(SharpIdeFile file)
|
||||||
@@ -32,4 +35,9 @@ public class IdeFileChangeHandler
|
|||||||
await RoslynAnalysis.ReloadProject(project);
|
await RoslynAnalysis.ReloadProject(project);
|
||||||
await RoslynAnalysis.UpdateSolutionDiagnostics();
|
await RoslynAnalysis.UpdateSolutionDiagnostics();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task HandleWorkspaceFileChanged(SharpIdeFile file)
|
||||||
|
{
|
||||||
|
await RoslynAnalysis.UpdateSolutionDiagnostics();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ public partial class IdeRoot : Control
|
|||||||
Singletons.FileWatcher = new IdeFileWatcher();
|
Singletons.FileWatcher = new IdeFileWatcher();
|
||||||
Singletons.FileManager = new IdeFileManager();
|
Singletons.FileManager = new IdeFileManager();
|
||||||
Singletons.FileExternalChangeHandler = new IdeFileExternalChangeHandler();
|
Singletons.FileExternalChangeHandler = new IdeFileExternalChangeHandler();
|
||||||
Singletons.FileChangeHandler = new IdeFileChangeHandler();
|
Singletons.FileSavedToDiskHandler = new IdeFileSavedToDiskHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
@@ -129,7 +129,7 @@ public partial class IdeRoot : Control
|
|||||||
_searchWindow.Solution = solutionModel;
|
_searchWindow.Solution = solutionModel;
|
||||||
_searchAllFilesWindow.Solution = solutionModel;
|
_searchAllFilesWindow.Solution = solutionModel;
|
||||||
Singletons.FileExternalChangeHandler.SolutionModel = solutionModel;
|
Singletons.FileExternalChangeHandler.SolutionModel = solutionModel;
|
||||||
Singletons.FileChangeHandler.SolutionModel = solutionModel;
|
Singletons.FileSavedToDiskHandler.SolutionModel = solutionModel;
|
||||||
Callable.From(_solutionExplorerPanel.RepopulateTree).CallDeferred();
|
Callable.From(_solutionExplorerPanel.RepopulateTree).CallDeferred();
|
||||||
RoslynAnalysis.StartSolutionAnalysis(solutionModel);
|
RoslynAnalysis.StartSolutionAnalysis(solutionModel);
|
||||||
Singletons.FileWatcher.StartWatching(solutionModel);
|
Singletons.FileWatcher.StartWatching(solutionModel);
|
||||||
|
|||||||
@@ -13,6 +13,6 @@ public static class Singletons
|
|||||||
public static IdeFileWatcher FileWatcher { get; set; } = null!;
|
public static IdeFileWatcher FileWatcher { get; set; } = null!;
|
||||||
public static IdeFileManager FileManager { get; set; } = null!;
|
public static IdeFileManager FileManager { get; set; } = null!;
|
||||||
public static IdeFileExternalChangeHandler FileExternalChangeHandler { 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!;
|
public static AppState AppState { get; set; } = null!;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user