Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove LocateOwner from HoverInfoService #9112

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Diagnostics;
using System.Linq;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Legacy;
using Microsoft.AspNetCore.Razor.Language.Syntax;
using Microsoft.AspNetCore.Razor.LanguageServer.Extensions;
using Microsoft.AspNetCore.Razor.LanguageServer.Tooltip;
Expand Down Expand Up @@ -68,23 +67,28 @@ public HoverInfoService(

var syntaxTree = codeDocument.GetSyntaxTree();

var change = new SourceChange(location.AbsoluteIndex, length: 0, newText: "");
var owner = syntaxTree.Root.LocateOwner(change);

var owner = syntaxTree.Root.FindInnermostNode(location.AbsoluteIndex);
if (owner is null)
{
Debug.Fail("Owner should never be null.");
return null;
}

var parent = owner.Parent;
// For cases where the point in the middle of an attribute,
// such as <any tes$$t=""></any>
// the node desired is the *AttributeSyntax
if (owner.Kind is SyntaxKind.MarkupTextLiteral)
{
owner = owner.Parent;
}

var position = new Position(location.LineIndex, location.CharacterIndex);
var tagHelperDocumentContext = codeDocument.GetTagHelperContext();

var ancestors = owner.Ancestors();
var (parentTag, parentIsTagHelper) = _tagHelperFactsService.GetNearestAncestorTagInfo(ancestors);

if (_htmlFactsService.TryGetElementInfo(parent, out var containingTagNameToken, out var attributes) &&
if (_htmlFactsService.TryGetElementInfo(owner, out var containingTagNameToken, out var attributes) &&
containingTagNameToken.Span.IntersectsWith(location.AbsoluteIndex))
{
// Hovering over HTML tag name
Expand Down Expand Up @@ -112,7 +116,7 @@ public HoverInfoService(
}
}

if (_htmlFactsService.TryGetAttributeInfo(parent, out containingTagNameToken, out _, out var selectedAttributeName, out var selectedAttributeNameLocation, out attributes) &&
if (_htmlFactsService.TryGetAttributeInfo(owner, out containingTagNameToken, out _, out var selectedAttributeName, out var selectedAttributeNameLocation, out attributes) &&
selectedAttributeNameLocation?.IntersectsWith(location.AbsoluteIndex) == true)
{
// Hovering over HTML attribute name
Expand Down
Loading