razor icon indicating copy to clipboard operation
razor copied to clipboard

Essential control flow keywords are missing from completions (and randomly disappear/appear)

Open Peter-Juhasz opened this issue 1 year ago • 5 comments

Version: VS 17.11.0 P2.1 (all extensions disabled)

Type switch, it is completely missing until you type it fully:

https://github.com/dotnet/razor/assets/9047283/926b8d52-1182-4d82-82c1-5cbd31d0edfd

Type foreach, sometimes appears, sometimes disappears:

https://github.com/dotnet/razor/assets/9047283/f5b153fa-3736-49c7-b080-f7f5b7babe99

Type if, and get completed with IFormatProvider (happens the most frequently):

https://github.com/dotnet/razor/assets/9047283/edd45be0-a656-4753-ac99-e2b461dc51cd

Similar to #10435 where items appear and disappear randomly, and you can also see the same symptoms as #9802 where completions selection bouncing and matching items randomly (maybe due to the list is being populated multiple times).

Peter-Juhasz avatar Jul 02 '24 14:07 Peter-Juhasz

I think this is the same as https://github.com/dotnet/razor/issues/6927, in that when you start typing you're effectively typing in C# that looks like var _o = $$, so the switch keyword is indeed not valid there. Once you finish typing the keyword, the Razor compiler recognizes it, and generates code where it is valid. But definitely worth validating that, I'm not 100% sure if the compiler does recognize keywords like that.

davidwengier avatar Jul 09 '24 22:07 davidwengier

@davidwengier Is this a compiler or tooling issue?

chsienki avatar Jul 11 '24 17:07 chsienki

This is tooling I believe.

davidwengier avatar Jul 11 '24 22:07 davidwengier

@Peter-Juhasz there've been a number of changes in Razor and Roslyn since this was filed. Trying this today, I seem to always get "switch" and other keywords in completion. You will see snippet-only for "switch", which is currently the same behavior in Roslyn if LSP is enabled.

Would you please let me know if you are still able to repro keyword not showing up for you at all while typing?

alexgav avatar Jun 30 '25 06:06 alexgav

Yes, this is the most frustrating issue with the editor right now, that "random" completions get committed whenever I type a control flow keyword, which is like super common:

https://github.com/user-attachments/assets/c848d62a-999a-49ab-b2e4-7da51b8c7ed9

  1. I type if and get IFileHttpResult completed instead
  2. Then it works
  3. Then although I already have if (with an extra space) in the completion span, the completion session is still active.

Here is another recording where completions appear and disappear:

https://github.com/user-attachments/assets/049c2659-5813-4a15-b8d7-23145f394a83

I can even see the list of completion items change while typing, it feels like being recalculated after every character and items are still arriving asynchronously and then it slips apart in many ways as you can see in the recording. Instead of the whole list calculated at once and frozen before starting the completion session like is should be.

Something is clearly wrong here. (To make it clear, snippets which are happened to be defined with the same name as keywords are only a workaround and hide the underlying root cause. I don't have them enabled since they appeared everywhere.)

But even if it would work a hundred percent correct (no flakyness), there would be still the case which David mentioned (var _o = $$) where a control flow keyword is not valid in C#, BUT it can be still valid in Razor (e.g. after a @ transition in a block). In that case I believe Razor should extend the completions it got from C# with control flow the keywords - like it would be a directive (e.g. @inject) although it is not.

(Similarly to Dustin's idea with the generic T which is although not defined yet, but when it is likely, it makes life easier more times to include that completion than it would make worse when it is there but not needed.)

Peter-Juhasz avatar Jun 30 '25 08:06 Peter-Juhasz