refactor diagnostic

This commit is contained in:
Matt Parker
2025-10-17 21:30:52 +10:00
parent 451fd316f2
commit 96d21f75f6
2 changed files with 18 additions and 15 deletions

View File

@@ -0,0 +1,6 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
namespace SharpIDE.Application.Features.Analysis;
public readonly record struct SharpIdeDiagnostic(LinePositionSpan Span, Diagnostic Diagnostic);

View File

@@ -32,7 +32,7 @@ public partial class SharpIdeCodeEdit : CodeEdit
private CustomHighlighter _syntaxHighlighter = new(); private CustomHighlighter _syntaxHighlighter = new();
private PopupMenu _popupMenu = null!; private PopupMenu _popupMenu = null!;
private ImmutableArray<(FileLinePositionSpan fileSpan, Diagnostic diagnostic)> _diagnostics = []; private ImmutableArray<SharpIdeDiagnostic> _diagnostics = [];
private ImmutableArray<CodeAction> _currentCodeActionsInPopup = []; private ImmutableArray<CodeAction> _currentCodeActionsInPopup = [];
private bool _fileChangingSuppressBreakpointToggleEvent; private bool _fileChangingSuppressBreakpointToggleEvent;
@@ -391,14 +391,12 @@ public partial class SharpIdeCodeEdit : CodeEdit
public override void _Draw() public override void _Draw()
{ {
//UnderlineRange(_currentLine, _selectionStartCol, _selectionEndCol, new Color(1, 0, 0)); //UnderlineRange(_currentLine, _selectionStartCol, _selectionEndCol, new Color(1, 0, 0));
foreach (var (fileSpan, diagnostic) in _diagnostics) foreach (var sharpIdeDiagnostic in _diagnostics)
{ {
if (diagnostic.Location.IsInSource) var line = sharpIdeDiagnostic.Span.Start.Line;
{ var startCol = sharpIdeDiagnostic.Span.Start.Character;
var line = fileSpan.StartLinePosition.Line; var endCol = sharpIdeDiagnostic.Span.End.Character;
var startCol = fileSpan.StartLinePosition.Character; var color = sharpIdeDiagnostic.Diagnostic.Severity switch
var endCol = fileSpan.EndLinePosition.Character;
var color = diagnostic.Severity switch
{ {
DiagnosticSeverity.Error => new Color(1, 0, 0), DiagnosticSeverity.Error => new Color(1, 0, 0),
DiagnosticSeverity.Warning => new Color("ffb700"), DiagnosticSeverity.Warning => new Color("ffb700"),
@@ -407,7 +405,6 @@ public partial class SharpIdeCodeEdit : CodeEdit
UnderlineRange(line, startCol, endCol, color); UnderlineRange(line, startCol, endCol, color);
} }
} }
}
public override void _UnhandledKeyInput(InputEvent @event) public override void _UnhandledKeyInput(InputEvent @event)
{ {
@@ -450,7 +447,7 @@ public partial class SharpIdeCodeEdit : CodeEdit
} }
[RequiresGodotUiThread] [RequiresGodotUiThread]
private void SetDiagnosticsModel(ImmutableArray<(FileLinePositionSpan fileSpan, Diagnostic diagnostic)> diagnostics) private void SetDiagnosticsModel(ImmutableArray<SharpIdeDiagnostic> diagnostics)
{ {
_diagnostics = diagnostics; _diagnostics = diagnostics;
QueueRedraw(); QueueRedraw();