fix symbol hover
This commit is contained in:
@@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.CodeActions;
|
|||||||
using Microsoft.CodeAnalysis.CodeFixes;
|
using Microsoft.CodeAnalysis.CodeFixes;
|
||||||
using Microsoft.CodeAnalysis.CodeRefactorings;
|
using Microsoft.CodeAnalysis.CodeRefactorings;
|
||||||
using Microsoft.CodeAnalysis.Completion;
|
using Microsoft.CodeAnalysis.Completion;
|
||||||
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
using Microsoft.CodeAnalysis.FindSymbols;
|
using Microsoft.CodeAnalysis.FindSymbols;
|
||||||
using Microsoft.CodeAnalysis.Host.Mef;
|
using Microsoft.CodeAnalysis.Host.Mef;
|
||||||
using Microsoft.CodeAnalysis.MSBuild;
|
using Microsoft.CodeAnalysis.MSBuild;
|
||||||
@@ -791,7 +792,25 @@ public class RoslynAnalysis(ILogger<RoslynAnalysis> logger, BuildService buildSe
|
|||||||
return (null, null);
|
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));
|
_logger.LogInformation("Symbol found: {SymbolName} ({SymbolKind}) - {SymbolDisplayString}", symbol.Name, symbol.Kind, symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
|
||||||
return (symbol, linePositionSpan);
|
return (symbol, linePositionSpan);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -268,9 +268,11 @@ public partial class SharpIdeCodeEdit : CodeEdit
|
|||||||
symbolNameHoverWindow.PopupWindow = true;
|
symbolNameHoverWindow.PopupWindow = true;
|
||||||
symbolNameHoverWindow.MinimizeDisabled = true;
|
symbolNameHoverWindow.MinimizeDisabled = true;
|
||||||
symbolNameHoverWindow.MaximizeDisabled = 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 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);
|
symbolNameHoverWindow.Size = new Vector2I(endSymbolCharRect.End.X - startSymbolCharRect.Position.X, lineHeight);
|
||||||
|
|
||||||
var globalPosition = GetGlobalPosition();
|
var globalPosition = GetGlobalPosition();
|
||||||
|
|||||||
Reference in New Issue
Block a user