vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

CsWin32 only generates when vscode is reloaded

Open FileOfName opened this issue 1 year ago • 1 comments

Issue Description

CsWin32 is

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.

And in vscode it only updates after reloading. CsWin32 link

Steps to Reproduce

  1. Create a new console project (dotnet new console -o <project_name>)
  2. Open the folder in vscode
  3. Add NuGet package CsWin32 (dotnet add package Microsoft.Windows.CsWin32 --version 0.2.63-beta)
  4. Create a file named NativeMethods.txt and in it write MessageBox

Expected Behavior

MessageBox should be now a method in the class Windows.Win32.PInvoke

Actual Behavior

MessageBox is not a method in class Windows.Win32.PInvoke and only becomes one after reloading vscode

Only vscode does not update, running dotnet run proves that Windows.Win32.PInvoke.MessageBox() does exist.

Logs

OmniSharp log

Starting OmniSharp server at 8. 10. 2022, 11:23:14 Target: c:\Users\username\Desktop\example

OmniSharp server started with .NET 6.0.401 . Path: c:\Users\username\.vscode\extensions\ms-dotnettools.csharp-1.25.0-win32-x64.omnisharp\1.39.0-net6.0\OmniSharp.dll PID: 14424

Starting OmniSharp on Windows 10.0.22621.0 (x64) info: OmniSharp.Services.DotNetCliService Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK info: OmniSharp.Services.DotNetCliService Using the 'dotnet' on the PATH. info: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet info: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 2 MSBuild instance(s) 1: .NET Core SDK 6.0.401 17.3.1 - "C:\Program Files\dotnet\sdk\6.0.401" 2: .NET Core SDK 6.0.304 17.2.0 - "C:\Program Files\dotnet\sdk\6.0.304" info: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: .NET Core SDK 6.0.401 17.3.1 - "C:\Program Files\dotnet\sdk\6.0.401" info: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0 info: OmniSharp.MSBuild.ProjectSystem No solution files found in 'c:\Users\username\Desktop\example' info: OmniSharp.MSBuild.ProjectManager Queue project update for 'c:\Users\username\Desktop\example\example.csproj' info: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in 'c:\Users\username\Desktop\example'. info: OmniSharp.Script.ScriptProjectSystem Did not find any CSX files info: OmniSharp.WorkspaceInitializer Configuration finished. info: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location 'c:\Users\username\Desktop\example' on host 28140. info: OmniSharp.MSBuild.ProjectManager Loading project: c:\Users\username\Desktop\example\example.csproj info: OmniSharp.MSBuild.ProjectManager Successfully loaded project file 'c:\Users\username\Desktop\example\example.csproj'. info: OmniSharp.MSBuild.ProjectManager Adding project 'c:\Users\username\Desktop\example\example.csproj' info: OmniSharp.MSBuild.ProjectManager Update project: example info: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers Solution initialized -> queue all documents for code analysis. Initial document count: 4. info: OmniSharp.MSBuild.ProjectManager Queue project update for 'c:\Users\username\Desktop\example\example.csproj' info: OmniSharp.MSBuild.ProjectManager Queue project update for 'c:\Users\username\Desktop\example\example.csproj' info: OmniSharp.MSBuild.ProjectManager Queue project update for 'c:\Users\username\Desktop\example\example.csproj' info: OmniSharp.MSBuild.ProjectManager Loading project: c:\Users\username\Desktop\example\example.csproj info: OmniSharp.MSBuild.ProjectManager Successfully loaded project file 'c:\Users\username\Desktop\example\example.csproj'. info: OmniSharp.MSBuild.ProjectManager Update project: example info: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Users\username\.nuget\packages\microsoft.windows.cswin32\0.2.63-beta\analyzers\cs\MessagePack.Annotations.dll info: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Users\username\.nuget\packages\microsoft.windows.cswin32\0.2.63-beta\analyzers\cs\MessagePack.dll info: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Users\username\.nuget\packages\microsoft.windows.cswin32\0.2.63-beta\analyzers\cs\Microsoft.Bcl.AsyncInterfaces.dll info: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Users\username\.nuget\packages\microsoft.windows.cswin32\0.2.63-beta\analyzers\cs\Microsoft.Windows.CsWin32.dll info: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Users\username\.nuget\packages\microsoft.windows.cswin32\0.2.63-beta\analyzers\cs\Microsoft.Windows.SDK.Win32Docs.dll info: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Users\username\.nuget\packages\microsoft.windows.cswin32\0.2.63-beta\analyzers\cs\System.Buffers.dll info: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Users\username\.nuget\packages\microsoft.windows.cswin32\0.2.63-beta\analyzers\cs\System.Memory.dll info: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Users\username\.nuget\packages\microsoft.windows.cswin32\0.2.63-beta\analyzers\cs\System.Numerics.Vectors.dll info: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Users\username\.nuget\packages\microsoft.windows.cswin32\0.2.63-beta\analyzers\cs\System.Runtime.CompilerServices.Unsafe.dll info: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Users\username\.nuget\packages\microsoft.windows.cswin32\0.2.63-beta\analyzers\cs\System.Text.Encodings.Web.dll info: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Users\username\.nuget\packages\microsoft.windows.cswin32\0.2.63-beta\analyzers\cs\System.Text.Json.dll info: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Users\username\.nuget\packages\microsoft.windows.cswin32\0.2.63-beta\analyzers\cs\System.Threading.Tasks.Extensions.dll Received response for /inlayHint/resolve but could not find request. [fail]: OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.GetCodeActionsService Error registering code fixes for Microsoft.CodeAnalysis.CSharp.CodeFixes.FullyQualify.CSharpFullyQualifyCodeFixProvider System.InvalidOperationException: Sequence contains no matching element at System.Linq.ThrowHelper.ThrowNoMatchException() at System.Linq.Enumerable.First[TSource](IEnumerable1 source, Func2 predicate) at Microsoft.CodeAnalysis.CodeFixes.FullyQualify.AbstractFullyQualifyCodeFixProvider.RegisterCodeFixesAsync(CodeFixContext context) at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService2.AppendFixesAsync(Document document, TextSpan span, IEnumerable1 diagnostics, List1 codeActions) in D:\a\1\s\src\OmniSharp.Roslyn.CSharp\Services\Refactoring\V2\BaseCodeActionService.cs:line 158 [fail]: OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.GetCodeActionsService Error registering code fixes for Microsoft.CodeAnalysis.CSharp.SpellCheck.CSharpSpellCheckCodeFixProvider System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'span') at Microsoft.CodeAnalysis.SyntaxNode.FindNode(TextSpan span, Boolean findInsideTrivia, Boolean getInnermostNodeForTie) at Microsoft.CodeAnalysis.SpellCheck.AbstractSpellCheckCodeFixProvider1.RegisterCodeFixesAsync(CodeFixContext context) at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService2.AppendFixesAsync(Document document, TextSpan span, IEnumerable1 diagnostics, List`1 codeActions) in D:\a\1\s\src\OmniSharp.Roslyn.CSharp\Services\Refactoring\V2\BaseCodeActionService.cs:line 158 Received response for /v2/getcodeactions but could not find request.

C# log

None

Environment information

VSCode version: 1.72.0 C# Extension: 1.25.0

Dotnet Information .NET SDK (reflecting any global.json): Version: 6.0.401 Commit: 0906eae6f8

Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.401\

global.json file: Not Found

Host: Version: 6.0.9 Architecture: x64 Commit: 163a63591c

.NET SDKs installed: 6.0.304 [C:\Program Files\dotnet\sdk] 6.0.401 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.9 [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.9 [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.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Download .NET: https://aka.ms/dotnet-download

Learn about .NET Runtimes and SDKs: https://aka.ms/dotnet/runtimes-sdk-info

Visual Studio Code Extensions
Extension Author Version
code-spell-checker streetsidesoftware 2.10.1
csharp ms-dotnettools 1.25.0
dotnet-interactive-vscode ms-dotnettools 1.0.3504060
gitlens eamodio 12.2.2
Ionide-fsharp Ionide 7.2.3
jupyter ms-toolsai 2022.9.1002791758
jupyter-keymap ms-toolsai 1.0.0
jupyter-renderers ms-toolsai 1.0.10
material-theme zhuangtongfa 3.15.5
todo-tree Gruntfuggly 0.0.215
vscode-dotnet-pack ms-dotnettools 1.0.9
vscode-dotnet-sdk ms-dotnettools 0.8.0
vscode-icons vscode-icons-team 11.19.0
vscode-jupyter-cell-tags ms-toolsai 0.1.6
vscode-jupyter-slideshow ms-toolsai 0.1.5

FileOfName avatar Oct 08 '22 14:10 FileOfName

This issue seems to be that O# doesn't have file watchers for "AdditionalFiles" such as the NativeMethods.txt used by the CsWin32 source generator. Since the file is added after the workspace is loaded, the additional file is never added to the workspace which the generator runs against.

JoeRobich avatar Oct 12 '22 22:10 JoeRobich

I face the same issue. Source Generator generates new sources based on AdditionalFiles. When I add new AdditiopnalFile into project, then in Visual Studio it generates new source, but not in Visual Studio Code. If I restart Visual Studio Code, then new classes become available for usage (I mean intellisense).

nvborisenko avatar Nov 11 '22 09:11 nvborisenko

@JoeRobich if you can expand more details on how to fix it, it will be great for potential contributors.

What I see:

  • vscode sends a request fileCreated/fileSaved/fileDeleted for AdditionalFile (not C#)
  • then omnisharp.stdio handles it does nothing

If you can describe what stdio should do, then may probably I can help translate it to C#.

nvborisenko avatar May 07 '23 15:05 nvborisenko