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

Langword null fixer breaks when null is at the end of the strinrg #76548

Open
RenderMichael opened this issue Dec 21, 2024 · 4 comments · May be fixed by #76552
Open

Langword null fixer breaks when null is at the end of the strinrg #76548

RenderMichael opened this issue Dec 21, 2024 · 4 comments · May be fixed by #76552
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@RenderMichael
Copy link
Contributor

RenderMichael commented Dec 21, 2024

Version Used: 17.13.0 Preview 2.1

Steps to Reproduce:

class C
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="x"></param>
    /// <exception cref="ArgumentNullException">If x is null</exception>
    void M(string x)
    {

    }
}

Move cursor to null and press Ctrl+.

Expected Behavior:

Fixer suggestion of Use <see langword="null"/>

Actual Behavior:

Load and crash

Workaround: add . after null: /// <exception cref="ArgumentNullException">If x is null.</exception>

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Dec 21, 2024
@CyrusNajmabadi
Copy link
Member

What crash do you get?

@RenderMichael
Copy link
Contributor Author

I'm assuming it's a crash or an exception somewhere down the line, because the Suggestions menu loads then abruptly disappears. Whatever the issue happens to be should be trivial to reproduce by running the above repro.

@RenderMichael
Copy link
Contributor Author

I think I figured out the issue: when inside an XML tag and the cursor is at the end of the inner text, the located token is actually the closing XML tag. I added the following test to the fixer:

[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>
        class C<TKey>
        {
        }
        """);
}

Debugging through showed me that token was calculated to be the closing summary tag

public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
var (document, span, cancellationToken) = context;
var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var token = root.FindToken(span.Start, findInsideTrivia: true);
if (!IsXmlTextToken(token))
return;

Is this something to fix? Could it be fixed somehow?

@RenderMichael
Copy link
Contributor Author

Opened PR #76552 for the fix, the regression tests all pass but I'm a little hesitant to make a change I don't 100% understand the consequences of.

Hope it's alright, and happy to make further changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants