open file from diagnostic

This commit is contained in:
Matt Parker
2025-08-17 12:34:54 +10:00
parent 1856b0b2db
commit 5bd6b64019
4 changed files with 28 additions and 4 deletions

View File

@@ -4,6 +4,11 @@ namespace SharpIDE.Application.Features.SolutionDiscovery;
public static class TreeMapperV2
{
public static IEnumerable<SharpIdeFile> GetAllFiles(this SharpIdeFolder folder)
{
return folder.Files
.Concat(folder.Folders.SelectMany(sub => sub.GetAllFiles()));
}
public static List<SharpIdeFolder> GetSubFolders(string csprojectPath)
{
var projectDirectory = Path.GetDirectoryName(csprojectPath)!;

View File

@@ -1,9 +1,11 @@
@using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence
@using SharpIDE.Application.Features.SolutionDiscovery
@using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence
<MudStack Style="height: 100%">
<MudTreeView T="string" Dense="true" ExpandOnClick="true">
@foreach (var project in SolutionModel.AllProjects)
{
<ProjectProblemComponent ProjectModel="@project"/>
<ProjectProblemComponent ProjectModel="@project" SelectedFile="@SelectedFile" SelectedFileChanged="@SelectedFileChanged"/>
}
</MudTreeView>
</MudStack>
@@ -11,4 +13,10 @@
@code {
[Parameter, EditorRequired]
public SharpIdeSolutionModel SolutionModel { get; set; } = null!;
[Parameter, EditorRequired]
public SharpIdeFile SelectedFile { get; set; } = null!;
[Parameter]
public EventCallback<SharpIdeFile> SelectedFileChanged { get; set; }
}

View File

@@ -1,6 +1,7 @@
@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)
@@ -24,6 +25,12 @@
[Parameter, EditorRequired]
public SharpIdeProjectModel ProjectModel { get; set; } = null!;
[Parameter, EditorRequired]
public SharpIdeFile SelectedFile { get; set; } = null!;
[Parameter]
public EventCallback<SharpIdeFile> SelectedFileChanged { get; set; }
private ImmutableArray<Diagnostic> _diagnostics = [];
private static Color GetDiagnosticIconColour(Diagnostic diagnostic) => diagnostic.Severity switch
@@ -36,7 +43,12 @@
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 SelectedFileChanged.InvokeAsync(file);
}
protected override async Task OnInitializedAsync()
@@ -44,5 +56,4 @@
var diagnostics = await RoslynAnalysis.GetProjectDiagnostics(ProjectModel);
_diagnostics = diagnostics;
}
}

View File

@@ -83,7 +83,7 @@
@if (_solutionFilePath is not null)
{
<DisplayNoneComponent Visible="@(_selectedBottomPanel is BottomPanelType.Problems)">
<ProblemsPanel SolutionModel="@_solutionModel" />
<ProblemsPanel SolutionModel="@_solutionModel" @bind-SelectedFile="@_selectedFile" />
</DisplayNoneComponent>
<DisplayNoneComponent Visible="@(_selectedBottomPanel is BottomPanelType.Run)">
<RunPanel SolutionModel="@_solutionModel"/>