belav / csharpier

CSharpier is an opinionated code formatter for c#.
https://csharpier.com
MIT License
1.41k stars 98 forks source link

Comments don't follow tabs indent style #1343

Closed J05HM0N5TER closed 2 months ago

J05HM0N5TER commented 2 months ago

When formatting the document, any comments which have indenting, get updated to use space indenting, even when indent style is set to tabs. The indenting provided by the function is kept, but the extra indenting from the comment is spaces. This makes the indenting in this example [tab][tab][space][space][space][space] instead of [tab][tab][tab].

I found out this problem because VS Code highlights lines with inconsistent indenting, and I was writing pseudocode in a comment block. I apologise for the awful looking formatting, but it is the best way I could find to demonstrate the problem.

Input:

    public void ExampleFunction()
    {
        /*
        The following line is an example with an indent:
            This line is indented by one tab.
        */
    }

Output:

    public void ExampleFunction()
    {
        /*
        The following line is an example with an indent:
            This line is indented by one tab.
        */
    }

Expected behavior:

    public void ExampleFunction()
    {
        /*
        The following line is an example with an indent:
            This line is indented by one tab.
        */
    }
belav commented 2 months ago

@J05HM0N5TER feel free to weigh in on the comment I left in #1344. Not sure if either of the two alternatives would be better than the fix I implemented.

J05HM0N5TER commented 2 months ago

@J05HM0N5TER feel free to weigh in on the comment I left in #1344. Not sure if either of the two alternatives would be better than the fix I implemented.

I think that looks like a great way to resolve it. I think if the user puts 4 spaces with indenting it will format the same as a tab anyway, and it will keep the indenting more consistent. This also means that if the user wants to have 1–3 spaces of indenting, like if they have something that they intend to line up with something on another line, then they can do that.

Thank you for creating a fix for this so quickly.