dotnet / dotnet/vscode-csharp

Extra newline added before closing branch when pressing [Enter] between 2 brackets

Open
#4,012 0 comments 0 reactions 0 assignees View on GitHub
Bug Editor-Formatting Triaged
Dominant language
TypeScript
Stars
3.1k
Forks
737
Avg merge
18h 40m
Merged PRs (30d)
31

Description

## Issue Description ##

When typing C# code I often place my cursor between a pair of (normal?) brackets `()`and press enter.
Usually to start formatting the arguments or parameters for a method on multiple lines.
I'm getting an extra line instead when the contents of the brackets is empty.

The C# convention's seem to be:

```c#
void A()
{
}

void B(object o)
{
}

void C(
object o1,
object o2)
{
}
```

But I keep getting and seeing the same from my team:

```c#
void C(
object o1,
object o2
)
{
}
```

Note if the existing code is:

```c#
void D(object o)
{
}

void E(
object o1
object o2)
{
}
```

and I press enter after `o` or `o2` it works as expected.

## Steps to Reproduce ##

Starting:
```c#
void Foo()
```

Place cursor between `(` and `)` and press enter

## Expected Behavior ##

Newline to be added with the bracket on the same line:

```c#
void Foo(
)
^ - cursor here
```

I don't mind too much about indentation, but a tab stop is preferred.

## Actual Behavior ##

An extra line for the bracket:

```c#
void Foo(
| < - cursor here
)
```

## Notes ##

This is the same when calling methods as declaring them:

```c#
DoFoo();
//becomes
DoFoo(
| < - cursor here
);
```

I'm not sure if this is VS Code or OmniSharp issue, but if I were to do this with `{}` I'd expect the format in the Actual, I'm assuming it needs to be syntactically aware of the language.

Using Visual Studio works fine and has done for many years.

I cannot find an editorconfig or omnisharp setting that would let me format my code correctly, allowing me to use Format on Save to clear this up.

I'm sure this is a fairly (few months) recent issue as I don't recall it always doing this.

## Logs ##

### OmniSharp log ###
n/a

### C# log ###
n/a

## Environment information ##

**VSCode version**: 1.48.1
**C# Extension**: 1.23.1

Dotnet Information
.NET Core SDK (reflecting any global.json):
Version: 3.1.201
Commit: b1768b4ae7

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19041
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.201\

Host (useful for support):
Version: 3.1.3
Commit: 4a9f85e9f8

.NET Core SDKs installed:
2.1.803 [C:\Program Files\dotnet\sdk]
3.1.201 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

Visual Studio Code Extensions

|Extension|Author|Version|
|---|---|---|
|bracket-pair-colorizer-2|CoenraadS|0.2.0|
|code-spell-checker|streetsidesoftware|1.9.0|
|color-highlight|naumovs|2.3.0|
|csharp|ms-dotnettools|1.23.1|
|cucumberautocomplete|alexkrechik|2.15.0|
|dotnet-test-explorer|formulahendry|0.7.4|
|ecdc|mitchdenny|1.3.0|
|EditorConfig|EditorConfig|0.15.1|
|gitlens|eamodio|10.2.2|
|go|golang|0.16.1|
|markdown-preview-github-styles|bierner|0.1.6|
|material-icon-theme|PKief|4.2.0|
|material-theme|zhuangtongfa|3.8.5|
|powershell|ms-vscode|2020.6.0|
|remote-wsl|ms-vscode-remote|0.44.4|
|vscode-icons|vscode-icons-team|10.2.0|
|vscode-markdownlint|DavidAnson|0.36.3|
|vscode-pull-request-github|GitHub|0.19.0|
|vscode-typescript-tslint-plugin|ms-vscode|1.2.3|
|vsliveshare|ms-vsliveshare|1.0.2666|
|xml|DotJoshJohnson|2.5.1|;

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.