dotnet/vscode-csharp

Autocomplete prevents typing a lambda expression

granthusbands opened this issue · 5 comments

Issue Description

Typing a lambda expression is a nightmare where you have to fight autocomplete and keep pressing escape to cancel suggestions

Steps to Reproduce

Try typing in a cs file (you can copy/paste before the var)):

    class Person {
        public bool isFriendOf(Person other) {
            return false;
        }
    }

    class Other {
        public void Hi() {
            var fn = (Person bob, Person lisa) => bob.isFriendOf(lisa);
        }
    }

Expected Behavior

You get the text you typed.

Actual Behavior

The var line comes out like:

            var fn = (Person ContextBoundObject, Person LdapStyleUriParser) => ContextBoundObject.isFriendOf(LdapStyleUriParser);

This happens when typing lambdas in all expression contexts, including when filling in a known-type parameter - I just simplified it to the above.

Pressing escape lots can work, but you have to be watching really carefully. Otherwise, typing ()=> first and then filling in the brackets and then the expression is a good workaround.

(Fighting the autocomplete is a way of life, but having valid code typed in order in the natural fashion turn into the above is not fun.)

Environment information

VSCode version: 1.61.1
C# Extension: 1.23.16

Dotnet Information .NET SDK (reflecting any global.json): Version: 5.0.402 Commit: e9d3381880

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

Host (useful for support):
Version: 5.0.11
Commit: f431858f8b

.NET SDKs installed:
3.1.120 [C:\Program Files\dotnet\sdk]
5.0.103 [C:\Program Files\dotnet\sdk]
5.0.402 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

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

Visual Studio Code Extensions
Extension Author Version
cpptools ms-vscode 1.7.0
csharp ms-dotnettools 1.23.16
jupyter ms-toolsai 2021.9.1101343141
jupyter-keymap ms-toolsai 1.0.0
jupyter-renderers ms-toolsai 1.0.3
ninja-syntax melak47 1.0.0
open-in-browser techer 2.0.0
python ms-python 2021.10.1336267007
remote-wsl ms-vscode-remote 0.58.2
rewrap stkb 1.14.0
vscode-autohotkey-plus cweijan 2.6.2
vscode-pylance ms-python 2021.10.1

There is no option in this extension to make the suggestion mode less intrusive, but maybe configuring it this way could help.

microsoft/vscode#70176 (comment)
#3394

Duplicate #3394

This bug isn't the same as that one - this bug is that the set of suggested completions is simply incorrect because (presumably) the C# extension is not allowing for the possibility of a lambda expression in expression position. Since it works exactly as expected if you add parameters after you've added the ()=>, it's clearly capable of doing so.

Is it not a bug that the set of suggestions is simply incorrect?

Is it not a bug that the set of suggestions is simply incorrect?

Even in VS you will get these same suggestions. The difference is that they are not hard selected like they are in VS Code.

image

In that VS screenshot, it looks like the first suggestion is what the user typed, which is a valid suggestion in the context and what would fix VS.Code's suggestions. Or maybe that's a box title? Even if VS did have the same autocomplete, I'm not sure I see how VS also having a bug means that VS.Code should ignore it.

It's worth noting that VS.Code probably only does it for user-provided types. If you type (int bob, int lisa), it doesn't insert other things, so it seems like it might already have some handling for this that just needs to do the same with user-provided types.

However, I probably will disable the commit characters, in config, as you suggest.

I'm not sure I see how VS also having a bug means that VS.Code should ignore it.

Point taken. I think I approach a lot of these issues with the mindset that if I can get VS Code to work as well as VS then that is success. I've am now rethinking that. Thanks for the different perspective.