From 5bd6b64019048879bac53a0f8ea4c7c17ea725dc Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Sun, 17 Aug 2025 12:34:54 +1000 Subject: [PATCH] open file from diagnostic --- .../Features/SolutionDiscovery/TreeMapperV2.cs | 5 +++++ .../Components/Problems/ProblemsPanel.razor | 12 ++++++++++-- .../Problems/ProjectProblemComponent.razor | 13 ++++++++++++- src/SharpIDE.Photino/Layout/MainLayout.razor | 2 +- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/SharpIDE.Application/Features/SolutionDiscovery/TreeMapperV2.cs b/src/SharpIDE.Application/Features/SolutionDiscovery/TreeMapperV2.cs index 2604eed..a3f6112 100644 --- a/src/SharpIDE.Application/Features/SolutionDiscovery/TreeMapperV2.cs +++ b/src/SharpIDE.Application/Features/SolutionDiscovery/TreeMapperV2.cs @@ -4,6 +4,11 @@ namespace SharpIDE.Application.Features.SolutionDiscovery; public static class TreeMapperV2 { + public static IEnumerable GetAllFiles(this SharpIdeFolder folder) + { + return folder.Files + .Concat(folder.Folders.SelectMany(sub => sub.GetAllFiles())); + } public static List GetSubFolders(string csprojectPath) { var projectDirectory = Path.GetDirectoryName(csprojectPath)!; diff --git a/src/SharpIDE.Photino/Components/Problems/ProblemsPanel.razor b/src/SharpIDE.Photino/Components/Problems/ProblemsPanel.razor index b11a623..e6f8366 100644 --- a/src/SharpIDE.Photino/Components/Problems/ProblemsPanel.razor +++ b/src/SharpIDE.Photino/Components/Problems/ProblemsPanel.razor @@ -1,9 +1,11 @@ -@using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence +@using SharpIDE.Application.Features.SolutionDiscovery +@using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence + @foreach (var project in SolutionModel.AllProjects) { - + } @@ -11,4 +13,10 @@ @code { [Parameter, EditorRequired] public SharpIdeSolutionModel SolutionModel { get; set; } = null!; + + [Parameter, EditorRequired] + public SharpIdeFile SelectedFile { get; set; } = null!; + + [Parameter] + public EventCallback SelectedFileChanged { get; set; } } diff --git a/src/SharpIDE.Photino/Components/Problems/ProjectProblemComponent.razor b/src/SharpIDE.Photino/Components/Problems/ProjectProblemComponent.razor index dd1dcc1..eada17e 100644 --- a/src/SharpIDE.Photino/Components/Problems/ProjectProblemComponent.razor +++ b/src/SharpIDE.Photino/Components/Problems/ProjectProblemComponent.razor @@ -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 SelectedFileChanged { get; set; } + private ImmutableArray _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; } - } diff --git a/src/SharpIDE.Photino/Layout/MainLayout.razor b/src/SharpIDE.Photino/Layout/MainLayout.razor index bb78ba2..699cabc 100644 --- a/src/SharpIDE.Photino/Layout/MainLayout.razor +++ b/src/SharpIDE.Photino/Layout/MainLayout.razor @@ -83,7 +83,7 @@ @if (_solutionFilePath is not null) { - +