fix symbol hover

This commit is contained in:
Matt Parker
2025-10-27 18:06:50 +10:00
parent 797589afad
commit 28f2d8ca38
2 changed files with 23 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.MSBuild;
@@ -791,7 +792,25 @@ public class RoslynAnalysis(ILogger<RoslynAnalysis> logger, BuildService buildSe
return (null, null);
}
var linePositionSpan = root.SyntaxTree.GetLineSpan(node.Span).Span;
var span = node switch
{
MethodDeclarationSyntax methodDecl => methodDecl.Identifier.Span,
ClassDeclarationSyntax classDecl => classDecl.Identifier.Span,
StructDeclarationSyntax structDecl => structDecl.Identifier.Span,
InterfaceDeclarationSyntax interfaceDecl => interfaceDecl.Identifier.Span,
EnumDeclarationSyntax enumDecl => enumDecl.Identifier.Span,
DelegateDeclarationSyntax delegateDecl => delegateDecl.Identifier.Span,
ConstructorDeclarationSyntax constructorDecl => constructorDecl.Identifier.Span,
DestructorDeclarationSyntax destructorDecl => destructorDecl.Identifier.Span,
PropertyDeclarationSyntax propDecl => propDecl.Identifier.Span,
EventDeclarationSyntax eventDecl => eventDecl.Identifier.Span,
VariableDeclaratorSyntax variableDecl => variableDecl.Identifier.Span,
AccessorDeclarationSyntax accessorDecl => accessorDecl.Keyword.Span,
IndexerDeclarationSyntax indexerDecl => indexerDecl.ThisKeyword.Span,
_ => node.Span
};
var linePositionSpan = root.SyntaxTree.GetLineSpan(span).Span;
_logger.LogInformation("Symbol found: {SymbolName} ({SymbolKind}) - {SymbolDisplayString}", symbol.Name, symbol.Kind, symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
return (symbol, linePositionSpan);
}

View File

@@ -268,9 +268,11 @@ public partial class SharpIdeCodeEdit : CodeEdit
symbolNameHoverWindow.PopupWindow = true;
symbolNameHoverWindow.MinimizeDisabled = true;
symbolNameHoverWindow.MaximizeDisabled = true;
// 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 + 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();