From eea4a41d7ee8fe1d6f97812fcd24c77a955bbb96 Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Mon, 11 Aug 2025 20:20:30 +1000 Subject: [PATCH] move analysis files --- .../Progress.cs | 2 +- .../Features/Analysis/RoslynTest.cs | 50 +++++++++++++++++++ .../Features/SolutionDiscovery/RoslynTest.cs | 38 -------------- src/SharpIDE.Photino/Layout/MainLayout.razor | 5 +- 4 files changed, 55 insertions(+), 40 deletions(-) rename src/SharpIDE.Application/Features/{SolutionDiscovery => Analysis}/Progress.cs (83%) create mode 100644 src/SharpIDE.Application/Features/Analysis/RoslynTest.cs delete mode 100644 src/SharpIDE.Application/Features/SolutionDiscovery/RoslynTest.cs diff --git a/src/SharpIDE.Application/Features/SolutionDiscovery/Progress.cs b/src/SharpIDE.Application/Features/Analysis/Progress.cs similarity index 83% rename from src/SharpIDE.Application/Features/SolutionDiscovery/Progress.cs rename to src/SharpIDE.Application/Features/Analysis/Progress.cs index 6634f6d..94f8edb 100644 --- a/src/SharpIDE.Application/Features/SolutionDiscovery/Progress.cs +++ b/src/SharpIDE.Application/Features/Analysis/Progress.cs @@ -1,6 +1,6 @@ using Microsoft.CodeAnalysis.MSBuild; -namespace SharpIDE.Application.Features.SolutionDiscovery; +namespace SharpIDE.Application.Features.Analysis; public class Progress : IProgress { diff --git a/src/SharpIDE.Application/Features/Analysis/RoslynTest.cs b/src/SharpIDE.Application/Features/Analysis/RoslynTest.cs new file mode 100644 index 0000000..f3d43fe --- /dev/null +++ b/src/SharpIDE.Application/Features/Analysis/RoslynTest.cs @@ -0,0 +1,50 @@ +using System.Diagnostics; +using Ardalis.GuardClauses; +using Microsoft.CodeAnalysis.Classification; +using Microsoft.CodeAnalysis.MSBuild; + +namespace SharpIDE.Application.Features.Analysis; + +public static class RoslynTest +{ + public static async Task Analyse(string solutionFilePath) + { + var workspace = MSBuildWorkspace.Create(); + var timer = Stopwatch.StartNew(); + workspace.WorkspaceFailed += (o, e) => Console.WriteLine(e.Diagnostic.Message); + var solution = await workspace.OpenSolutionAsync(solutionFilePath, new Progress()); + timer.Stop(); + Console.WriteLine($"RoslynTest: Solution loaded in {timer.ElapsedMilliseconds}ms"); + Console.WriteLine(); + + foreach (var project in solution.Projects) + { + Console.WriteLine($"Project: {project.Name}"); + foreach (var document in project.Documents) + { + Console.WriteLine($"Document: {document.Name}"); + var compilation = await project.GetCompilationAsync(); + Guard.Against.Null(compilation, nameof(compilation)); + + // Get diagnostics (built-in or custom analyzers) + var diagnostics = compilation.GetDiagnostics(); + + foreach (var diagnostic in diagnostics) + { + Console.WriteLine(diagnostic); + // Optionally run CodeFixProviders here + } + // var syntaxTree = await document.GetSyntaxTreeAsync(); + // var root = await syntaxTree!.GetRootAsync(); + // var classifiedSpans = await Classifier.GetClassifiedSpansAsync(document, root.FullSpan); + // foreach (var span in classifiedSpans) + // { + // var classifiedSpan = root.GetText().GetSubText(span.TextSpan); + // Console.WriteLine($"{span.TextSpan}: {span.ClassificationType}"); + // Console.WriteLine(classifiedSpan); + // } + } + } + + } +} diff --git a/src/SharpIDE.Application/Features/SolutionDiscovery/RoslynTest.cs b/src/SharpIDE.Application/Features/SolutionDiscovery/RoslynTest.cs deleted file mode 100644 index d506b50..0000000 --- a/src/SharpIDE.Application/Features/SolutionDiscovery/RoslynTest.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Diagnostics; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Classification; -using Microsoft.CodeAnalysis.MSBuild; - -namespace SharpIDE.Application.Features.SolutionDiscovery; - -public static class RoslynTest -{ - public static async Task Analyse(string solutionFilePath) - { - var workspace = MSBuildWorkspace.Create(); - var timer = Stopwatch.StartNew(); - var solution = await workspace.OpenSolutionAsync(solutionFilePath, new Progress()); - timer.Stop(); - Console.WriteLine($"Solution loaded in {timer.ElapsedMilliseconds}ms"); - Console.WriteLine(); - - // foreach (var project in solution.Projects) - // { - // Console.WriteLine($"Project: {project.Name}"); - // foreach (var document in project.Documents) - // { - // Console.WriteLine($"Document: {document.Name}"); - // var syntaxTree = await document.GetSyntaxTreeAsync(); - // var root = await syntaxTree!.GetRootAsync(); - // var classifiedSpans = await Classifier.GetClassifiedSpansAsync(document, root.FullSpan); - // foreach (var span in classifiedSpans) - // { - // var classifiedSpan = root.GetText().GetSubText(span.TextSpan); - // Console.WriteLine($"{span.TextSpan}: {span.ClassificationType}"); - // Console.WriteLine(classifiedSpan); - // } - // } - // } - - } -} diff --git a/src/SharpIDE.Photino/Layout/MainLayout.razor b/src/SharpIDE.Photino/Layout/MainLayout.razor index 436366a..afda840 100644 --- a/src/SharpIDE.Photino/Layout/MainLayout.razor +++ b/src/SharpIDE.Photino/Layout/MainLayout.razor @@ -1,4 +1,6 @@ -@using SharpIDE.Application.Features.Build +@using Microsoft.Build.Tasks +@using SharpIDE.Application.Features.Analysis +@using SharpIDE.Application.Features.Build @using SharpIDE.Application.Features.Events @using SharpIDE.Application.Features.SolutionDiscovery @using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence @@ -150,6 +152,7 @@ var solutionModel = await VsPersistenceMapper.GetSolutionModel(_solutionFilePath); _solutionModel = solutionModel; + await RoslynTest.Analyse(_solutionFilePath); } private CancellationTokenSource? _cancellationTokenSource = null!;