dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.86k stars 671 forks source link

Extension stops indexing .razor (Blazor) component files after a certain number unless you open the file. #6921

Open TrieBr opened 7 months ago

TrieBr commented 7 months ago

Issue Description

I think I finally found the main issue preventing me from using VS Code.

I have dotnet.backgroundAnalysis.compilerDiagnosticsScope and dotnet.backgroundAnalysis.analyzerDiagnosticsScope both set to fullSolution and csharp.maxProjectFileCountForDiagnosticAnalysis set to 9999999999. However it appears that the extension ignores this setting for razor files. After a certain number of razor files, you end up with tons of "Found markup element with unexpected name "SomeComponent" errors until you go open SomeComponent.razor

Steps to Reproduce

  1. Clone my test repo here.

    git clone -b test-large-solution https://github.com/TrieBr/blazor-input-bug.git
  2. Open BlazorInputBug/InputBug/Pages/Counter.razor. Notice that "InputTextFour" is underlined and an error shows Found markup element with unexpected name 'InputTextFour'. If this is intended to be a component, add a @using directive for its namespace.. NOTE: Sometimes (flaky) it does work, but you can rename the component to something else like InputTextFive or InputTextSix and observe the same behavior.

  3. Open BlazorInputBug/InputBug/Shared/Inputs/InputTextFour.razor. Then go back to BlazorInputBug/InputBug/Pages/Counter.razor and observe the problem goes away.

  4. Delete most of the other files (BlazorInputBug/InputBug/Shared/Inputs/InputText{11..50.razor}) and command pallete => reload the window. The problem goes away. You can change between InputTextTwo, InputTextThree, InputTextFour, etc and they all work.

  5. Re-add more files (for i in {11..50}; do cp InputText.razor "InputText$i.razor"; done, reload the window and see the problem comes back. You change between InputTextTwo, InputTextThree, InputTextFour, etc and is starts to say "Found markup element with unexpected name"

Expected Behavior

When dotnet.backgroundAnalysis.compilerDiagnosticsScope is set to fullSolution, all razor files should be indexed, and I shouldn't have to go open the ".razor" file to get rid of reference errors.

Actual Behavior

After enough razor files in the solution (my tests seem to break at only 50, but i didn't bisect a smaller number). Intellesense stop working for Blazor components

Logs

Archive.zip

C# log

https://pastebin.com/xwDQQM8k

C# LSP Trace Logs

https://pastebin.com/KrCEXRNw

davidwengier commented 7 months ago

Like https://github.com/dotnet/vscode-csharp/issues/6852, seems like our closed file support might have stopped working.

karanveersp commented 6 months ago

Hmm. I think I'm seeing this too. I just created a new Blazor server app using the dotnet CLI and the PageTitle component, along with all the other components referenced in the _Imports.razor file all highlight as red, unrecognized tags. Screenshot 2024-04-12 at 4 13 32 PM

danielscatigno-ncpc commented 5 months ago

I'm also facing this problem and one workaround I Found is to create a code behind class for the Component or Razor page

ktravelet commented 2 months ago

I'm facing this issue on M1 mac. The issue is that I cant reliably reproduce it. It seems to appear after renaming files and all goes crazy afterwords. I havent figured out a consistent workaround either

ryzngard commented 1 month ago

it seems to appear after renaming files and all goes crazy afterwords. I havent figured out a consistent workaround either

This seems to be a new repro. The current issue has 100% repro and we believe we have a fix. @ktravelet can you file a separate issue when you get into that state? The best thing to do would be set razor logs to trace in your settings.json with "razor.server.trace": "Trace" and when you hit the issue use the Razor: report an issue command