dotnet / vscode-csharp

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

False errors that disappear when clicked #6970

Open ianmaclarty opened 7 months ago

ianmaclarty commented 7 months ago

Type: Bug

Issue Description

When opening my Unity project, many false errors appear in the error-list. As soon as I open the corresponding file or click on the error, the error disappears.

Here is a video showing the problem: https://github.com/dotnet/vscode-csharp/assets/3203019/9b428049-dfe5-4c48-86ee-877fd6a9ca38

Note that many of the errors are of the form "Predefined type 'System.Double' is not defined or imported" or "Predefined type 'System.String' is not defined or imported", etc

Steps to Reproduce

This issue occurs with a large closed-source Unity project. I do not have a smaller project that shows the problem, but I did record a video showing what happens (see description above). Clearly the extension is able to determine that these are not real errors once I open the files, but not before for some reason, as if some sort of cache is stale.

The errors usually, but not always, appear after opening VSCode. Once the errors have be clicked and disappear they do not come back for that session, however sometimes, new false errors will appear after a minute or so.

Expected Behavior

Only show actual errors and don't make errors suddenly disappear when they're clicked on.

Actual Behavior

False errors are shown, which disappear when clicked, or the corresponding file is opened.

Logs

OmniSharp log

I don't have such a log (Omnisharp does not appear in the list, I think becaues I have C# Dev Kit installed which causes Omnisharp not to be used).

C# log

Installing Razor Telemetry Version = 7.0.0-preview.24151.1... Platform: win32, x86_64

Downloading package 'Razor Language Server Telemetry (Windows / x64)' (9680 KB).................... Done! Validating download... Integrity Check succeeded. Installing package 'Razor Language Server Telemetry (Windows / x64)'

Finished

Using dotnet configured on PATH Dotnet path: C:\Program Files\dotnet\dotnet.exe Activating C# + C# Dev Kit... waiting for named pipe information from server... [stdout] {"pipeName":"\\.\pipe\dd2565c0"} received named pipe information from server attempting to connect client to server... client has connected to server [Info - 11:58:38 AM] [Program] Language server initialized [Info - 11:58:39 AM] [WorkspaceProjectFactoryService] Project C:\Users\ian\projects\mfl\FMODUnityResonance.csproj loaded by C# Dev Kit [Info - 11:58:39 AM] [WorkspaceProjectFactoryService] Project C:\Users\ian\projects\mfl\FMODUnity.csproj loaded by C# Dev Kit [Info - 11:58:39 AM] [WorkspaceProjectFactoryService] Project C:\Users\ian\projects\mfl\Assembly-CSharp.csproj loaded by C# Dev Kit [Info - 11:58:39 AM] [WorkspaceProjectFactoryService] Project C:\Users\ian\projects\mfl\FMODUnityResonanceEditor.csproj loaded by C# Dev Kit [Info - 11:58:39 AM] [WorkspaceProjectFactoryService] Project C:\Users\ian\projects\mfl\com.rlabrecque.steamworks.net.csproj loaded by C# Dev Kit [Info - 11:58:39 AM] [WorkspaceProjectFactoryService] Project C:\Users\ian\projects\mfl\ShapesRuntime.csproj loaded by C# Dev Kit [Info - 11:58:39 AM] [WorkspaceProjectFactoryService] Project C:\Users\ian\projects\mfl\Assembly-CSharp-Editor.csproj loaded by C# Dev Kit [Info - 11:58:39 AM] [WorkspaceProjectFactoryService] Project C:\Users\ian\projects\mfl\FMODUnityEditor.csproj loaded by C# Dev Kit [Info - 11:58:39 AM] [WorkspaceProjectFactoryService] Project C:\Users\ian\projects\mfl\I2.csproj loaded by C# Dev Kit [Info - 11:58:39 AM] [WorkspaceProjectFactoryService] Project C:\Users\ian\projects\mfl\Noise.csproj loaded by C# Dev Kit [Info - 11:58:39 AM] [WorkspaceProjectFactoryService] Project C:\Users\ian\projects\mfl\ShapesEditor.csproj loaded by C# Dev Kit [Info - 11:58:39 AM] [WorkspaceProjectFactoryService] Project C:\Users\ian\projects\mfl\com.rlabrecque.steamworks.net.editor.csproj loaded by C# Dev Kit [Info - 11:58:39 AM] [WorkspaceProjectFactoryService] Project C:\Users\ian\projects\mfl\I2Editor.csproj loaded by C# Dev Kit [Info - 11:58:39 AM] [WorkspaceProjectFactoryService] Project C:\Users\ian\projects\mfl\Assembly-CSharp-Editor-firstpass.csproj loaded by C# Dev Kit [Info - 11:58:39 AM] [WorkspaceProjectFactoryService] Project C:\Users\ian\projects\mfl\Assembly-CSharp-firstpass.csproj loaded by C# Dev Kit Using dotnet configured on PATH

Environment information

VSCode version: 1.87.2 C# Extension: 2.22.3 Using OmniSharp: true

Dotnet Information .NET SDK: Version: 8.0.201 Commit: 4c2d78f037 Workload version: 8.0.200-manifests.3097af8b Runtime Environment: OS Name: Windows OS Version: 10.0.22631 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.201\ .NET workloads installed: There are no installed workloads to display. Host: Version: 8.0.2 Architecture: x64 Commit: 1381d5ebd2 .NET SDKs installed: 6.0.402 [C:\Program Files\dotnet\sdk] 8.0.201 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Other architectures found: None Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download
Visual Studio Code Extensions |Extension|Author|Version|Folder Name| |---|---|---|---| |csdevkit|ms-dotnettools|1.4.29|ms-dotnettools.csdevkit-1.4.29-win32-x64| |csharp|ms-dotnettools|2.22.3|ms-dotnettools.csharp-2.22.3-win32-x64| |vscode-dotnet-runtime|ms-dotnettools|2.0.2|ms-dotnettools.vscode-dotnet-runtime-2.0.2| |vstuc|visualstudiotoolsforunity|1.0.0|visualstudiotoolsforunity.vstuc-1.0.0|;

Extension version: 2.22.3 VS Code version: Code 1.87.2 (863d2581ecda6849923a2118d93a088b0745d9d6, 2024-03-08T15:20:17.278Z) OS version: Windows_NT x64 10.0.22631 Modes:

System Info |Item|Value| |---|---| |CPUs|13th Gen Intel(R) Core(TM) i5-13600K (20 x 3494)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|31.79GB (11.69GB free)| |Process Argv|| |Screen Reader|no| |VM|0%|
dibarbet commented 7 months ago

@ianmaclarty can you let me know what the values are for the following two settings?

image

Additionally did you run a build at all that caused the errors to initially appear?

The errors appearing (when not opened) and going away (when opened) is not expected regardless of the setting, but it may help track down exactly what is happening.

ianmaclarty commented 7 months ago

Thanks for the prompt response!

Here are my settings: image (I remember fiddling with these to try and fix the issue, so they might not've been these exact settings when the issue first occurred, although the problem was still happening with these values.)

To answer your other question, the errors showed when I opened VSCode. I'm pretty sure I had Unity open already and it likely would've done a build recently, but there weren't any errors in Unity. Re-opening VSCode didn't seem to fix the issue. I think I'd done a branch switch in git a little while before, but this didn't occur immediately after doing a branch swap. Usually if I do a branch swap with VSCode already open, I'll get a lot of errors, but then just re-opening it will fix them. That didn't work in this case.

I haven't been having this problem today btw - it seems intermittent.

ianmaclarty commented 7 months ago

Oh I spoke to soon - the issue just occurred again after I posted my response above. VSCode had been open in the background and when I switched back to it one of the files was red. Clicking on the file cleared the error. Unity was closed at the time.

dibarbet commented 7 months ago

Thanks for the details @ianmaclarty ! A couple more questions that might help:

  1. The errors you're seeing in the problems window - do the error codes start with 'CS' (compiler diagnostics), or something else?
  2. If you wait a bit before opening the file, do the errors eventually go away? Workspace diagnostics can be quite slow depending on the solution size
ianmaclarty commented 7 months ago

Not sure if it's helpful, but here's another video of it occurring. I was doing my usual edit code / run in Unity iteration and then these false errors showed up. I hadn't changed the files with the errors.

https://github.com/dotnet/vscode-csharp/assets/3203019/a18b6424-3037-493e-97ea-ef64f5eb46aa

ianmaclarty commented 7 months ago

Oh sorry, didn't see your last post (that was quick!).

Yes the errors codes start with CS (you can see some of them in the video above).

I've tried waiting for a few seconds (around 10-15) and they don't go away. Next time I'll try wait longer.

My solution is around 170k loc including packages: image

ianmaclarty commented 7 months ago

(excluding external packages it's around 60k loc)

dibarbet commented 7 months ago

@ianmaclarty apologies, one more request. Set the dotnet.server.trace setting in vscode to Trace (and reload the window). The next time you see the issue, could you zip up the entire extension logs folder

image

You can attach here, or send to me directly (dabarbet@microsoft.com) - it will contain things like full file paths and other information you may not want to share publicly.

Once done, you'll want to reset the trace log setting back to 'Information' since its quite verbose.

ianmaclarty commented 7 months ago

Ok will do!

ianmaclarty commented 7 months ago

@dibarbet I just emailed you the logs. Here's what it looked like for me:

https://github.com/dotnet/vscode-csharp/assets/3203019/c14b5f31-20ad-46de-ae62-c5d59e17b657

Note that these errors occurred a few minutes after doing a git pull. The diff was quite small (only a few files changed), but the errors relate to the diff (e.g. the missing definitions it's complaining about were added in the diff).

dibarbet commented 7 months ago

@ianmaclarty got the mail, thanks! I'll do my best to investigate this week.