refactor
This commit is contained in:
@@ -7,13 +7,28 @@ namespace SharpIDE.Application.Features.Analysis;
|
|||||||
|
|
||||||
public static class RoslynAnalysis
|
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)
|
public static async Task Analyse(string solutionFilePath)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"RoslynAnalysis: Loading solution");
|
Console.WriteLine($"RoslynAnalysis: Loading solution");
|
||||||
var timer = Stopwatch.StartNew();
|
var timer = Stopwatch.StartNew();
|
||||||
var workspace = MSBuildWorkspace.Create();
|
_workspace ??= MSBuildWorkspace.Create();
|
||||||
workspace.WorkspaceFailed += (o, e) => throw new InvalidOperationException($"Workspace failed: {e.Diagnostic.Message}");
|
_workspace.WorkspaceFailed += (o, e) => throw new InvalidOperationException($"Workspace failed: {e.Diagnostic.Message}");
|
||||||
var solution = await workspace.OpenSolutionAsync(solutionFilePath, new Progress());
|
var solution = await _workspace.OpenSolutionAsync(solutionFilePath, new Progress());
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
Console.WriteLine($"RoslynAnalysis: Solution loaded in {timer.ElapsedMilliseconds}ms");
|
Console.WriteLine($"RoslynAnalysis: Solution loaded in {timer.ElapsedMilliseconds}ms");
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
|
|||||||
@@ -152,7 +152,7 @@
|
|||||||
|
|
||||||
var solutionModel = await VsPersistenceMapper.GetSolutionModel(_solutionFilePath);
|
var solutionModel = await VsPersistenceMapper.GetSolutionModel(_solutionFilePath);
|
||||||
_solutionModel = solutionModel;
|
_solutionModel = solutionModel;
|
||||||
await RoslynAnalysis.Analyse(_solutionFilePath);
|
RoslynAnalysis.StartSolutionAnalysis(_solutionFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CancellationTokenSource? _cancellationTokenSource = null!;
|
private CancellationTokenSource? _cancellationTokenSource = null!;
|
||||||
|
|||||||
Reference in New Issue
Block a user