Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow null langword fixer at the end of an XML tag #76552

Merged
merged 2 commits into from
Jan 9, 2025
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 @@ -75,6 +75,44 @@ class C<TKey>
""");
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/76548")]
public async Task TestEndOfKeyword_XmlCloseTagFollowing()
{
await TestInRegularAndScriptAsync(
"""
/// <summary>Testing keyword null[||]</summary>
class C<TKey>
{
}
""",

"""
/// <summary>Testing keyword <see langword="null"/></summary>
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi Dec 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test where the keyword is the first word in the summary and the caret is at the start of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, that scenario did regress with this change. I pushed a fix and tests.

class C<TKey>
{
}
""");
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/76548")]
public async Task TestEndOfKeyword_XmlOpenTagPreceding()
{
await TestInRegularAndScriptAsync(
"""
/// <summary>[||]null is an option.</summary>
class C<TKey>
{
}
""",

"""
/// <summary><see langword="null"/> is an option.</summary>
class C<TKey>
{
}
""");
}

[Fact]
public async Task TestSelectedKeyword()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
var token = root.FindToken(span.Start, findInsideTrivia: true);

if (!IsXmlTextToken(token))
return;
{
token = root.FindTokenFromEnd(span.Start, findInsideTrivia: true);
if (!IsXmlTextToken(token))
{
return;
}
}

if (!token.FullSpan.Contains(span))
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,32 @@ class C(Of TKey)
end class")
End Function

<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/76548")>
Public Async Function TestEndOfKeyword_XmlCloseTagFollowing() As Task
Await TestInRegularAndScriptAsync(
"
''' <summary>Testing keyword MustInherit[||]</summary>
class C(Of TKey)
end class",
"
''' <summary>Testing keyword <see langword=""MustInherit""/></summary>
class C(Of TKey)
end class")
End Function

<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/76548")>
Public Async Function TestEndOfKeyword_XmlOpenTagPreceding() As Task
Await TestInRegularAndScriptAsync(
"
''' <summary>[||]MustInherit is a thing</summary>
class C(Of TKey)
end class",
"
''' <summary>[||]<see langword=""MustInherit""/> is a thing</summary>
class C(Of TKey)
end class")
End Function

<Fact>
Public Async Function TestSelectedKeyword() As Task
Await TestInRegularAndScriptAsync(
Expand Down
Loading