display underline for diagnostics

This commit is contained in:
Matt Parker
2025-08-18 18:20:15 +10:00
parent c0c240cf0e
commit ef5a4c4a64
5 changed files with 76 additions and 21 deletions

View File

@@ -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<ImmutableArray<Diagnostic>> 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<ImmutableArray<CodeAction>> GetCodeFixesAsync(Diagnostic diagnostic)
{
var cancellationToken = CancellationToken.None;

View File

@@ -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