This commit is contained in:
Matt Parker
2025-08-13 21:50:55 +10:00
parent d5a4540ab7
commit 3ef1705451
2 changed files with 19 additions and 4 deletions

View File

@@ -7,13 +7,28 @@ namespace SharpIDE.Application.Features.Analysis;
public static class RoslynAnalysis
{
private static MSBuildWorkspace? _workspace;
public static void StartSolutionAnalysis(string solutionFilePath)
{
_ = Task.Run(async () =>
{
try
{
await Analyse(solutionFilePath);
}
catch (Exception e)
{
Console.WriteLine($"RoslynAnalysis: Error during analysis: {e}");
}
});
}
public static async Task Analyse(string solutionFilePath)
{
Console.WriteLine($"RoslynAnalysis: Loading solution");
var timer = Stopwatch.StartNew();
var workspace = MSBuildWorkspace.Create();
workspace.WorkspaceFailed += (o, e) => throw new InvalidOperationException($"Workspace failed: {e.Diagnostic.Message}");
var solution = await workspace.OpenSolutionAsync(solutionFilePath, new Progress());
_workspace ??= MSBuildWorkspace.Create();
_workspace.WorkspaceFailed += (o, e) => throw new InvalidOperationException($"Workspace failed: {e.Diagnostic.Message}");
var solution = await _workspace.OpenSolutionAsync(solutionFilePath, new Progress());
timer.Stop();
Console.WriteLine($"RoslynAnalysis: Solution loaded in {timer.ElapsedMilliseconds}ms");
Console.WriteLine();

View File

@@ -152,7 +152,7 @@
var solutionModel = await VsPersistenceMapper.GetSolutionModel(_solutionFilePath);
_solutionModel = solutionModel;
await RoslynAnalysis.Analyse(_solutionFilePath);
RoslynAnalysis.StartSolutionAnalysis(_solutionFilePath);
}
private CancellationTokenSource? _cancellationTokenSource = null!;