dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.88k stars 676 forks source link

Watched file change generating invalid paths #7693

Open RivenSkaye opened 1 month ago

RivenSkaye commented 1 month ago

Type: Bug

Issue Description

Having watched files or paths is causing the workspace/didChangeWatchedFiles handler to try and 1:1 tranlate a glob pattern (valid paths can include .. anywhere) to a regular expression (very different semantics surrounding ..). This is causing a stacktrace dump on every single edit for watched files. Which includes all .cs files by default! The annoying thing is that I can't get this to reproduce upon first opening a project, but the repro steps account for that.

Steps to Reproduce

Expected Behavior

Watched files being processed regardless of file extension.

Actual Behavior

Only the text fragment/document requests succeed for things when explicitly passed to the LSP.

Logs

This one's dumped regardless:


[LanguageServerHost] [09:13:07.531][Start]workspace/didChangeWatchedFiles
[Error - 11:13:07 AM] [LanguageServerHost] System.ArgumentException: ".." can be only added at the beginning of the pattern.
   at Microsoft.Extensions.FileSystemGlobbing.Internal.Patterns.PatternBuilder.Build(String pattern)
   at Microsoft.Extensions.FileSystemGlobbing.Matcher.AddInclude(String pattern)
   at Microsoft.Extensions.FileSystemGlobbing.MatcherExtensions.AddIncludePatterns(Matcher matcher, IEnumerable`1[] includePatternsGroups)
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.<>c.b__18_19(FileGlobs glob) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 230
   at System.Linq.Enumerable.SelectArrayIterator`2.Fill(ReadOnlySpan`1 source, Span`1 destination, Func`2 func)
   at System.Linq.Enumerable.SelectArrayIterator`2.ToArray()
   at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
--- End of stack trace from previous location ---
   at System.LazyHelper.ThrowException()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.FileChangedContext_FileChanged(Object sender, String filePath) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 76
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.FileWatching.LspFileChangeWatcher.FileChangeContext.WatchedFilesHandler_OnNotificationRaised(Object sender, DidChangeWatchedFilesParams e) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspFileChangeWatcher.cs:line 103
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.FileWatching.LspDidChangeWatchedFilesHandler.Microsoft.CommonLanguageServerProtocol.Framework.INotificationHandler.HandleNotificationAsync(DidChangeWatchedFilesParams request, RequestContext requestContext, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/FileWatching/LspDidChangeWatchedFilesHandler.cs:line 28
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`1.StartRequestAsync[TRequest,TResponse](TRequest request, TRequestContext context, IMethodHandler handler, String language, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 199
[LanguageServerHost] [09:13:07.534][End]workspace/didChangeWatchedFiles

C# LSP Trace Logs

I would've pasted this in as a code block, but instead I learned issues have a hard upper bound character maximum today! csharp-lsp-trace.log.txt

C# log

Less big but still big csharp-lsp.log.txt

Environment information

VSCode version: 1.94.2 C# Extension: 2.50.27 Using OmniSharp: false

Dotnet Information .NET SDK: Version: 8.0.400 Commit: 36fe6dda56 Workload version: 8.0.400-manifests.6c274a57 MSBuild version: 17.11.3+0c8610977 Runtime Environment: OS Name: Windows OS Version: 10.0.19045 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.400\ .NET workloads installed: Configured to use loose manifests when installing new manifests. There are no installed workloads to display. Host: Version: 8.0.8 Architecture: x64 Commit: 08338fcaa5 .NET SDKs installed: 7.0.317 [C:\Program Files\dotnet\sdk] 7.0.408 [C:\Program Files\dotnet\sdk] 7.0.410 [C:\Program Files\dotnet\sdk] 8.0.204 [C:\Program Files\dotnet\sdk] 8.0.206 [C:\Program Files\dotnet\sdk] 8.0.400 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation] 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 According to the trace log, none of these register anything with the C# extension |Extension|Author|Version|Folder Name| |---|---|---|---| |apc-extension|drcika|0.4.1|drcika.apc-extension-0.4.1| |autodocstring|njpwerner|0.6.1|njpwerner.autodocstring-0.6.1| |avalonia-templates|ADdy2142|0.0.15|addy2142.avalonia-templates-0.0.15| |better-cpp-syntax|jeff-hykin|1.27.1|jeff-hykin.better-cpp-syntax-1.27.1| |c-sharp-utilities|revrenlove|1.12.4|revrenlove.c-sharp-utilities-1.12.4| |csharp|ms-dotnettools|2.50.27|ms-dotnettools.csharp-2.50.27-win32-x64| |csharp-grammar-extended|dannymcgee|1.1.1|dannymcgee.csharp-grammar-extended-1.1.1| |debugpy|ms-python|2024.12.0|ms-python.debugpy-2024.12.0-win32-x64| |dependi|fill-labs|0.7.10|fill-labs.dependi-0.7.10| |docomment|k--kato|1.0.0|k--kato.docomment-1.0.0| |doki-theme|unthrottled|88.1.18|unthrottled.doki-theme-88.1.18| |EditorConfig|EditorConfig|0.16.4|editorconfig.editorconfig-0.16.4| |errorlens|usernamehw|3.20.0|usernamehw.errorlens-3.20.0| |even-better-toml|tamasfe|0.19.2|tamasfe.even-better-toml-0.19.2| |fastendpoints|drilko|1.2.1|drilko.fastendpoints-1.2.1| |githistory|donjayamanne|0.6.20|donjayamanne.githistory-0.6.20| |gitlens|eamodio|15.6.2|eamodio.gitlens-15.6.2| |glysis|GlysisSoftware|1.1.0|glysissoftware.glysis-1.1.0| |go|golang|0.42.1|golang.go-0.42.1| |graphviz-interactive-preview|tintinweb|0.3.5|tintinweb.graphviz-interactive-preview-0.3.5| |hexeditor|ms-vscode|1.10.0|ms-vscode.hexeditor-1.10.0| |html-entities|christopherstyles|1.1.2|christopherstyles.html-entities-1.1.2| |inline-sql-syntax|qufiwefefwoyn|2.16.0|qufiwefefwoyn.inline-sql-syntax-2.16.0| |isort|ms-python|2023.10.1|ms-python.isort-2023.10.1| |lotus-theme|SkyLiss|1.1.4|skyliss.lotus-theme-1.1.4| |makefile-tools|ms-vscode|0.11.13|ms-vscode.makefile-tools-0.11.13| |markdown-all-in-one|yzhang|3.6.2|yzhang.markdown-all-in-one-3.6.2| |mermaid-markdown-syntax-highlighting|bpruitt-goddard|1.6.6|bpruitt-goddard.mermaid-markdown-syntax-highlighting-1.6.6| |msbuild-project-tools|tintoy|0.6.6|tintoy.msbuild-project-tools-0.6.6| |mypy|matangover|0.4.0|matangover.mypy-0.4.0| |php-debug|xdebug|1.35.0|xdebug.php-debug-1.35.0| |php-intellisense|zobo|1.3.3|zobo.php-intellisense-1.3.3| |php-pack|xdebug|1.0.3|xdebug.php-pack-1.0.3| |python|ms-python|2024.16.1|ms-python.python-2024.16.1-win32-x64| |python-docs|Mukundan|0.8.3|mukundan.python-docs-0.8.3| |qtvsctools|tonka3000|0.11.0|tonka3000.qtvsctools-0.11.0| |remote-repositories|ms-vscode|0.42.0|ms-vscode.remote-repositories-0.42.0| |resttext|TatsuyaNakamori|0.1.2|tatsuyanakamori.resttext-0.1.2| |resxpress|PrateekMahendrakar|6.1.1|prateekmahendrakar.resxpress-6.1.1| |ruff|charliermarsh|2024.52.0|charliermarsh.ruff-2024.52.0-win32-x64| |rust-analyzer|rust-lang|0.4.2158|rust-lang.rust-analyzer-0.4.2158-win32-x64| |scss-lint|adamwalzer|0.1.11|adamwalzer.scss-lint-0.1.11| |se-csproj-extensions|selcukermaya|0.0.7|selcukermaya.se-csproj-extensions-0.0.7| |shopify-liquid|sissel|4.0.1|sissel.shopify-liquid-4.0.1| |svg-preview|SimonSiefke|2.8.3|simonsiefke.svg-preview-2.8.3| |tiffcolors|tiffnix|0.1.5|tiffnix.tiffcolors-0.1.5| |visual-nuget|fullstackspider|0.3.4|fullstackspider.visual-nuget-0.3.4| |vsc-python-indent|KevinRose|1.18.0|kevinrose.vsc-python-indent-1.18.0| |vscode-avalonia-community|microhobby|0.0.35|microhobby.vscode-avalonia-community-0.0.35| |vscode-clangd|llvm-vs-code-extensions|0.1.29|llvm-vs-code-extensions.vscode-clangd-0.1.29| |vscode-dotnet-runtime|ms-dotnettools|2.2.1|ms-dotnettools.vscode-dotnet-runtime-2.2.1| |vscode-eslint|dbaeumer|3.0.10|dbaeumer.vscode-eslint-3.0.10| |vscode-github-actions|github|0.27.0|github.vscode-github-actions-0.27.0| |vscode-gutter-preview|kisstkondoros|0.31.2|kisstkondoros.vscode-gutter-preview-0.31.2| |vscode-html-css|ecmel|2.0.10|ecmel.vscode-html-css-2.0.10| |vscode-lldb|vadimcn|1.11.0|vadimcn.vscode-lldb-1.11.0| |vscode-lua|trixnz|0.12.4|trixnz.vscode-lua-0.12.4| |vscode-markdownlint|DavidAnson|0.56.0|davidanson.vscode-markdownlint-0.56.0| |vscode-mermaid-editor|tomoyukim|0.19.1|tomoyukim.vscode-mermaid-editor-0.19.1| |vscode-modelines|chrislajoie|2.0.6|chrislajoie.vscode-modelines-2.0.6| |vscode-phpfmt|kokororin|1.2.19|kokororin.vscode-phpfmt-1.2.19| |vscode-pylance|ms-python|2024.10.1|ms-python.vscode-pylance-2024.10.1| |vscode-solution-explorer|fernandoescolar|0.8.6|fernandoescolar.vscode-solution-explorer-0.8.6| |vscode-whatthecommit|Gaardsholt|0.2.16|gaardsholt.vscode-whatthecommit-0.2.16| |vscode-yaml-sort|PascalReitermann93|6.5.17|pascalreitermann93.vscode-yaml-sort-6.5.17| |xml|DotJoshJohnson|2.5.1|dotjoshjohnson.xml-2.5.1|;

Extension version: 2.50.27 VS Code version: Code 1.94.2 (384ff7382de624fb94dbaf6da11977bba1ecd427, 2024-10-09T16:08:44.566Z) OS version: Windows_NT x64 10.0.19045 Modes:

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz (4 x 3192)| |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
webnn: disabled_off| |Load (avg)|undefined| |Memory (System)|15.88GB (6.98GB free)| |Process Argv|| |Screen Reader|no| |VM|0%|
RivenSkaye commented 1 month ago

have a free MRE repo. The problem persists after I removed the extra dir as well - but it might be picking up on obj or build. So I didn't run a gitignore, ensuring either one would be present for what should be instant fun?

dibarbet commented 3 weeks ago

It looks like MS.Extensions.FileGlobbing does not have great support for absolute path based globs. (Tangentially related, https://github.com/dotnet/runtime/issues/62333).

A simple repro is to add the following to a project and save any cs file.

<ItemGroup>
  <Compile Include="$(MSBuildThisFileDirectory)../**/*.cs"/>
</ItemGroup>

I suspect we won't be able to use MS.Extensions.FileGlobbing and may need to copy the MSBuild glob evaluator. I recommend if you can to use C# Dev Kit as it should be more robust to these sorts of issues.