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>
|
||||
|
||||
@@ -53,12 +53,12 @@
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await Task.Run(() => LoadSolution("D:/matth/Documents/Git/amazon/ClientPortal.sln"));
|
||||
await Task.Run(() => LoadSolution("C:/Users/Matthew/Documents/Git/amazon/ClientPortal.sln"));
|
||||
}
|
||||
|
||||
private void LoadSolution(string solutionPath)
|
||||
{
|
||||
var solutionFile = GetNodesInSolution.ParseSolutionFileFromPath("D:/matth/Documents/Git/amazon/ClientPortal.sln");
|
||||
var solutionFile = GetNodesInSolution.ParseSolutionFileFromPath("C:/Users/Matthew/Documents/Git/amazon/ClientPortal.sln");
|
||||
ArgumentNullException.ThrowIfNull(solutionFile);
|
||||
_solutionFile = solutionFile;
|
||||
var rootNodes = solutionFile.ProjectsByGuid.Values.Where(p => p.ParentProjectGuid == null).OrderBy(s => s.ProjectName).ToList();
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
@page "/"
|
||||
@using SharpIDE.Application.Features.SolutionDiscovery
|
||||
|
||||
<CodeViewer FilePath="D:\matth\Documents\Git\amazon\src\Utilities\ClientPortal.Utilities.DebugConsole\DataversePlayground.cs" />
|
||||
<CodeViewer FilePath="C:\Users\Matthew\Documents\Git\amazon\src\Utilities\ClientPortal.Utilities.DebugConsole\DataversePlayground.cs" />
|
||||
|
||||
@code
|
||||
{
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await RoslynTest.Analyse("C:/Users/Matthew/Documents/Git/StatusApp/StatusApp.sln");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user