Skip to content
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

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

Open
awteeter opened this issue Sep 9, 2021 · 10 comments

Comments

@awteeter
Copy link

awteeter commented Sep 9, 2021

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

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

  • Install VS Code and its C# extension

  • Enable "Roslyn Analyzers" under VS Code's OmniSharp settings
    image

  • OR in the OmniSharp.json
    image

  • Create a new C# project either externally or through a .NET terminal

  • Have multiple files defined in the project

  • Have references to fields, variables or methods in another file than the one they originate in

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)

@awteeter awteeter changed the title Enabling Roslyn Analyzers prevents OmniSharp project-wide error reporting / resolution Enabling 'Roslyn Analyzers' prevents OmniSharp project-wide error reporting / resolution Sep 9, 2021
@T3kla
Copy link

T3kla commented Sep 22, 2021

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
Copy link
Author

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
Copy link

T3kla commented Sep 23, 2021

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
Copy link
Author

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
Copy link

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
Copy link

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

@X9VoiD
Copy link

X9VoiD commented Aug 14, 2022

Any news for this issue?

@XorZy
Copy link

XorZy commented Aug 21, 2022

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
Copy link

XorZy commented Jan 15, 2023

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

@uinteger32
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants