Skip to content

Commit

Permalink
PR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
marcarro committed Jul 30, 2024
1 parent e0db8d1 commit 5707fd9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ICSharpCode.Decompiler.CSharp.Syntax;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Components;
using Microsoft.AspNetCore.Razor.Language.Extensions;
Expand Down Expand Up @@ -108,6 +107,7 @@ private static bool IsInsideProperHtmlContent(RazorCodeActionContext context, Ma
{
return true;
}

return context.Location.AbsoluteIndex > startElementNode.StartTag.Span.End &&
context.Location.AbsoluteIndex < startElementNode.EndTag.SpanStart;
}
Expand All @@ -128,7 +128,6 @@ private static bool IsInsideProperHtmlContent(RazorCodeActionContext context, Ma
}

var endOwner = syntaxTree.Root.FindInnermostNode(endLocation.Value.AbsoluteIndex, true);

if (endOwner is null)
{
return null;
Expand Down Expand Up @@ -206,10 +205,11 @@ private static void ProcessMultiPointSelection(MarkupElementSyntax startElementN

private static SourceLocation? GetEndLocation(Position selectionEnd, RazorCodeDocument codeDocument, ILogger logger)
{
if (!selectionEnd.TryGetSourceLocation(codeDocument.GetSourceText(), logger, out var location))
if (!selectionEnd.TryGetSourceLocation(codeDocument.Source.Text, logger, out var location))
{
return null;
}

return location;
}

Expand All @@ -236,7 +236,7 @@ private static (SyntaxNode? Start, SyntaxNode? End) FindContainingSiblingPair(Sy
var startSpan = startNode.Span;
var endSpan = endNode.Span;

foreach (var child in nearestCommonAncestor.ChildNodes().Where(node => node.Kind == SyntaxKind.MarkupElement))
foreach (var child in nearestCommonAncestor.ChildNodes().Where(static node => node.Kind == SyntaxKind.MarkupElement))
{
var childSpan = child.Span;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,20 @@ public async Task Handle_MultiPointSelection_ReturnsNotEmpty()
var location = new SourceLocation(cursorPosition, -1, -1);
var context = CreateRazorCodeActionContext(request, location, documentPath, contents);

AddMultiPointSelectionToContext(context, selectionSpan);

var provider = new ExtractToNewComponentCodeActionProvider(LoggerFactory);

// Act
var commandOrCodeActionContainer = await provider.ProvideAsync(context, default);

// Assert
Assert.NotEmpty(commandOrCodeActionContainer);
var codeAction = Assert.Single(commandOrCodeActionContainer);
var razorCodeActionResolutionParams = ((JsonElement)codeAction.Data!).Deserialize<RazorCodeActionResolutionParams>();
Assert.NotNull(razorCodeActionResolutionParams);
var actionParams = ((JsonElement)razorCodeActionResolutionParams.Data).Deserialize<ExtractToNewComponentCodeActionParams>();
Assert.NotNull(actionParams);
}

[Fact]
Expand Down Expand Up @@ -201,7 +208,7 @@ public async Task Handle_MultiPointSelectionWithEndAfterElement_ReturnsCurrentEl
var location = new SourceLocation(cursorPosition, -1, -1);
var context = CreateRazorCodeActionContext(request, location, documentPath, contents);

AddMultiPointSelectionToContext(ref context, selectionSpan);
AddMultiPointSelectionToContext(context, selectionSpan);

var provider = new ExtractToNewComponentCodeActionProvider(LoggerFactory);

Expand Down Expand Up @@ -249,10 +256,9 @@ private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionP
return context;
}


private static void AddMultiPointSelectionToContext(ref RazorCodeActionContext context, TextSpan selectionSpan)
private static void AddMultiPointSelectionToContext(RazorCodeActionContext context, TextSpan selectionSpan)
{
var sourceText = context.CodeDocument.GetSourceText();
var sourceText = context.CodeDocument.Source.Text;
var startLinePosition = sourceText.Lines.GetLinePosition(selectionSpan.Start);
var startPosition = new Position(startLinePosition.Line, startLinePosition.Character);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ internal static class FileUtilities
public static string GenerateUniquePath(string path, string extension)
{
// Add check for rooted path in the future, currently having issues in platforms other than Windows.
//if (!Path.IsPathRooted(path))
//{
// throw new ArgumentException("The path is not rooted.", nameof(path));
//}
// See: https://github.com/dotnet/razor/issues/10684

var directoryName = Path.GetDirectoryName(path).AssumeNotNull();
var baseFileName = Path.GetFileNameWithoutExtension(path);
Expand Down

0 comments on commit 5707fd9

Please sign in to comment.