Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ public ImmutableArray<RazorCompletionItem> GetCompletionItems(RazorCompletionCon
if (owner is null)
{
Debug.Fail("Owner should never be null.");
return ImmutableArray<RazorCompletionItem>.Empty;
return [];
}

owner = owner switch
{
// This provider is trying to find the nearest Start or End tag. Most of the time, that's a level up, but if the index the user is typing at
// is a token of a start or end tag directly, we already have the node we want.
MarkupStartTagSyntax or MarkupEndTagSyntax or MarkupTagHelperStartTagSyntax or MarkupTagHelperEndTagSyntax or MarkupTagHelperAttributeSyntax => owner,
// Invoking completion in an empty file will give us RazorDocumentSyntax which always has null parent
RazorDocumentSyntax => owner,
// Either the parent is a context we can handle, or it's not and we shouldn't show completions.
_ => owner.Parent
};
Expand Down Expand Up @@ -118,7 +120,7 @@ static bool InOrAtEndOfAttribute(SyntaxNode attributeSyntax, int absoluteIndex)
}

// Invalid location for TagHelper completions.
return ImmutableArray<RazorCompletionItem>.Empty;
return [];
}

private ImmutableArray<RazorCompletionItem> GetAttributeCompletions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ public void GetCompletionAt_AtEmptyTagName_ReturnsCompletions()
completion => Assert.Equal("test2", completion.InsertText));
}

[Fact]
public void GetCompletionAt_InEmptyDocument_ReturnsEmptyCompletionArray()
{
// Arrange
var service = new TagHelperCompletionProvider(RazorTagHelperCompletionService, TestRazorLSPOptionsMonitor.Create());
var context = CreateRazorCompletionContext(
"$$",
isRazorFile: true,
tagHelpers: DefaultTagHelpers);

// Act
var completions = service.GetCompletionItems(context);

// Assert
Assert.Empty(completions);
}

[Fact]
public void GetCompletionAt_OutsideOfTagName_DoesNotReturnCompletions()
{
Expand Down