dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.86k stars 673 forks source link

Brace completion doesn't take existing end brace into account #7172

Open davidfowl opened 5 months ago

davidfowl commented 5 months ago

It always injects the end brace even if one already exists:

https://github.com/dotnet/vscode-csharp/assets/95136/d42481f1-6819-452d-acbf-8efc17045717

dibarbet commented 4 months ago

Unfortunately since extensions do not run inside the VSCode rendering process, VSCode does not allow us as much control over brace completion as VS does. The existing support for customizing brace completion in VSCode is called language-configuration.json, but I don't think it allows us to fix this issue easily.

In this particular instance, while we can adjust the autoCloseBefore characters (see link above) to remove ) as a character to close before, that would result in an equally poor experience in a different area. Consider the following example where the cursor is represented by $$

Console.WriteLine(GetString$$)
static string GetString()
{
    return "Hello";
}

Without ) as an autoCloseBefore character, typing ( would result in Console.WriteLine(GetString(), instead of Console.WriteLine(GetString()) and putting the cursor inside the nested parens.

I was also thinking if VSCode could have a conditional auto close before ) that only triggers if the close paren has a matching open paren. But that also wouldn't solve the case in your video because ) is matched.

May need to discuss with the VSCode team to see if there is something we can do here.

davidfowl commented 4 months ago

May need to discuss with the VSCode team to see if there is something we can do here.

Can you open an issue on the vscode repository? This behavior is quite difficult to deal with.

dibarbet commented 4 months ago

Yes, I plan to do that, but I need to collect a few more details and minimal repro steps first. I'll update this issue once I've done that.