vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

Brace completion doesn't take existing end brace into account

Open davidfowl opened this issue 1 year ago • 3 comments

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

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

davidfowl avatar May 27 '24 06:05 davidfowl

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.

dibarbet avatar Jun 20 '24 00:06 dibarbet

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.

davidfowl avatar Jun 20 '24 01:06 davidfowl

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.

dibarbet avatar Jun 20 '24 01:06 dibarbet