dotnet / razor

Compiler and tooling experience for Razor ASP.NET Core apps in Visual Studio, Visual Studio for Mac, and VS Code.
https://asp.net
MIT License
500 stars 191 forks source link

Intellisense absent in .razor files #9377

Closed Petit-Pas closed 1 year ago

Petit-Pas commented 1 year ago

I don't know when it started to happen but it certainely wasn't the case before.

Whenever I'm in a razor file of a blazor component library, the Intellisense doesn't work for anything anymore. Neither the completion of names I started typing (like parameters of that component) nor when I look for properties on existing objects.

The red squigglies appear normally (although a bit slow) if I type something that does not exist or if I haven't finished typing a property and then vanished when I finish typing it, but I still have to know everything by heart.

I work on a project that has hundreds of classes and I can hardly know every property in them.

What I've tried so far:

I can hardly imagine that this is general to the current release/preview cause that would have been seen already, but I don't really know what to provide to help analyze this more.

Any help to try to fix is appreciated because this is really absolutely unusable now :(

davidwengier commented 1 year ago

@Petit-Pas apologies that you're running into issues. You're right that generally speaking these things should work, and it's good that it seems diagnostics is at least working for you. Perhaps the best thing to do in this case is to use the in-built Report a Problem feature in Visual Studio, and the option within that to attach a recording. Even just a 30 second recording of you typing, and bringing up IntelliSense, will capture various logs and memory information from the system which will hopefully help us track down what is going on.

Petit-Pas commented 1 year ago

Didn't know about that, I will indeed use that feature then

Petit-Pas commented 1 year ago

I don't know if you can help on that side @davidwengier but here is the report: https://developercommunity.visualstudio.com/t/Intellisense-absent-in-razor-files/10485597

davidwengier commented 1 year ago

Thanks @Petit-Pas we got it.

For Microsofites, diagnostics info available in https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1897908 Looks like the repro is a .razor file in a Razor Class Library project, referencing classes from itself, and a class library.

Petit-Pas commented 1 year ago

I can't recall if I show it with both classes from the other library or the same, but the problem occurs with both just the same.

davidwengier commented 1 year ago

@Petit-Pas Thanks for the reports. I tried to repro this myself with an RCL that referenced a class library, and things seemed to work okay. I typed out @TestM after setting up things, and completion was shown. If I press escape to close the list, then press Ctrl+Space, the list pops up.

Sorry if this is a silly question, but I've been digging into your report and I think I can see you hit Ctrl+Space to bring up IntelliSense, but I'm not seeing anything in the logs that indicates that we actually get requested to provide intellisense, so just to double check, does this issue only repro in Razor files? Only Razor Class Libraries? It would be worth double checking if it also repros in plain C# files, as maybe your keyboard configuration has become incorrect. Does it happen if you just create a brand new BlazorServer or BlazorWebApp project?

All of the data on the Razor side does appear to have been discovered properly, which implies the Roslyn compilation is correct too.

image
Petit-Pas commented 1 year ago

Hey @davidwengier, Thanks for the quick feedback.

I won't have access to the machine one which I encounter the problem today, but I can already tell you that the Ctrl+Spc to bring IntelliSense works like a charm in the xyz.razor.cs files, or any plain .cs files for that matter.

So if you don't see the Ctrl+Spc calling the intelliSense, I would say that's indeed the issue (and not the keybord configuration, unless it can be changed for razor files only?)

I also didn't have any doubt about the roslyn compilation since the red squigglies seem to work just fine :)

I will make some more tests with different project types as soon as I can!

davidwengier commented 1 year ago

It's possible for the keyboard combo to do something different in razor files I think, but unlikely. I just realised though, you logged two VS feedback issues, and only one was missing completion requests in the logs. Did you definitely invoke it in both recordings? Also, did you only invoke it with Ctrl+Space, or with regular typing too, if you can remember?

Petit-Pas commented 1 year ago

The latest created issue was because I did not receive any feedback from VS platform that the first one had indeed been created, and after like 10 minutes I still didn't see it so I recreated it. I can't really remember the differences I made in both recordings, but the first one definitely was the most complete one.

As for the "invoking it with regular typing", if by that you mean typing the start of the word, then just passively waiting for completion to be proposed, that doesn't do anything either.

Do you mean that in one of the recordings, when I press Ctrl+Spc you actually see the request for the InelliSense popup to appear ?

Petit-Pas commented 1 year ago

Also, for the the key binding, since I fully uninstalled/reinstalled VS and didn't import any settings, I believe I should have the default ones ?
I will definitely have a look whenever I can if Ctrl+Spc is bound to anything else in a given context that might explain it.

davidwengier commented 1 year ago

Do you mean that in one of the recordings, when I press Ctrl+Spc you actually see the request for the InelliSense popup to appear ?

The recordings are not actually recordings per se, they are a series of screenshots with some minor information, but it seems like in that info you have pressed Ctrl+Space, which is good. We also get some logs from the Razor server, and in those logs I can see requests for completion in only one of the two issues.

I will see if I can loop in the editor team, and see if they can see anything that might indicate a problem.

Petit-Pas commented 1 year ago

Would it help if I do an actual recording of the screen, and post it, let's say as a non referenced youtube video or is it work for nothing ?

I am not an expert, but I think with Bandicam I can probably show my keyboard inputs as well. And if I do that all the while recording with the VS report feature, maybe you can cross the data?

davidwengier commented 1 year ago

Thanks for the offer, but I'm happy to take your word for it as to what you did in the recording. The only way to get more information that what we have already would be if you set an environment variable on your machine before you run VS. If you set "LogLevel" to "Verbose" then the logs that get attached to a VS report have a lot more detail in them, but even that I'm not sure would add much value. If Razor we reporting warnings or errors, they would be in the Razor log category in the output window, and in the logs that were already collected, but I didn't see any.

Petit-Pas commented 1 year ago

I can still try the logging just in case. Maybe don't spend too much brain power on it for now, let's see what my different investigations give if I can hopefully do them tonight (I live in GMT+2).

I can't thank you enough for looking into this, I really love blazor and this has just made it awful to use for some time :(

I'll keep you tuned!

Petit-Pas commented 1 year ago

@davidwengier here is the result of all my investigations, do not hesitate to tell me if anything is missing, I'll work from home tomorrow so I can be more reactive in case of wanted data.

I will soon provide another debug trace with LogLevel to verbose!

Petit-Pas commented 1 year ago

There you go, the linked VS ticket has been updated with the verbose logs

davidwengier commented 1 year ago

Thanks for the extra logs. I can see that we are receiving completion requests, but they're empty. It looks like we're getting a null result back from Roslyn when we ask for C# completion items. Still digging in to see if I can work out why.

Is it just C# in razor that is not working? Do you get the intellisense popup for html element, or components in your razor files?

davidwengier commented 1 year ago

Still looking through the logs, it seems the RCL is multi-targetting net6, net7 and net8. Is that right? When you tried with a new BlazorServer project, were you multi-targeting that too?

Petit-Pas commented 1 year ago

Is it just C# in razor that is not working? Do you get the intellisense popup for html element, or components in your razor files?

  • Things like \
    or \ work like a charm.
  • @name proposes namespace immediately, but @usi does not propose using, same for @route ... I Don't know where the border is set :/

I can see that we are receiving completion requests, but they're empty. It looks like we're getting a null result back from Roslyn when we ask for C# completion items.

Well spotted, 1 step in the right direction 👍🏻

were you multi-targeting that too?

Nothing in the tests I made were multi-targeting from what I know, in the original project that made me detect the issue its .net 7 all the way, and in the test project I created with VS Preview, it's .net 8

davidwengier commented 1 year ago

Thank you, thats very helpful and helps narrow things down to a Roslyn LSP issue. Will see what they have to say for themselves 😁

Petit-Pas commented 1 year ago

Thanks, keep me tuned :)

Petit-Pas commented 1 year ago

Hello @davidwengier, I see plenty of tags were added, does it mean you guyd have found the origin of the issue, or just that it's going to tested by a given team ?

In any case, if you guys find a hotfix I could do on my end in the meantime, I'm really interested :)

davidwengier commented 1 year ago

This is currently being investigated by the Roslyn team, still looking for a reason why you're getting the behaviour you're getting. Will let you know here when anything changes, or you will probably get a notification on the VS feedback issue too.

Petit-Pas commented 1 year ago

Thanks a lot :)

genlu commented 1 year ago

@Petit-Pas Hi! Would you be able to provide us a sample project to repro this issue? Thanks!

davidwengier commented 1 year ago

@Petit-Pas unfortunately we've hit a bit of a dead end with the logs we have from your VS feedback issues. We can see a couple of warnings that might be telling, but sadly the logs don't give us any context as to when those warnings appear, so its hard to tell. Would it be possible for you to add a new recording to the issue, or log a new issue, and repro the problem again (ie, try to bring up intellisense in C# in a .razor file), but this time before you run any instances of Visual Studio, can you create an environment variable on your machine called LogLevel, and give it the value Verbose?

Doing that should hopefully add more context to the logs so we can either see where this warning is coming from, or rule it out (and hopefully see something else useful!)

The other thing that might be useful, since you said the issue occurs in a new BlazorServer or BlazorWebApp project, would be to use that sort of project for the report. That way we might be able to identify issues with the Razor compiled output, because we can compare to a working copy of the project locally.

Petit-Pas commented 1 year ago

Hi @genlu, I'd indeed be able to do so, but I'm pretty sure this is an installation wide problem, since I literally did nothing more than creating a new project. I'll try to push it to a public repo, then test it myself on another machine and post the result + repository here.

@davidwengier, I'll try that if you want, but I already provided an example with that kind of log level before...

To align both your requests, I'll create a new BlazorWebApp project, test that it fails locally, push it to a public git, test it on another machine, then post everything here + the new issue in VS feedback

Petit-Pas commented 1 year ago

Alright @genlu & @davidwengier, you may find a repo that does reproduce the issue for me here: https://github.com/Petit-Pas/TestBlazorMsftBug which is literally the default Blazor Web App template, without any changes.

As stated before, the issue is not reproduced for me on a different machine, it really is a local/installation problem.

However you may find a new recording in the attached VS issue with me trying to bring it up from both @code block and razor html part of the editor. (LogLevel = Verbose)

Hope this helps :)

davidwengier commented 1 year ago

but I already provided an example with that kind of log level before...

Did you? Oh, sorry! I must have forgotten. I'll go dig that one up and check it again too

Petit-Pas commented 1 year ago

Thanks for the extra logs. I can see that we are receiving completion requests, but they're empty. It looks like we're getting a null result back from Roslyn when we ask for C# completion items.

Here's what you found in the first set of data with Verbose, so you know what you'll probably find :D Anyway I think the new logs are in a different kind of project, so who knows ?

davidwengier commented 1 year ago

Had a look at the new logs, and yeah, I guess we have been here before: It seems Roslyn completion doesn't log anything extra when verbose logging is on. The good news is, the warnings we saw earlier are all but gone, the bad news is that means we still don't know why Roslyn is deciding it has no completions to offer you.

Petit-Pas commented 1 year ago

Would an in person session help in any way? I can make myself available at any reasonable time for GCT+2 for you or a member of your team.

genlu commented 1 year ago

@Petit-Pas I have added a bit more logging in Roslyn to help us investigate. What would be the best way for you to install it? https://github.com/dotnet/roslyn/pull/70422

I have uploaded a locally built Roslyn vsix from the PR branch above. So one option is to download and install it to your VS. This will replace Roslyn comes with your official installation (you can uninstall this debug vsix later by going to Extensions -> manage Extensions) https://1drv.ms/u/s!AkbPBE3d3Hv-hp8AMi-nTSgTLqjWWA?e=WBp73w

or, if you prefer to build it from source yourself, here 's instruction of how to do that.

Once you have the new bits installed, make sure to set LogLevel to "All" this time (which would include more information in the log than "Verbose") before repro the issue you are seeing. After you are done, the logs are in %temp%/vslogs folder, with a name similar to VS09265221.Roslyn.RazorInProcLanguageClient.2.DLFQ.svclog

Petit-Pas commented 1 year ago

Hey @genlu, the svclog file has beed added to the linked VS issue. With a log level set to All as mentionned.

davidwengier commented 1 year ago

Thanks @Petit-Pas!! We really appreciate all of your effort here. Unfortunately we'll both have to wait until tomorrow for an answer, because @genlu has just logged off, but it is 11:15pm for him, so its probably fair enough :)

Petit-Pas commented 1 year ago

Indeed, I'm aware of the problems of timezones :D no worries, it's not impacting my work, just my pet project. So while it's very annoying, my work productivity is not impacted :)

davidwengier commented 1 year ago

@Petit-Pas Can you check the value of the top-most option in Tools, Options, Text Editor, C#, IntelliSense? And/or the second?

image

I looked at the log you added, and whilst I don't understand why, I checked against what my machine produces when LogLevel is All, and with Gen's vsix, and I think those top two checkboxes might be the cause.

Petit-Pas commented 1 year ago

@davidwengier here it is: image I indeed don't have the "after a character is deleted", but that's about it. I changed it just to test, but to no avail.

davidwengier commented 1 year ago

It looks to me like Roslyn thinks the top one is unchecked, but I might be wrong about where that comes from. Can you uncheck it, press OK, go back in and check it, and see if that does anything?

Otherwise hopefully Gen will know more in the morning.

Petit-Pas commented 1 year ago

No change :( It would have been weird though, as Ctrl+Spc is not exactly "after a character is typed"

davidwengier commented 1 year ago

No, it definitely still would have been a bug I think. At the end of the day, no matter the settings, your completion experience should be roughly the same in C# and Razor files. Hopefully the new logs mean more to Gen, and he'll have some other suggestions.

genlu commented 1 year ago

Thanks a lot @Petit-Pas!

@davidwengier is right, the issue seems to be CompletionOptions.TriggerOnTyping is set to false, which would cause the CompletionService to bail here

That option is controlled by "auto list members" in UI, could you pls check if tweaking this would workaround the issue you saw?

image

The reason this doesn't affect completion in regular C# file is because it's a separate code path where we do some other checks before asking CompletionService here

I believe this is a bug in CompletionService.ShouldTriggerCompletion where we shouldn't let the option to decide the behvavior of explict triggering of completion

Petit-Pas commented 1 year ago

Hey @genlu, Glad I checked on the thread before going to sleep. Checking those 3 boxes in "Statement completion" solve the issue temporarily!!

At least now I do have a local fix :) Any idea why I seem to be the only one impacted? Is that option often/usually selected by default? What bugs me is that it did not happen on my other computer... Although my configuration should be the same across computers...

I'll double check that option on the other computer tomorrow!

Thanks again, at least for the local fix :)

genlu commented 1 year ago

@Petit-Pas Great! Glad to hear it worked. I have sent out a proper fix for the issue in Roslyn. Thank you so much for reporting the bug and all the help you provided during investigation. It'd be very difficult for us to figure out the problem without it :)

genlu commented 1 year ago

Any idea why I seem to be the only one impacted? Is that option often/usually selected by default?

I think the default of this option is true. I suspect at some point it was accidentally changed on your computer, which got persisted since then. You might not notice it at the time because only C# in Razor is affected by this value, not regular C# code. I think the option storage was backed by local registry, which would explain why your other computer works fine.

Petit-Pas commented 1 year ago

@genlu The options does not seem to be enabled on my other machine either... But the VS version is quite different too, so if that was a regression, it only happened somewhere in between : image

Glad I could be of help :)

Will I be aware when that fix is released in the preview VS ?