Add IdeFileChangeHandler
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using SharpIDE.Application.Features.Analysis;
|
||||
using SharpIDE.Application.Features.Evaluation;
|
||||
using SharpIDE.Application.Features.Events;
|
||||
using SharpIDE.Application.Features.SolutionDiscovery;
|
||||
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||
|
||||
namespace SharpIDE.Application.Features.FileWatching;
|
||||
|
||||
public class IdeFileChangeHandler
|
||||
{
|
||||
public SharpIdeSolutionModel SolutionModel { get; set; } = null!;
|
||||
|
||||
public IdeFileChangeHandler()
|
||||
{
|
||||
GlobalEvents.Instance.IdeFileChanged.Subscribe(HandleIdeFileChanged);
|
||||
}
|
||||
|
||||
private async Task HandleIdeFileChanged(SharpIdeFile file)
|
||||
{
|
||||
await file.FileContentsChangedExternallyFromDisk.InvokeParallelAsync();
|
||||
if (file.IsCsprojFile)
|
||||
{
|
||||
await HandleCsprojChanged(file);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleCsprojChanged(SharpIdeFile file)
|
||||
{
|
||||
var project = SolutionModel.AllProjects.SingleOrDefault(p => p.FilePath == file.Path);
|
||||
if (project is null) return;
|
||||
await ProjectEvaluation.ReloadProject(file.Path);
|
||||
await RoslynAnalysis.ReloadProject(project);
|
||||
await RoslynAnalysis.UpdateSolutionDiagnostics();
|
||||
}
|
||||
}
|
||||
@@ -23,24 +23,15 @@ public class IdeFileExternalChangeHandler
|
||||
var now = DateTimeOffset.Now;
|
||||
if (now - sharpIdeFile.LastIdeWriteTime.Value < TimeSpan.FromMilliseconds(300))
|
||||
{
|
||||
Console.WriteLine($"IdeFileChangeHandler: Ignored - {filePath}");
|
||||
Console.WriteLine($"IdeFileExternalChangeHandler: Ignored - {filePath}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
Console.WriteLine($"IdeFileChangeHandler: Changed - {filePath}");
|
||||
await sharpIdeFile.FileContentsChangedExternallyFromDisk.InvokeParallelAsync();
|
||||
if (sharpIdeFile.IsCsprojFile)
|
||||
Console.WriteLine($"IdeFileExternalChangeHandler: Changed - {filePath}");
|
||||
var file = SolutionModel.AllFiles.SingleOrDefault(f => f.Path == filePath);
|
||||
if (file is not null)
|
||||
{
|
||||
await HandleCsprojChanged(filePath);
|
||||
await GlobalEvents.Instance.IdeFileChanged.InvokeParallelAsync(file);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user