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

Some Cleanup For ExtractToComponent #11008

Merged
merged 6 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -67,7 +67,7 @@ public Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(
}

var tree = context.CodeDocument.GetSyntaxTree();
var node = tree.Root.FindInnermostNode(context.Location.AbsoluteIndex);
var node = tree.Root.FindInnermostNode(context.StartLocation.AbsoluteIndex);
var isInImplicitExpression = node?.AncestorsAndSelf().Any(n => n is CSharpImplicitExpressionSyntax) ?? false;

var allowList = isInImplicitExpression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static bool TryGetOwner(RazorCodeActionContext context, [NotNullWhen(true)] out
return false;
}

owner = syntaxTree.Root.FindInnermostNode(context.Location.AbsoluteIndex);
owner = syntaxTree.Root.FindInnermostNode(context.StartLocation.AbsoluteIndex);
if (owner is null)
{
Debug.Fail("Owner should never be null.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,22 @@ public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, V
request.Range = vsCodeActionContext.SelectionRange;
}

if (!sourceText.TryGetSourceLocation(request.Range.Start, out var location))
if (!sourceText.TryGetSourceLocation(request.Range.Start, out var startLocation))
{
return null;
}

if (!sourceText.TryGetSourceLocation(request.Range.End, out var endLocation))
{
endLocation = startLocation;
}

var context = new RazorCodeActionContext(
request,
documentSnapshot,
codeDocument,
location,
startLocation,
endLocation,
sourceText,
_languageServerFeatureOptions.SupportsFileManipulation,
_supportsCodeActionResolve);
Expand All @@ -177,7 +183,7 @@ public void ApplyCapabilities(VSInternalServerCapabilities serverCapabilities, V

private async Task<ImmutableArray<RazorVSInternalCodeAction>> GetDelegatedCodeActionsAsync(DocumentContext documentContext, RazorCodeActionContext context, Guid correlationId, CancellationToken cancellationToken)
{
var languageKind = context.CodeDocument.GetLanguageKind(context.Location.AbsoluteIndex, rightAssociative: false);
var languageKind = context.CodeDocument.GetLanguageKind(context.StartLocation.AbsoluteIndex, rightAssociative: false);

// No point delegating if we're in a Razor context
if (languageKind == RazorLanguageKind.Razor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text.Json.Serialization;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models;

// NOTE: As mentioned before, these have changed in future PRs, where much of the Provider logic was moved to the resolver.
// The last three properties are not used in the current implementation.
internal sealed class ExtractToComponentCodeActionParams
{
[JsonPropertyName("uri")]
public required Uri Uri { get; set; }

[JsonPropertyName("extractStart")]
public int ExtractStart { get; set; }
[JsonPropertyName("start")]
public int Start { get; set; }

[JsonPropertyName("extractEnd")]
public int ExtractEnd { get; set; }
[JsonPropertyName("end")]
public int End { get; set; }

[JsonPropertyName("namespace")]
public required string Namespace { get; set; }

[JsonPropertyName("usingDirectives")]
public required List<string> usingDirectives { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal sealed class ComponentAccessibilityCodeActionProvider : IRazorCodeActio
public async Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorCodeActionContext context, CancellationToken cancellationToken)
{
// Locate cursor
var node = context.CodeDocument.GetSyntaxTree().Root.FindInnermostNode(context.Location.AbsoluteIndex);
var node = context.CodeDocument.GetSyntaxTree().Root.FindInnermostNode(context.StartLocation.AbsoluteIndex);
if (node is null)
{
return [];
Expand All @@ -44,7 +44,7 @@ public async Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorC
return [];
}

if (context.Location.AbsoluteIndex < startTag.SpanStart)
if (context.StartLocation.AbsoluteIndex < startTag.SpanStart)
{
// Cursor is before the start tag, so we shouldn't show a light bulb. This can happen
// in cases where the cursor is in whitespace at the beginning of the document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorCodeAct
return SpecializedTasks.EmptyImmutableArray<RazorVSInternalCodeAction>();
}

var owner = syntaxTree.Root.FindInnermostNode(context.Location.AbsoluteIndex);
var owner = syntaxTree.Root.FindInnermostNode(context.StartLocation.AbsoluteIndex);
if (owner is null)
{
_logger.LogWarning($"Owner should never be null.");
Expand Down Expand Up @@ -84,7 +84,7 @@ public Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorCodeAct
}

// Do not provide code action if the cursor is inside the code block
if (context.Location.AbsoluteIndex > csharpCodeBlockNode.SpanStart)
if (context.StartLocation.AbsoluteIndex > csharpCodeBlockNode.SpanStart)
{
return SpecializedTasks.EmptyImmutableArray<RazorVSInternalCodeAction>();
}
Expand Down
Loading
Loading