dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.83k stars 659 forks source link

Omnisharp does not detect fixed code until restart or manual build for certain error types #4185

Open stewartadam opened 3 years ago

stewartadam commented 3 years ago

Issue Description

Certain error types are reported by omnisharp but do not disappear when fixed; a manual restart or build is required to make omnisharp recognize the code is now valid.

I can reproduce with the BOM rule (SA1412) reliably; I've also seen it intermittently with newlines following opening brace (SA1505).

Steps to Reproduce

  1. Open a file with code errors
  2. Fix errors, save file. Omnisharp still shows errors.
  3. F5 to build & debug or or restart omnisharp, and errors will dissapear.

Expected Behavior

Omnisharp removes errors no longer present in codebase

Actual Behavior

Omnisharp hangs on to reported errors until next build

Logs

OmniSharp log

Starting OmniSharp server at 11/5/2020, 9:12:24 AM
    Target: /Users/stewartadam/TestTool/ValidationTool.sln

OmniSharp server started.
    Path: /Users/stewartadam/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.4-beta.20/run
    PID: 28751

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on MacOS 10.15.7 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 16.8.0 - "/Users/stewartadam/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.4-beta.20/omnisharp/.msbuild/Current/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to '/Users/stewartadam/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.4-beta.20/omnisharp/.msbuild/Current/Bin/MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 16.8.0 - "/Users/stewartadam/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.4-beta.20/omnisharp/.msbuild/Current/Bin"
            CscToolExe = csc.exe
            MSBuildToolsPath = /Users/stewartadam/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.4-beta.20/omnisharp/.msbuild/Current/Bin
            CscToolPath = /Users/stewartadam/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.4-beta.20/omnisharp/.msbuild/Current/Bin/Roslyn
            BypassFrameworkInstallChecks = true
            MSBuildExtensionsPath = /Users/stewartadam/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.4-beta.20/omnisharp/.msbuild
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/Users/stewartadam/TestTool'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in '/Users/stewartadam/TestTool/ValidationTool.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/stewartadam/TestTool/ConsoleApp/ConsoleApp.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/stewartadam/TestTool/ValidatorTool/ValidatorTool.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/stewartadam/TestTool/ValidatorToolTests/ValidatorToolTests.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/Users/stewartadam/TestTool'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/stewartadam/TestTool/ConsoleApp/ConsoleApp.csproj
[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.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/Users/stewartadam/TestTool' on host 25807.
[warn]: OmniSharp.MSBuild.ProjectLoader
        Package 'FluentHub 1.0.40' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
[warn]: OmniSharp.MSBuild.ProjectLoader
        Package 'FluentHub.Validation 1.0.40' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/stewartadam/TestTool/ConsoleApp/ConsoleApp.csproj'.
/Users/stewartadam/TestTool/ConsoleApp/ConsoleApp.csproj
/Users/stewartadam/TestTool/ConsoleApp/ConsoleApp.csproj(0,0): Error: Package 'FluentHub 1.0.40' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
/Users/stewartadam/TestTool/ConsoleApp/ConsoleApp.csproj(0,0): Error: Package 'FluentHub.Validation 1.0.40' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.

[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/stewartadam/TestTool/ConsoleApp/ConsoleApp.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/stewartadam/TestTool/ValidatorTool/ValidatorTool.csproj
[warn]: OmniSharp.MSBuild.ProjectLoader
        Package 'FluentHub 1.0.40' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
[warn]: OmniSharp.MSBuild.ProjectLoader
        Package 'FluentHub.Validation 1.0.40' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/stewartadam/TestTool/ValidatorTool/ValidatorTool.csproj'.
/Users/stewartadam/TestTool/ValidatorTool/ValidatorTool.csproj
/Users/stewartadam/TestTool/ValidatorTool/ValidatorTool.csproj(0,0): Error: Package 'FluentHub 1.0.40' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
/Users/stewartadam/TestTool/ValidatorTool/ValidatorTool.csproj(0,0): Error: Package 'FluentHub.Validation 1.0.40' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.

[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/stewartadam/TestTool/ValidatorTool/ValidatorTool.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/stewartadam/TestTool/ValidatorToolTests/ValidatorToolTests.csproj
[warn]: OmniSharp.MSBuild.ProjectLoader
        Package 'FluentHub 1.0.40' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
[warn]: OmniSharp.MSBuild.ProjectLoader
        Package 'FluentHub.Validation 1.0.40' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/stewartadam/TestTool/ValidatorToolTests/ValidatorToolTests.csproj'.
/Users/stewartadam/TestTool/ValidatorToolTests/ValidatorToolTests.csproj
/Users/stewartadam/TestTool/ValidatorToolTests/ValidatorToolTests.csproj(0,0): Error: Package 'FluentHub 1.0.40' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
/Users/stewartadam/TestTool/ValidatorToolTests/ValidatorToolTests.csproj(0,0): Error: Package 'FluentHub.Validation 1.0.40' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.

[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/stewartadam/TestTool/ValidatorToolTests/ValidatorToolTests.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: ConsoleApp
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: ValidatorTool
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: ValidatorToolTests
[info]: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers
        Solution initialized -> queue all documents for code analysis. Initial document count: 29.
[info]: OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.RunCodeActionService
        Applying code action: using System.Threading.Tasks;
[info]: OmniSharp.DotNetTest.VSTestManager
        read: {"MessageType":"TestSession.Connected","Payload":null}
[info]: OmniSharp.DotNetTest.VSTestManager
        read: {"MessageType":"ProtocolVersion","Payload":1}
[info]: OmniSharp.DotNetTest.DebugSessionManager
        Debug session started.
[info]: OmniSharp.DotNetTest.DebugSessionManager
        Debug session ended.
[info]: OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.RunCodeActionService
        Applying code action: using Microsoft.Extensions.Configuration;
[info]: OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.RunCodeActionService
        Applying code action: Convert to binary
[info]: OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.RunCodeActionService
        Applying code action: using System;
[info]: OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.RunCodeActionService
        Applying code action: using System;
[info]: OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.RunCodeActionService
        Applying code action: Use discard '_'

C# log

Getting latest OmniSharp version information
Downloading package 'Latest OmniSharp Version Information' (1 KB).................... Done!
Getting latest OmniSharp version information
Downloading package 'Latest OmniSharp Version Information' (1 KB).................... Done!
Getting latest OmniSharp version information
Downloading package 'Latest OmniSharp Version Information' (1 KB).................... Done!
Getting latest OmniSharp version information
Downloading package 'Latest OmniSharp Version Information' (1 KB).................... Done!
Getting latest OmniSharp version information
Downloading package 'Latest OmniSharp Version Information' (1 KB).................... Done!
Getting latest OmniSharp version information
Downloading package 'Latest OmniSharp Version Information' (1 KB).................... Done!
Getting latest OmniSharp version information
Downloading package 'Latest OmniSharp Version Information' (1 KB).................... Done!

Environment information

VSCode version: 1.50.1 C# Extension: 1.23.5

Mono Information OmniSharp using built-in mono
Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.403 Commit: 9e895200cd Runtime Environment: OS Name: Mac OS X OS Version: 10.15 OS Platform: Darwin RID: osx.10.15-x64 Base Path: /usr/local/share/dotnet/sdk/3.1.403/ Host (useful for support): Version: 3.1.9 Commit: 774fc3d6a9 .NET Core SDKs installed: 3.1.403 [/usr/local/share/dotnet/sdk] .NET Core runtimes installed: Microsoft.AspNetCore.App 3.1.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |aadb2c|AzureADB2CTools|1.2.93| |azure-account|ms-vscode|0.9.3| |azurerm-vscode-tools|msazurermtools|0.13.0| |code-spell-checker|streetsidesoftware|1.9.2| |cortex-debug|marus25|0.3.7| |cpptools|ms-vscode|1.0.1| |csharp|ms-dotnettools|1.23.5| |CursorColumnSelectOnTrueLines|martinzimmermannapps|0.0.2| |docomment|k--kato|0.1.18| |EditorConfig|EditorConfig|0.15.1| |gitlens|eamodio|10.2.3| |go|golang|0.18.1| |kubernetes-context|Okteto|0.1.0| |markdown-all-in-one|yzhang|3.3.0| |markdown-mermaid|bierner|1.8.1| |markdown-preview-enhanced|shd101wyy|0.5.13| |mssql|ms-mssql|1.9.0| |prettier-vscode|esbenp|5.7.1| |python|ms-python|2020.10.332292344| |remote-wsl|ms-vscode-remote|0.50.1| |scala|scala-lang|0.4.5| |sublime-keybindings|ms-vscode|4.0.7| |terraform|hashicorp|2.2.3| |vscode-azurefunctions|ms-azuretools|1.0.0| |vscode-azureresourcegroups|ms-azuretools|0.2.0| |vscode-azurestorage|ms-azuretools|0.11.0| |vscode-cosmosdb|ms-azuretools|0.15.0| |vscode-docker|ms-azuretools|1.7.0| |vscode-dotnet-adapter|derivitec-ltd|1.4.3| |vscode-dotnet-runtime|ms-dotnettools|0.1.2| |vscode-drawio|hediet|1.0.3| |vscode-html-css|ecmel|0.2.3| |vscode-icons|vscode-icons-team|11.0.0| |vscode-kubernetes-tools|ms-kubernetes-tools|1.2.1| |vscode-markdownlint|DavidAnson|0.37.2| |vscode-node-azure-pack|ms-vscode|0.0.11| |vscode-solution-explorer|fernandoescolar|0.3.11| |vscode-test-explorer|hbenl|2.19.1| |vscode-yaml|redhat|0.12.0| |vsliveshare|ms-vsliveshare|1.0.3121| |xml|DotJoshJohnson|2.5.1|;
webczat commented 3 years ago

what about the one where it cannot find a symbol because the type doesn't exist, you add the type, error still there

stewartadam commented 3 years ago

Yes, not sure if that is related as in the above I'm seeing certain errors persist on files that are otherwise being analyzed, I think there may be a separate issue around namespace discovery (adding or moving files) where those files don't get included for analysis until Omnisharp restart.