From 57e837fbfbee7d7b18fc15dd22ebf576a23b502f Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Mon, 27 Oct 2025 19:02:29 +1000 Subject: [PATCH] display symbol lookup popup at mouse --- .../CodeEditor/SharpIdeCodeEdit_SymbolHover.cs | 12 ++++-------- .../CodeEditor/SharpIdeCodeEdit_SymbolLookup.cs | 10 +++++++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit_SymbolHover.cs b/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit_SymbolHover.cs index 17b53dc..8ebbb63 100644 --- a/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit_SymbolHover.cs +++ b/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit_SymbolHover.cs @@ -19,13 +19,11 @@ public partial class SharpIdeCodeEdit { if (HasFocus() is false) return; // only show if we have focus, every tab is currently listening for this event, maybe find a better way - var globalMousePosition = - GetGlobalMousePosition(); // don't breakpoint before this, else your mouse position will be wrong + var globalMousePosition = GetGlobalMousePosition(); // don't breakpoint before this, else your mouse position will be wrong var lineHeight = GetLineHeight(); GD.Print($"Symbol hovered: {symbol} at line {line}, column {column}"); - var (roslynSymbol, linePositionSpan) = - await _roslynAnalysis.LookupSymbol(_currentFile, new LinePosition((int)line, (int)column)); + var (roslynSymbol, linePositionSpan) = await _roslynAnalysis.LookupSymbol(_currentFile, new LinePosition((int)line, (int)column)); if (roslynSymbol is null || linePositionSpan is null) { return; @@ -47,10 +45,8 @@ public partial class SharpIdeCodeEdit // To debug location, make type a PopupPanel, and uncomment //symbolNameHoverWindow.AddThemeStyleboxOverride("panel", new StyleBoxFlat { BgColor = new Color(1, 0, 0, 0.5f) }); - var startSymbolCharRect = - GetRectAtLineColumn(linePositionSpan.Value.Start.Line, linePositionSpan.Value.Start.Character + 1); - var endSymbolCharRect = - GetRectAtLineColumn(linePositionSpan.Value.End.Line, linePositionSpan.Value.End.Character); + var startSymbolCharRect = GetRectAtLineColumn(linePositionSpan.Value.Start.Line, linePositionSpan.Value.Start.Character + 1); + var endSymbolCharRect = GetRectAtLineColumn(linePositionSpan.Value.End.Line, linePositionSpan.Value.End.Character); symbolNameHoverWindow.Size = new Vector2I(endSymbolCharRect.End.X - startSymbolCharRect.Position.X, lineHeight); var globalPosition = GetGlobalPosition(); diff --git a/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit_SymbolLookup.cs b/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit_SymbolLookup.cs index e69237e..2478c01 100644 --- a/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit_SymbolLookup.cs +++ b/src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit_SymbolLookup.cs @@ -13,6 +13,11 @@ public partial class SharpIdeCodeEdit private void OnSymbolLookup(string symbolString, long line, long column) { GD.Print($"Symbol lookup requested: {symbolString} at line {line}, column {column}"); + var globalMousePosition = GetGlobalMousePosition(); // don't breakpoint before this, else your mouse position will be wrong + var clickedCharRect = GetRectAtLineColumn((int)line, (int)column); + var globalPosition = GetGlobalPosition(); + var startSymbolCharGlobalPos = clickedCharRect.Position + globalPosition; + _ = Task.GodotRun(async () => { var (symbol, linePositionSpan, semanticInfo) = await _roslynAnalysis.LookupSymbolSemanticInfo(_currentFile, new LinePosition((int)line, (int)column)); @@ -56,7 +61,10 @@ public partial class SharpIdeCodeEdit await this.InvokeAsync(() => { AddChild(symbolLookupPopup); - symbolLookupPopup.PopupCentered(); + symbolLookupPopup.Position = new Vector2I((int)globalMousePosition.X - 5, (int)startSymbolCharGlobalPos.Y); + symbolLookupPopup.Popup(); + var currentMousePos = GetGlobalMousePosition(); + Input.WarpMouse(currentMousePos with {X = currentMousePos.X + 1}); // it seems that until the mouse moves, behind the popup can still receive mouse events, which causes symbol the hover symbol popup to appear. }); } }