move analysis files
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
using Microsoft.CodeAnalysis.MSBuild;
|
using Microsoft.CodeAnalysis.MSBuild;
|
||||||
|
|
||||||
namespace SharpIDE.Application.Features.SolutionDiscovery;
|
namespace SharpIDE.Application.Features.Analysis;
|
||||||
|
|
||||||
public class Progress : IProgress<ProjectLoadProgress>
|
public class Progress : IProgress<ProjectLoadProgress>
|
||||||
{
|
{
|
||||||
50
src/SharpIDE.Application/Features/Analysis/RoslynTest.cs
Normal file
50
src/SharpIDE.Application/Features/Analysis/RoslynTest.cs
Normal file
@@ -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);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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.Events
|
||||||
@using SharpIDE.Application.Features.SolutionDiscovery
|
@using SharpIDE.Application.Features.SolutionDiscovery
|
||||||
@using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence
|
@using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence
|
||||||
@@ -150,6 +152,7 @@
|
|||||||
|
|
||||||
var solutionModel = await VsPersistenceMapper.GetSolutionModel(_solutionFilePath);
|
var solutionModel = await VsPersistenceMapper.GetSolutionModel(_solutionFilePath);
|
||||||
_solutionModel = solutionModel;
|
_solutionModel = solutionModel;
|
||||||
|
await RoslynTest.Analyse(_solutionFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CancellationTokenSource? _cancellationTokenSource = null!;
|
private CancellationTokenSource? _cancellationTokenSource = null!;
|
||||||
|
|||||||
Reference in New Issue
Block a user