Skip to content

Commit 41f0ce1

Browse files
committed
Change to FindContainingSiblingPair
1 parent 3455a0e commit 41f0ce1

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private static SelectionAnalysisResult TryAnalyzeSelection(RazorCodeDocument cod
189189

190190
endElementNode ??= startElementNode;
191191

192-
var success = TryProcessMultiPointSelection(startElementNode,
192+
var success = TryProcessSelection(startElementNode,
193193
endElementNode,
194194
codeDocument,
195195
actionParams,
@@ -267,7 +267,7 @@ private static (MarkupSyntaxNode? Start, MarkupSyntaxNode? End) GetStartAndEndEl
267267
}
268268

269269
// Correct selection to include the current node if the selection ends at the "edge" (i.e. immediately after the ">") of a tag.
270-
if (string.IsNullOrWhiteSpace(endOwner.ToFullString()) && endOwner.TryGetPreviousSibling(out var previousSibling))
270+
if (endOwner is MarkupTextLiteralSyntax && endOwner.ContainsOnlyWhitespace() && endOwner.TryGetPreviousSibling(out var previousSibling))
271271
{
272272
endOwner = previousSibling;
273273
}
@@ -286,16 +286,16 @@ private static (MarkupSyntaxNode? Start, MarkupSyntaxNode? End) GetStartAndEndEl
286286
}
287287

288288
/// <summary>
289-
/// Processes a multi-point selection, providing the start and end of the extraction range if successful.
289+
/// Processes a selection, providing the start and end of the extraction range if successful.
290290
/// </summary>
291291
/// <param name="startElementNode">The starting element of the selection.</param>
292-
/// <param name="endElementNode">The ending element of the selection, if it exists.</param>
292+
/// <param name="endElementNode">The ending element of the selection</param>
293293
/// <param name="codeDocument">The code document containing the selection.</param>
294-
/// <param name="actionParams">The parameters for the extraction action, which will be updated.</param>
294+
/// <param name="actionParams">The parameters for the extraction action</param>
295295
/// <param name="extractStart">The start of the extraction range.</param>
296296
/// <param name="extractEnd">The end of the extraction range</param>
297297
/// <returns> <c>true</c> if the selection was successfully processed; otherwise, <c>false</c>.</returns>
298-
private static bool TryProcessMultiPointSelection(MarkupSyntaxNode startElementNode, MarkupSyntaxNode endElementNode, RazorCodeDocument codeDocument, ExtractToComponentCodeActionParams actionParams, out int extractStart, out int extractEnd)
298+
private static bool TryProcessSelection(MarkupSyntaxNode startElementNode, MarkupSyntaxNode endElementNode, RazorCodeDocument codeDocument, ExtractToComponentCodeActionParams actionParams, out int extractStart, out int extractEnd)
299299
{
300300
extractStart = startElementNode.Span.Start;
301301
extractEnd = endElementNode.Span.End;
@@ -388,10 +388,14 @@ private static (SyntaxNode? Start, SyntaxNode? End) FindContainingSiblingPair(Sy
388388

389389
var endIsCodeBlock = endNode is CSharpCodeBlockSyntax;
390390

391-
foreach (var child in nearestCommonAncestor.ChildNodes().Where(node => IsValidNode(node, endIsCodeBlock)))
391+
foreach (var child in nearestCommonAncestor.ChildNodes())
392392
{
393-
var childSpan = child.Span;
393+
if (!IsValidNode(child, endIsCodeBlock))
394+
{
395+
continue;
396+
}
394397

398+
var childSpan = child.Span;
395399
if (startContainingNode is null && childSpan.Contains(startSpan))
396400
{
397401
startContainingNode = child;

0 commit comments

Comments
 (0)