-
Notifications
You must be signed in to change notification settings - Fork 686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated code (WPF, *.g.cs files) triggers infinite textDocument/diagnostic loop #6985
Comments
Attaching more logs from the start of a new session. |
Thanks for the detailed report. Think I know what the general issue here is. The language server registers file watchers for all .cs files in the workspace - if .cs files are added or removed we know we need to reload the project in order to ensure the right files are reflected in the right projects. However - this is problematic for the xaml generated .g.cs files in the obj/ directory. When we reload the project, we call msbuild to do a design time build. It seems like this design time build is re-generating the .g.cs file - which causes a file watcher notification - which causes a project reload - which causes a file watcher change - ad infinitum. A potential fix here is to ignore the obj/ directory for changes to .cs files. Since these are all generated, theoretically any changes to .cs files here would be triggered by changes to the project or other files outside of obj/, which we would hear about and reload the project to see the updated generated code. We shouldn't need to explicitly look for changes that only happen in obj/. It is also a bit weird that text only changes to closed files cause a project reload - theoretically we should be able to just update the text of existing files. But that wouldn't solve this issue by itself since the file is getting added/removed/changed. (cc @jasonmalinowski) |
@michaelpduda As a workaround while we fix the issue, you can exclude all .cs files in the obj/ folder from VSCode's file watcher in vscode settings |
The workaround does not seem to work on a Maui project in my workspace. Although, it did work on a WPF project.
Here is the C# LSP Trace Logs output (paths scrubbed for privacy):
The triggering files is not reliable either, here's a subsequent run:
|
Actually, |
A fix for this should be available in an upcoming prerelease |
This should be fixed in 2.50.25 or higher |
Type: Bug
Issue Description
Since version 2.22.3, for WPF projects (possibly other types as well), the extension sometimes gets stuck in a loop where it executes
textDocument/diagnostic
, which causes/obj/debug/.../*.g.cs
files to be regenerated, which causesworkspace/didChangeWatchedFiles
to trigger, which causes the extension to runtextDocument/diagnostic
, and so on... resulting in instability and heavy CPU usage.(This may not be the actual sequence of events, just my guess from observing and reading the logs.)
Steps to Reproduce
This has affected multiple projects of mine, and I was able to reproduce the issue using a fresh
dotnet new wpf
template project.test
dotnet new wpf
code .
)Expected Behavior
Extension executes the code Analysis once (or not at all?).
Actual Behavior
Infinite analysis loop (see description above).
Workarounds
Downgrading to version to version 2.18.16 stops the issue. Also, switching to Omnisharp (
"dotnet.server.useOmnisharp": true
) works as well.Logs
The logs run infinitely, so they are quite long, but below I tried to capture two full loops. If more logs are necessary, I can record more.
C# log
C# LSP Trace Logs
Environment information
VSCode version: 1.87.2
C# Extension: 2.22.5
Using OmniSharp: false
Dotnet Information
.NET SDK: Version: 8.0.103 Commit: 6a90b4b4bc Workload version: 8.0.100-manifests.4e94be9cRuntime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.103\
.NET workloads installed:
Workload version: 8.0.100-manifests.4e94be9c
There are no installed workloads to display.
Host:
Version: 8.0.3
Architecture: x64
Commit: 9f4b1f5d66
.NET SDKs installed:
7.0.117 [C:\Program Files\dotnet\sdk]
8.0.103 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.28 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.3 [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 version: 2.22.5
VS Code version: Code 1.87.2 (863d2581ecda6849923a2118d93a088b0745d9d6, 2024-03-08T15:20:17.278Z)
OS version: Windows_NT x64 10.0.19045
Modes:
System Info
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
A/B Experiments
The text was updated successfully, but these errors were encountered: