Skip to content

Commit 0b411d2

Browse files
committed
Tried fixing nullability issues
1 parent 0d8bf70 commit 0b411d2

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public Task<ImmutableArray<RazorVSInternalCodeAction>> ProvideAsync(RazorCodeAct
7474
var endOwner = owner;
7575
var endComponentNode = startComponentNode;
7676

77-
if (isSelection)
77+
if (isSelection && selectionEnd is not null)
7878
{
7979
if (!selectionEnd.TryGetSourceLocation(context.CodeDocument.GetSourceText(), _logger, out var location))
8080
{
@@ -161,7 +161,7 @@ private static bool TryGetNamespace(RazorCodeDocument codeDocument, [NotNullWhen
161161
// good namespace to extract to
162162
=> codeDocument.TryComputeNamespace(fallbackToRootNamespace: true, out @namespace);
163163

164-
public (SyntaxNode Start, SyntaxNode End) FindContainingSiblingPair(SyntaxNode startNode, SyntaxNode endNode)
164+
public (SyntaxNode? Start, SyntaxNode? End) FindContainingSiblingPair(SyntaxNode startNode, SyntaxNode endNode)
165165
{
166166
// Find the lowest common ancestor of both nodes
167167
var lowestCommonAncestor = FindLowestCommonAncestor(startNode, endNode);
@@ -170,28 +170,29 @@ private static bool TryGetNamespace(RazorCodeDocument codeDocument, [NotNullWhen
170170
return (null, null);
171171
}
172172

173-
SyntaxNode startContainingNode = null;
174-
SyntaxNode endContainingNode = null;
173+
SyntaxNode? startContainingNode = null;
174+
SyntaxNode? endContainingNode = null;
175175

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

180-
181180
foreach (var child in lowestCommonAncestor.ChildNodes().Where(node => node.Kind == SyntaxKind.MarkupElement))
182181
{
183182
var childSpan = child.Span;
184183

185184
if (startContainingNode == null && childSpan.Contains(startSpan))
186185
{
187186
startContainingNode = child;
188-
if (endContainingNode != null) break; // Exit if we've found both
187+
if (endContainingNode != null)
188+
break; // Exit if we've found both
189189
}
190190

191191
if (childSpan.Contains(endSpan))
192192
{
193193
endContainingNode = child;
194-
if (startContainingNode != null) break; // Exit if we've found both
194+
if (startContainingNode != null)
195+
break; // Exit if we've found both
195196
}
196197
}
197198

@@ -208,6 +209,7 @@ private static bool TryGetNamespace(RazorCodeDocument codeDocument, [NotNullWhen
208209
{
209210
return current;
210211
}
212+
211213
current = current.Parent;
212214
}
213215

0 commit comments

Comments
 (0)