add roslyn
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Build" Version="17.12.6" ExcludeAssets="runtime" />
|
||||
<PackageReference Include="Microsoft.Build.Locator" Version="1.7.8" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.12.0" />
|
||||
<PackageReference Include="NuGet.Protocol" Version="6.12.1" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user