Skip to content

Commit 5707fd9

Browse files
committed
PR Feedback
1 parent e0db8d1 commit 5707fd9

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/CodeActions/Razor/ExtractToNewComponentCodeActionProvider.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using System.Text;
1010
using System.Threading;
1111
using System.Threading.Tasks;
12-
using ICSharpCode.Decompiler.CSharp.Syntax;
1312
using Microsoft.AspNetCore.Razor.Language;
1413
using Microsoft.AspNetCore.Razor.Language.Components;
1514
using Microsoft.AspNetCore.Razor.Language.Extensions;
@@ -108,6 +107,7 @@ private static bool IsInsideProperHtmlContent(RazorCodeActionContext context, Ma
108107
{
109108
return true;
110109
}
110+
111111
return context.Location.AbsoluteIndex > startElementNode.StartTag.Span.End &&
112112
context.Location.AbsoluteIndex < startElementNode.EndTag.SpanStart;
113113
}
@@ -128,7 +128,6 @@ private static bool IsInsideProperHtmlContent(RazorCodeActionContext context, Ma
128128
}
129129

130130
var endOwner = syntaxTree.Root.FindInnermostNode(endLocation.Value.AbsoluteIndex, true);
131-
132131
if (endOwner is null)
133132
{
134133
return null;
@@ -206,10 +205,11 @@ private static void ProcessMultiPointSelection(MarkupElementSyntax startElementN
206205

207206
private static SourceLocation? GetEndLocation(Position selectionEnd, RazorCodeDocument codeDocument, ILogger logger)
208207
{
209-
if (!selectionEnd.TryGetSourceLocation(codeDocument.GetSourceText(), logger, out var location))
208+
if (!selectionEnd.TryGetSourceLocation(codeDocument.Source.Text, logger, out var location))
210209
{
211210
return null;
212211
}
212+
213213
return location;
214214
}
215215

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

239-
foreach (var child in nearestCommonAncestor.ChildNodes().Where(node => node.Kind == SyntaxKind.MarkupElement))
239+
foreach (var child in nearestCommonAncestor.ChildNodes().Where(static node => node.Kind == SyntaxKind.MarkupElement))
240240
{
241241
var childSpan = child.Span;
242242

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/CodeActions/Razor/ExtractToNewComponentCodeActionProviderTest.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,20 @@ public async Task Handle_MultiPointSelection_ReturnsNotEmpty()
155155
var location = new SourceLocation(cursorPosition, -1, -1);
156156
var context = CreateRazorCodeActionContext(request, location, documentPath, contents);
157157

158+
AddMultiPointSelectionToContext(context, selectionSpan);
159+
158160
var provider = new ExtractToNewComponentCodeActionProvider(LoggerFactory);
159161

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

163165
// Assert
164166
Assert.NotEmpty(commandOrCodeActionContainer);
167+
var codeAction = Assert.Single(commandOrCodeActionContainer);
168+
var razorCodeActionResolutionParams = ((JsonElement)codeAction.Data!).Deserialize<RazorCodeActionResolutionParams>();
169+
Assert.NotNull(razorCodeActionResolutionParams);
170+
var actionParams = ((JsonElement)razorCodeActionResolutionParams.Data).Deserialize<ExtractToNewComponentCodeActionParams>();
171+
Assert.NotNull(actionParams);
165172
}
166173

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

204-
AddMultiPointSelectionToContext(ref context, selectionSpan);
211+
AddMultiPointSelectionToContext(context, selectionSpan);
205212

206213
var provider = new ExtractToNewComponentCodeActionProvider(LoggerFactory);
207214

@@ -249,10 +256,9 @@ private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionP
249256
return context;
250257
}
251258

252-
253-
private static void AddMultiPointSelectionToContext(ref RazorCodeActionContext context, TextSpan selectionSpan)
259+
private static void AddMultiPointSelectionToContext(RazorCodeActionContext context, TextSpan selectionSpan)
254260
{
255-
var sourceText = context.CodeDocument.GetSourceText();
261+
var sourceText = context.CodeDocument.Source.Text;
256262
var startLinePosition = sourceText.Lines.GetLinePosition(selectionSpan.Start);
257263
var startPosition = new Position(startLinePosition.Line, startLinePosition.Character);
258264

src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/FileUtilities.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ internal static class FileUtilities
1919
public static string GenerateUniquePath(string path, string extension)
2020
{
2121
// Add check for rooted path in the future, currently having issues in platforms other than Windows.
22-
//if (!Path.IsPathRooted(path))
23-
//{
24-
// throw new ArgumentException("The path is not rooted.", nameof(path));
25-
//}
22+
// See: https://github.com/dotnet/razor/issues/10684
2623

2724
var directoryName = Path.GetDirectoryName(path).AssumeNotNull();
2825
var baseFileName = Path.GetFileNameWithoutExtension(path);

0 commit comments

Comments
 (0)