Skip to content

OnTypeFormatting is adding multiple new lines when using a primary constructor #8939

@JoeRobich

Description

@JoeRobich

For instance, when using a primary constructor with parameters indented on new lines, adding a comma followed by a new line to the end of a parameter list adds multiple newlines

Before:

Image

After:

Image

From the LSP trace logs we see that we are sending over a single new line and formatting is returning multiple new lines and some indentation.

// 2026-01-28 10:59:54.696 [trace] Sending request 'textDocument/onTypeFormatting - (450)'.
// Params:
{
    "textDocument": {
        "uri": "file:///Users/loganbussell/src/docker-tools/src/ImageBuilder/RegistryCredentialsProviderExtensions.cs"
    },
    "position": {
        "line": 17,
        "character": 8
    },
    "ch": "\n",
    "options": {
        "tabSize": 4,
        "insertSpaces": true,
        "trimTrailingWhitespace": true,
        "trimFinalNewlines": true
    }
}
// 2026-01-28 10:59:54.702 [trace] Received response 'textDocument/onTypeFormatting - (450)' in 6ms.
// Result:
[
    {
        "range": {
            "start": {
                "line": 17,
                "character": 0
            },
            "end": {
                "line": 18,
                "character": 4
            }
        },
        "newText": "\n\n    "
    }
]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions