@using System.Collections.Immutable
@using Microsoft.CodeAnalysis
@using SharpIDE.Application.Features.Analysis
@using SharpIDE.Application.Features.SolutionDiscovery
@using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence
@if (_diagnostics.Length is not 0)
{
@foreach (var diagnostic in _diagnostics)
{
@diagnostic.GetMessage()
@diagnostic.Id
}
}
@code {
[Parameter, EditorRequired]
public SharpIdeProjectModel ProjectModel { get; set; } = null!;
[Parameter]
public EventCallback OnFileSelected { get; set; }
private ImmutableArray _diagnostics = [];
private static Color GetDiagnosticIconColour(Diagnostic diagnostic) => diagnostic.Severity switch
{
DiagnosticSeverity.Error => Color.Error,
DiagnosticSeverity.Warning => Color.Warning,
DiagnosticSeverity.Info => Color.Info,
_ => Color.Info
};
private async Task OpenDocumentContainingDiagnostic(Diagnostic diagnostic)
{
// TODO: probably store a flat list of all files in each project to avoid recursion
var file = ProjectModel.Files
.Concat(ProjectModel.Folders.SelectMany(f => f.GetAllFiles()))
.Single(s => s.Path == diagnostic.Location.SourceTree?.GetMappedLineSpan(diagnostic.Location.SourceSpan).Path);
await OnFileSelected.InvokeAsync(file);
}
protected override async Task OnInitializedAsync()
{
var diagnostics = await RoslynAnalysis.GetProjectDiagnostics(ProjectModel);
_diagnostics = diagnostics;
}
}