Skip to content

Commit

Permalink
Tried fixing nullability issues
Browse files Browse the repository at this point in the history
  • Loading branch information
marcarro committed Jul 19, 2024
1 parent 144c307 commit a7fd529
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public ExtractToNewComponentCodeActionProvider(ILoggerFactory loggerFactory)
var endOwner = owner;
var endComponentNode = startComponentNode;

if (isSelection)
if (isSelection && selectionEnd is not null)
{
if (!selectionEnd.TryGetSourceLocation(context.CodeDocument.GetSourceText(), _logger, out var location))
{
Expand Down Expand Up @@ -166,7 +166,7 @@ private static bool TryGetNamespace(RazorCodeDocument codeDocument, [NotNullWhen
// good namespace to extract to
=> codeDocument.TryComputeNamespace(fallbackToRootNamespace: true, out @namespace);

public (SyntaxNode Start, SyntaxNode End) FindContainingSiblingPair(SyntaxNode startNode, SyntaxNode endNode)
public (SyntaxNode? Start, SyntaxNode? End) FindContainingSiblingPair(SyntaxNode startNode, SyntaxNode endNode)
{
// Find the lowest common ancestor of both nodes
var lowestCommonAncestor = FindLowestCommonAncestor(startNode, endNode);
Expand All @@ -175,28 +175,29 @@ private static bool TryGetNamespace(RazorCodeDocument codeDocument, [NotNullWhen
return (null, null);
}

SyntaxNode startContainingNode = null;
SyntaxNode endContainingNode = null;
SyntaxNode? startContainingNode = null;
SyntaxNode? endContainingNode = null;

// Pre-calculate the spans for comparison
var startSpan = startNode.Span;
var endSpan = endNode.Span;


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

if (startContainingNode == null && childSpan.Contains(startSpan))
{
startContainingNode = child;
if (endContainingNode != null) break; // Exit if we've found both
if (endContainingNode != null)
break; // Exit if we've found both
}

if (childSpan.Contains(endSpan))
{
endContainingNode = child;
if (startContainingNode != null) break; // Exit if we've found both
if (startContainingNode != null)
break; // Exit if we've found both
}
}

Expand All @@ -213,6 +214,7 @@ private static bool TryGetNamespace(RazorCodeDocument codeDocument, [NotNullWhen
{
return current;
}

current = current.Parent;
}

Expand Down

0 comments on commit a7fd529

Please sign in to comment.