microsoft / vscode-dotnettools

This is a feedback repository to capture issues logged for the C# Dev Kit and related extensions from Visual Studio Code
Other
231 stars 13 forks source link

C# + C# Dev Kit Language Server is not watching new files #897

Closed ajwells128 closed 6 months ago

ajwells128 commented 9 months ago

Type: Bug

Issue Description

I've found two issues, probably related, with the C# Dev Kit LSP on a net6.0 application.

First, The LSP is failing to pick up on new files and any classes added to them. Classes added to new files show up as non-existent (red squiggle). Classes added to existing files show up as valid types right away (as expected).

The second, possibly related issue, is that Running >.NET: Restart Language Server results in all Nav features breaking. I thought restarting the language server might pick up the new files, but instead all Nav breaks.

Finally, running >Developer: Reload Window results in a restoration of the LSP which picks up all the new files and their new classes and correctly suggests / autocompletes them.

Steps to Reproduce

dotnet new webapi -f net6.0 code . # open in vscode >Devcontainers: Rebuild and Reopen in Container I selected C# (.NET) | 6.0 bullseye

Ensure omnisharp is disabled and C# Dev Kit is installed in the devcontainer. Rebuild if required. Add a folder and class Configuration/ConfigOptions.cs to the project. In Program.cs, try to write var options = new ConfigOptions(); with the necessary using statement.

ConfigOptions should show as not a valid class. >Developer: Reload Window ConfigOptions should show as a valid class Optionally: Add another class to a new file in the Configuration folder. Try to instantiate it. It shouldn't work, but navigation to ConfigOptions should. Try a >.NET: Restart Language Server -- now neither one should have proper Nav.

Expected Behavior

New classes written in new files should be recognized by the langauge server right away. Restarting the language server should not break Nav, especially not for classes for which it was working before restarting the language server.

Actual Behavior

New files aren't recognized until a window reload. Nav breaks after restarting the language server.

Logs

I could potentially share a zip of logs but that would take a lot of effort on my part for security reasons. Since this was relatively easy for me to reproduce off the bat, I don't think that should be necessary, but let me know if more is needed.

C# log

Here's a small snippet of the Debug C# logs, annotated: [LanguageServerHost] /workspaces/test/Program.cs found in workspace Host [LanguageServerHost] [10:18:37.717][Start]textDocument/definition ## I ran F2 on ProofOptions in Program.cs, a new class in a new file (ProofOptions.cs) which should be recognized but isn't [LanguageServerHost] [10:18:37.719][End]textDocument/definition [LanguageServerHost] /workspaces/test/Program.cs found in workspace Host ## I ran F2 on AnotherOptions in Program.cs, a newish class in a newish file, which originally wasn't recognized but I'd run a Window Reload since then and now it was being recognized [LanguageServerHost] [10:18:40.550][Start]textDocument/documentHighlight [LanguageServerHost] [10:18:40.553][End]textDocument/documentHighlight [LanguageServerHost] /workspaces/test/Program.cs found in workspace Host [LanguageServerHost] [10:18:40.802][Start]textDocument/codeAction [LanguageServerHost] [10:18:40.896][End]textDocument/codeAction [LanguageServerHost] /workspaces/test/Program.cs found in workspace Host [LanguageServerHost] [10:18:43.920][Start]textDocument/definition [LanguageServerHost] [10:18:43.921][End]textDocument/definition [LanguageServerHost] /workspaces/test/Configuration/AnotherOptions.cs found in workspace Host ## Notice that AnotherOptions is found in workspace Host [LanguageServerHost] [10:18:43.970][Start]textDocument/codeAction [LanguageServerHost] /workspaces/test/Configuration/AnotherOptions.cs found in workspace Host [LanguageServerHost] [10:18:44.017][Start]textDocument/inlayHint [LanguageServerHost] [10:18:44.018][End]textDocument/inlayHint [LanguageServerHost] [10:18:44.088][End]textDocument/codeAction [LanguageServerHost] /workspaces/test/Configuration/AnotherOptions.cs found in workspace Host [LanguageServerHost] [10:18:44.106][Start]textDocument/semanticTokens/range [LanguageServerHost] [10:18:44.107][End]textDocument/semanticTokens/range [LanguageServerHost] /workspaces/test/Configuration/ProofOptions.cs found in workspace MiscellaneousFiles ## Notice that ProofOptions.cs (which contains the valid definition of ProofOptions) is in the same folder as AnotherOptions.cs but is in MiscellaneousFiles. Why is it not in Host? [LanguageServerHost] [10:18:44.167][Start]textDocument/diagnostic

C# LSP Trace Logs

Post the output from Output-->C# LSP Trace Logs here. Requires `dotnet.server.trace` to be set to `Trace`

Environment information

VSCode version: 1.86.0 C# Extension: 2.15.30 Using OmniSharp: false

Dotnet Information Host: Version: 7.0.15 Architecture: x64 Commit: 8f4568cdaa .NET SDKs installed: No SDKs were found. .NET runtimes installed: Microsoft.NETCore.App 7.0.15 [/home/vscode/.vscode-server/data/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.15~x64/shared/Microsoft.NETCore.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| |---|---|---|---| |copilot|GitHub|1.156.0|github.copilot-1.156.0| |copilot-chat|GitHub|0.12.0|github.copilot-chat-0.12.0| |csdevkit|ms-dotnettools|1.2.7|ms-dotnettools.csdevkit-1.2.7-linux-x64| |csharp|ms-dotnettools|2.15.30|ms-dotnettools.csharp-2.15.30-linux-x64| |vscode-dotnet-runtime|ms-dotnettools|2.0.1|ms-dotnettools.vscode-dotnet-runtime-2.0.1| |vscode-eslint|dbaeumer|2.4.4|dbaeumer.vscode-eslint-2.4.4| |vscode-pull-request-github|GitHub|0.80.0|github.vscode-pull-request-github-0.80.0| |vscodeintellicode-csharp|ms-dotnettools|0.1.26|ms-dotnettools.vscodeintellicode-csharp-0.1.26-linux-x64|;

Extension version: 1.2.7 VS Code version: Code 1.86.0 (05047486b6df5eb8d44b2ecd70ea3bdf775fd937, 2024-01-31T10:28:19.990Z) OS version: Windows_NT x64 10.0.19045 Modes: Remote OS version: Linux x64 5.10.102.1-microsoft-standard-WSL2 Remote OS version: Linux x64 5.10.102.1-microsoft-standard-WSL2

System Info |Item|Value| |---|---| |CPUs|Intel(R) Xeon(R) E-2276M CPU @ 2.80GHz (12 x 2808)| |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)|63.73GB (21.73GB free)| |Process Argv|--crash-reporter-id 60e71f16-b92f-4ec7-9f16-2a79533ce536| |Screen Reader|no| |VM|0%| |Item|Value| |---|---| |Remote|Dev Container: RelativityOne Dev Platform| |OS|Linux x64 5.10.102.1-microsoft-standard-WSL2| |CPUs|Intel(R) Xeon(R) E-2276M CPU @ 2.80GHz (12 x 2807)| |Memory (System)|49.99GB (43.69GB free)| |VM|0%| |Item|Value| |---|---| |Remote|Dev Container: C# (.NET)| |OS|Linux x64 5.10.102.1-microsoft-standard-WSL2| |CPUs|Intel(R) Xeon(R) E-2276M CPU @ 2.80GHz (12 x 2807)| |Memory (System)|49.99GB (43.69GB free)| |VM|0%|
A/B Experiments ``` vsliv368:30146709 vspor879:30202332 vspor708:30202333 vspor363:30204092 vstes627:30244334 vscod805cf:30301675 binariesv615:30325510 vsaa593:30376534 py29gd2263:30899288 c4g48928:30535728 azure-dev_surveyone:30548225 2i9eh265:30646982 962ge761:30951796 pythongtdpath:30769146 welcomedialog:30910333 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30936856 pyreplss1:30897532 pythonmypyd1:30879173 pythoncet0:30885854 pythontbext0:30879054 accentitlementsc:30887149 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 dsvsc019bcf:30953938 3ef8e399:30949928 ```
ajwells128 commented 9 months ago

Here's the full C# log -- looking a little closer, I'm wondering if the project gets loaded once and then never refreshed. The Program.cs file is also a Miscellaneous file until the project gets loaded, then becomes a Host file, and the word Project never appears again after that. The new file should become part of the project dynamically but there's no mention of the project being refreshed.

csharp.log

ajwells128 commented 8 months ago

Seems possibly the same issue as https://github.com/dotnet/vscode-csharp/issues/5882 and related to https://github.com/dotnet/vscode-csharp/issues/5853 but reloading the window doesn't always help (sometimes it does)

arunchndr commented 6 months ago

The above dup find looks accurate. We ll track on the vscode-csharp repo. This is also what kicked off the additional file telemetry monitoring v-team to catch issues, so we should have a handle on this soon.