Roslyn: IDE0063 code fixer deletes comments nearby using statement or curly braces

Created on 14 Oct 2020  路  3Comments  路  Source: dotnet/roslyn

Version Used: Visual Studio 2019 Version 16.7.5

Steps to Reproduce:

  1. Write a following code, which has an IDE0063 'using' statement can be simplified:
using System;
using System.IO;

class C
{
    static void Main()
    {
        using (var s = new MemoryStream()) // foo
        { // bar
            Console.WriteLine(s.CanRead); // Only this comment remains.
        } // baz
    }
}
  1. Apply the Use simple 'using' statement

Expected Behavior:
All comments remain like this:

using System;
using System.IO;

class C
{
    static void Main()
    {
        using var s = new MemoryStream(); // foo
        // bar
        Console.WriteLine(s.CanRead); // Only this comment remains.
        // baz
    }
}

Actual Behavior:
"foo", "bar", "baz" comments are deleted:

using System;
using System.IO;

class C
{
    static void Main()
    {
        using var s = new MemoryStream();
        Console.WriteLine(s.CanRead); // Only this comment remains.
    }
}
Area-IDE Concept-Continuous Improvement IDE-CodeStyle help wanted

Most helpful comment

I can take a look at it.

All 3 comments

We would take a targetted PR that updated things to have this behavior.

I can take a look at it.

Expected Behavior:
All comments remain like this:

using System;
using System.IO;

class C
{
    static void Main()
    {
        using var s = new MemoryStream(); // foo
        // bar
        Console.WriteLine(s.CanRead); // Only this comment remains.
        // baz
    }
}

Ok, so I managed to resolve the issue, but instead I get aligned comments as follows:

using System;
using System.IO;

class C
{
    static void Main()
    {
        using var s = new MemoryStream(); // foo
                                          // bar
        Console.WriteLine(s.CanRead); // Only this comment remains.
                                      // baz
    }
}

If that sounds acceptable, I'll gladly submit a PR.

Was this page helpful?
0 / 5 - 0 ratings