dotnet/roslyn

FormatAsync removes whitespace outside the requested bounds

Aperta

#50.129 aperta il 24 dic 2020

 (13 commenti) (0 reazioni) (0 assegnatari)C# (4257 fork)batch import
Area-IDEConcept-Continuous ImprovementIDE-Formatterhelp wanted

Metriche repository

Star
 (20.414 stelle)
Metriche merge PR
 (Merge medio 6g 17h) (256 PR mergiate in 30 g)

Descrizione

Version Used: 3.8.0

Steps to Reproduce:

Consider the following code:

class C
{
    public void M()
    {
        // There is a space after the ; here, and 8 spaces on the next line.
        var i = 1; 
        
    }
}

If I make a FormatAsync call, with the bounds [109..130), I get back a text change removing both the space on the end of the var line and the spaces on the line after, with a changed span of [127..138). This span is outside the bounds of what I asked for. In practice, what this means that if I have on-type formatting turned on in vscode and I have a trailing space, FormatAsync will remove the auto-indentation added in to put my cursor, when all that was asked to be formatted was the previous line.

Guida contributor