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 locate owner usage from document context #9235

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
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 @@ -160,7 +160,7 @@ public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, V
return (null, null);
}

var node = owner.Parent?.FirstAncestorOrSelf<SyntaxNode>(n =>
var node = owner.FirstAncestorOrSelf<SyntaxNode>(n =>
n.Kind == SyntaxKind.MarkupTagHelperStartTag ||
n.Kind == SyntaxKind.MarkupTagHelperEndTag);
if (node is null)
Expand All @@ -178,16 +178,21 @@ public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, V

string? propertyName = null;

if (!ignoreAttributes)
if (!ignoreAttributes && node is MarkupTagHelperStartTagSyntax startTag)
{
// Include attributes where the end index also matches, since GetSyntaxNodeAsync will consider that the start tag but we behave
// as if the user wants to go to the attribute definitiion.
// ie: <Componet attribute$$></Component>
var selectedAttribute = startTag.Attributes.FirstOrDefault(a => a.Span.Contains(absoluteIndex) || a.Span.End == absoluteIndex);

// If we're on an attribute then just validate against the attribute name
if (owner.Parent is MarkupTagHelperAttributeSyntax attribute)
if (selectedAttribute is MarkupTagHelperAttributeSyntax attribute)
{
// Normal attribute, ie <Component attribute=value />
name = attribute.Name;
propertyName = attribute.TagHelperAttributeInfo.Name;
}
else if (owner.Parent is MarkupMinimizedTagHelperAttributeSyntax minimizedAttribute)
else if (selectedAttribute is MarkupMinimizedTagHelperAttributeSyntax minimizedAttribute)
{
// Minimized attribute, ie <Component attribute />
name = minimizedAttribute.Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using System.Threading;
using System.Threading.Tasks;
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.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Workspaces.Extensions;
using Microsoft.CodeAnalysis.Text;
Expand Down Expand Up @@ -108,13 +108,12 @@ public virtual async Task<SourceText> GetHtmlSourceTextAsync(CancellationToken c

public async Task<SyntaxNode?> GetSyntaxNodeAsync(int absoluteIndex, CancellationToken cancellationToken)
{
var change = new SourceChange(absoluteIndex, length: 0, newText: string.Empty);
var syntaxTree = await GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
if (syntaxTree.Root is null)
{
return null;
}

return syntaxTree.Root.LocateOwner(change);
return syntaxTree.Root.FindInnermostNode(absoluteIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private static bool BindingContainsTagHelper(TagHelperDescriptor tagHelper, TagH
return null;
}

var node = owner.Parent?.FirstAncestorOrSelf<SyntaxNode>(n => n.Kind == SyntaxKind.MarkupTagHelperStartTag);
var node = owner.FirstAncestorOrSelf<SyntaxNode>(n => n.Kind == SyntaxKind.MarkupTagHelperStartTag);
if (node is not MarkupTagHelperStartTagSyntax tagHelperStartTag)
{
return null;
Expand Down