dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.12k stars 4.04k forks source link

Completion builder prefers regular completions over built ones and activates them in lambda parameters #74322

Open Peter-Juhasz opened 4 months ago

Peter-Juhasz commented 4 months ago

VS 17.11.0 P2.1

Completion session controller should select the built completion when naming variables (in this case lambda expression parameter name), instead of matching the existing symbols or regular completions provided.

This makes writing lambda expressions quite frustrating, because every time it completes the name I try to assign to a completion from the list.

https://github.com/dotnet/razor/assets/9047283/4ccebacf-33a8-46c9-ad28-bba30c7d5208

@code {
    protected override void OnInitialized()
    {
        int[] numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
        var even = numbers.Where(n$$);
        base.OnInitialized();
    }
}
ryzngard commented 4 months ago

Interestingly it seems to also happen in csharp files

4cc265ab-de50-4bc0-a86c-c4c15f3fba6b

@alexgav is this something we should move over to dotnet/roslyn?

alexgav commented 4 months ago

I believe the main difficulty @Peter-Juhasz is having is not so much that the "standard" completion items are present in the completion list, but the fact that they are selected via "hard" (as opposed to "soft" :) ) selection in LSP. That causes them to be completed when space is typed. As @ryzngard said it reproes in plain C# files if I enabled LSP C#/VB editor (which is what Razor uses). In "old" C# editor (default for standalone C# files) actually uses soft selection in this case and won't commit selected item. E.g. if you type "n" in Razor and LSP C#, you get "nameof" completed, even if you actually want to do something like "n => n > 3".

In the old (current C#) editor, even though nameof gets soft selected, it is not completed when space is pressed, so instead of ending up with Where(nameof ) you actually get Where(n )

I agree though, this should go to Roslyn. @ToddGrun and @genlu .