From ef5a4c4a649c20e70decccf3e9107db9251f3fc4 Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Mon, 18 Aug 2025 18:20:15 +1000 Subject: [PATCH] display underline for diagnostics --- .../Features/Analysis/RoslynAnalysis.cs | 18 +++++++ .../VsPersistence/SharpIdeModels.cs | 11 ++++ src/SharpIDE.Godot/IdeRoot.cs | 16 ++++-- src/SharpIDE.Godot/IdeRoot.tscn | 2 +- src/SharpIDE.Godot/SharpIdeCodeEdit.cs | 50 +++++++++++++------ 5 files changed, 76 insertions(+), 21 deletions(-) diff --git a/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs b/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs index 7b97195..f8c35e1 100644 --- a/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs +++ b/src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs @@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.MSBuild; using Microsoft.CodeAnalysis.Text; using NuGet.Packaging; +using SharpIDE.Application.Features.SolutionDiscovery; using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; namespace SharpIDE.Application.Features.Analysis; @@ -125,6 +126,23 @@ public static class RoslynAnalysis return diagnostics; } + public static async Task> GetDocumentDiagnostics(SharpIdeFile fileModel) + { + await _solutionLoadedTcs.Task; + var cancellationToken = CancellationToken.None; + var project = _workspace!.CurrentSolution.Projects.Single(s => s.FilePath == ((IChildSharpIdeNode)fileModel).GetNearestProjectNode()!.FilePath); + var document = project.Documents.Single(s => s.FilePath == fileModel.Path); + //var document = _workspace!.CurrentSolution.GetDocument(fileModel.Path); + Guard.Against.Null(document, nameof(document)); + + var semanticModel = await document.GetSemanticModelAsync(cancellationToken); + Guard.Against.Null(semanticModel, nameof(semanticModel)); + + var diagnostics = semanticModel.GetDiagnostics(cancellationToken: cancellationToken); + diagnostics = diagnostics.Where(d => d.Severity is not DiagnosticSeverity.Hidden).ToImmutableArray(); + return diagnostics; + } + public static async Task> GetCodeFixesAsync(Diagnostic diagnostic) { var cancellationToken = CancellationToken.None; diff --git a/src/SharpIDE.Application/Features/SolutionDiscovery/VsPersistence/SharpIdeModels.cs b/src/SharpIDE.Application/Features/SolutionDiscovery/VsPersistence/SharpIdeModels.cs index b7bf399..2d0350b 100644 --- a/src/SharpIDE.Application/Features/SolutionDiscovery/VsPersistence/SharpIdeModels.cs +++ b/src/SharpIDE.Application/Features/SolutionDiscovery/VsPersistence/SharpIdeModels.cs @@ -14,6 +14,17 @@ public interface IExpandableSharpIdeNode public interface IChildSharpIdeNode { public IExpandableSharpIdeNode Parent { get; set; } + + // TODO: Profile/redesign + public SharpIdeProjectModel? GetNearestProjectNode() + { + var current = this; + while (current is not SharpIdeProjectModel && current?.Parent is not null) + { + current = current.Parent as IChildSharpIdeNode; + } + return current as SharpIdeProjectModel; + } } public class SharpIdeSolutionModel : ISharpIdeNode, IExpandableSharpIdeNode diff --git a/src/SharpIDE.Godot/IdeRoot.cs b/src/SharpIDE.Godot/IdeRoot.cs index 32974a4..60a310f 100644 --- a/src/SharpIDE.Godot/IdeRoot.cs +++ b/src/SharpIDE.Godot/IdeRoot.cs @@ -1,12 +1,8 @@ using System; using System.IO; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Runtime.Loader; +using System.Linq; using Godot; using Microsoft.Build.Locator; -using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.Host.Mef; using SharpIDE.Application.Features.Analysis; using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; @@ -16,14 +12,18 @@ public partial class IdeRoot : Control { private Button _openSlnButton = null!; private FileDialog _fileDialog = null!; + private SharpIdeCodeEdit _sharpIdeCodeEdit = null!; public override void _Ready() { MSBuildLocator.RegisterDefaults(); _openSlnButton = GetNode