dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.87k stars 675 forks source link

Enabling 'Roslyn Analyzers' prevents OmniSharp project-wide error reporting / resolution #4754

Open awteeter opened 3 years ago

awteeter commented 3 years ago

Environment data

.NET info:

.NET SDK (reflecting any global.json): Version: 5.0.400 Commit: d61950f9bf Runtime Environment: OS Name: Windows OS Version: 10.0.19042 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.400\ Host (useful for support): Version: 5.0.9 Commit: 208e377a53 .NET SDKs installed: 5.0.400 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

VS Code version:

Version: 1.60.0 (user setup) Commit: e7d7e9a9348e6a8cc8c03f877d39cb72e5dfb1ff Date: 2021-09-01T10:41:52.311Z Electron: 13.1.8 Chrome: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Windows_NT x64 10.0.19042

C# Extension version: v1.23.15

OmniSharp log

OmniSharp Log Starting OmniSharp server at 2021-09-09, 1:49:41 p.m. Target: c:\Users\-\Test OmniSharp server started. Path: c:\Users\.vscode\extensions\ms-dotnettools.csharp-1.23.15\.omnisharp\1.37.15\OmniSharp.exe PID: 11552 [info]: OmniSharp.Stdio.Host Starting OmniSharp on Windows 6.2.9200.0 (x64) [info]: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 1 MSBuild instance(s) 1: StandAlone 17.0.0 - "c:\Users\.vscode\extensions\ms-dotnettools.csharp-1.23.15\.omnisharp\1.37.15\.msbuild\Current\Bin" [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator MSBUILD_EXE_PATH environment variable set to 'c:\Users\.vscode\extensions\ms-dotnettools.csharp-1.23.15\.omnisharp\1.37.15\.msbuild\Current\Bin\MSBuild.exe' [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: StandAlone 17.0.0 - "c:\Users\.vscode\extensions\ms-dotnettools.csharp-1.23.15\.omnisharp\1.37.15\.msbuild\Current\Bin" CscToolExe = csc.exe CscToolPath = c:\Users\-\.vscode\extensions\ms-dotnettools.csharp-1.23.15\.omnisharp\1.37.15\.msbuild\Current\Bin\Roslyn MSBuildExtensionsPath = c:\Users\.vscode\extensions\ms-dotnettools.csharp-1.23.15\.omnisharp\1.37.15\.msbuild MSBuildToolsPath = c:\Users\.vscode\extensions\ms-dotnettools.csharp-1.23.15\.omnisharp\1.37.15\.msbuild\Current\Bin [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140 [info]: OmniSharp.Cake.CakeProjectSystem Detecting Cake files in 'c:\Users\Test'. [info]: OmniSharp.Cake.CakeProjectSystem Could not find any Cake files [info]: OmniSharp.MSBuild.ProjectSystem No solution files found in 'c:\Users\Test' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for 'c:\Users\Test\Test.csproj' [info]: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in 'c:\Users\Test'. [info]: OmniSharp.Script.ScriptProjectSystem Could not find any CSX files [info]: OmniSharp.WorkspaceInitializer Configuration finished. [info]: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location 'c:\Users\Test' on host 5208. [info]: OmniSharp.MSBuild.ProjectManager Loading project: c:\Users\Test\Test.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file 'c:\Users\Test\Test.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project 'c:\Users\Test\Test.csproj' [info]: OmniSharp.MSBuild.ProjectManager Update project: Test [info]: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers Solution initialized -> queue all documents for code analysis. Initial document count: 4.

Steps to reproduce

Expected behavior

Changing fields in one file should propagate to connected files and reflect the change in the editor automatically, in real-time. e.g. Removing a constant variable used in another file should subsequently produce an error automatically in the "Problems" pane

This is the behaviour when "Roslyn Analyzers is disabled, the editor detects and resolves issues in real time

ezgif com-gif-maker (2)

Actual behavior

Changing, deleting or modifying a field does not update the other open files in the editor, and will not respond to the change unless the affected file is selected and modified, as seen here:

The editor does not detect an error UNTIL the affected file is updated:

ezgif com-gif-maker

The editor does not resolve the error UNTIL the affected file is, again, updated: ezgif com-gif-maker (1)

T3kla commented 3 years ago

Same thing is happening to me in a Unity project. I deleted a namespace expecting every script that used it to go red, but they don't do it until I open them and either modify or save the file. Also a mix of these errors appear in the Output:

Received response for /v2/getcodeactions but could not find request.
Received response for /v2/gotodefinition but could not find request.
No symbol found "name of a script that had the deleted namespace"

Also, enabling or disabling "Roslyn Analyzers" option does nothing, I have this error since I made the project. I'm using the latest version of the Visual Studio Code unity extension and reset solution and projects multiple times.

awteeter commented 3 years ago
Received response for /v2/getcodeactions but could not find request.
Received response for /v2/gotodefinition but could not find request.
No symbol found "name of a script that had the deleted namespace"

I've seen this as well, with Unity projects! This specific instance I used as an example was a native C# project and curiously it didn't appear in the log.

T3kla commented 3 years ago

Found something.

Up until now I had been turning on and off Roslyn analyzers with the settings toggle:

image

Tinkering around today, I found the file that @yoshi45111 talks about in the OP (omnisharp.json) and I noticed that, in the file, EnableAnalyzersSupport was true while the toggle was off, so it should be false. Changed it to false, reloaded VSCode and there you go, project wide error reporting was back.

Turns out that the toggle only modify the line "omnisharp.enableRoslynAnalyzers": true in settings.json, but doesn't change anything from omnisharp.json.

Not only that, but I found why it was turned on in the first place. I tried an extension called Roslynator by @JosefPihrt which adds this chunk of code to omnisharp.json:

"EnableAnalyzersSupport": true,
"LocationPaths": [
    "c:/Users/[Username]/.vscode/extensions/josefpihrt-vscode.roslynator-3.2.2/roslyn/common",
    "c:/Users/[Username]/.vscode/extensions/josefpihrt-vscode.roslynator-3.2.2/roslyn/analyzers",
    "c:/Users/[Username]/.vscode/extensions/josefpihrt-vscode.roslynator-3.2.2/roslyn/refactorings",
    "c:/Users/[Username]/.vscode/extensions/josefpihrt-vscode.roslynator-3.2.2/roslyn/fixes"
]

Even when you uninstall the extension, these changes remain, which is why this value changed for me even tho I have never handled omnisharp.json directly.

And that's it. Mystery solved. At least for me lol.

For anyone looking for omnisharp.json it's in C:\Users\username\.omnisharp\omnisharp.json

awteeter commented 3 years ago

Tinkering around today, I found the file that @yoshi45111 talks about in the OP (omnisharp.json) and I noticed that, in the file, EnableAnalyzersSupport was true while the toggle was off, so it should be false. Turned it to false, reloaded VSCode and there you go, project wide error reporting was back.

This does bring back project-wide error reporting for me, though ideally I would like to keep the Roslynator analyzers AND project-wide reporting. It seems to be one or the other at present unfortunately!

gregor160300 commented 2 years ago

I can confirm this issue exists, both on Windows (11) and Linux (Fedora 35). I think the expected behaviour would be to leave Solution wide error reporting enabled and have Roslyn analyzers enabled at the same time, thus also showing all the warnings, informations etc. that the Roslyn analyzer produces for the entire project and not just for the opened file(s).

youegraillot commented 2 years ago

Also happening in vscode 1.63.2 (c# extension v1.23.17) with .net core 3.1

X9VoiD commented 2 years ago

Any news for this issue?

XorZy commented 2 years ago

The issue is still present with version ms-dotnettools.csharp-1.25.0-linux-x64 .NET 6.0.108. The workaround mentioned by T3kla works, but it would be preferable to have both working at the same time.

When setting "EnableAnalyzersSupport": true,

The log is filled with messages like this one : Received response for /completion but could not find request. And solution-wide analysis stops working as expected

XorZy commented 1 year ago

Any news? It's been over two years and there does not seem to be any indication that this will ever be fixed.

uinteger32 commented 1 year ago

Having the same issue on vscode 1.77.3. (c# extension v1.25.4, .net sdk 6)