dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.86k stars 672 forks source link

Warnings are not displayed in the problems panel #3165

Open AnthonyMastrean opened 5 years ago

AnthonyMastrean commented 5 years ago

Issue Description

Warnings are not displayed in the problems panel.

Steps to Reproduce

Add some code, to, literally, any kind of csharp project, that usually produces a warning, for example, an unused field.

private readonly string example;

The dotnet build command line complains

PS> dotnet build
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 3.3 sec for C:\Users\anthony\example\src\Example\Example.csproj.
Startup.cs(16,24): warning CS0169: The field 'Startup.example' is never used [C:\Users\anthony\example\src\Example\Example.csproj]
  Example -> C:\Users\anthony\example\src\Example\bin\Debug\netcoreapp2.2\Example.dll

Build succeeded.

Startup.cs(16,24): warning CS0169: The field 'Startup.example' is never used [C:\Users\anthony\example\src\Example\Example.csproj]
    1 Warning(s)
    0 Error(s)

Time Elapsed 00:00:06.30

Expected Behavior

Warnings should be displayed in the problems panel.

Actual Behavior

Warnings are not displayed in the problems panel.

Logs

OmniSharp log

Post the output from Output-->OmniSharp log here

C# log

Post the output from Output-->C# here

Environment information

VSCode version: 1.36.1 C# Extension: 1.20.0

Dotnet Information .NET Core SDK (reflecting any global.json): Version: 2.2.105 Commit: 7cecb35b92 Runtime Environment: OS Name: Windows OS Version: 10.0.18362 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.2.105\ Host (useful for support): Version: 2.2.3 Commit: 6b8ad509b6 .NET Core SDKs installed: 2.2.100 [C:\Program Files\dotnet\sdk] 2.2.102 [C:\Program Files\dotnet\sdk] 2.2.104 [C:\Program Files\dotnet\sdk] 2.2.105 [C:\Program Files\dotnet\sdk] .NET Core runtimes installed: Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.3 [C:\Program Files\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| |---|---|---| |csharp|ms-vscode|1.20.0| |EditorConfig|EditorConfig|0.13.0| |powershell|ms-vscode|2019.5.0| |prettier-vscode|esbenp|1.9.0| |puppet-vscode|jpogran|0.18.1| |remote-containers|ms-vscode-remote|0.66.0| |remote-ssh|ms-vscode-remote|0.44.0| |remote-ssh-edit|ms-vscode-remote|0.44.0| |remote-ssh-explorer|ms-vscode-remote|0.44.0| |remote-wsl|ms-vscode-remote|0.38.9| |synthwave-vscode|RobbOwen|0.0.7| |theme-panda|tinkertrain|1.3.0| |vscode-docker|ms-azuretools|0.7.0| |vscode-peacock|johnpapa|2.4.0| |vscode-remote-extensionpack|ms-vscode-remote|0.15.0| |vscode-terminals|fabiospampinato|1.12.6| |vsliveshare|ms-vsliveshare|1.0.509| |vsliveshare-audio|ms-vsliveshare|0.1.59| |vsliveshare-pack|ms-vsliveshare|0.3.2| |xml|DotJoshJohnson|2.5.0|;
AnthonyMastrean commented 5 years ago

For what's it's worth, warnings that are upgraded to errors are also not displayed.

Example.csproj

  <PropertyGroup>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>
filipw commented 5 years ago

CS0169 is a build diagnostic, you need to run a build ctrl+shift+b for it to show up, it cannot be shown otherwise (same in Visual Studio).

If you'd like to get the diagnostics around unused members from intellisense immediately upon typing, without building, that's IDE0051 diagnostic from roslyn analyzers. For it to work you need to enable "omnisharp.enableRoslynAnalyzers": true setting.

AnthonyMastrean commented 5 years ago

I don't see any Problems picked up when running the default build task (this was created automatically by Code).

        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/src/Example/Example.csproj"
            ],
            "problemMatcher": "$tsc"
        },

code-build-warning

AnthonyMastrean commented 5 years ago

The "Enable Roslyn Analyzers" option is working pretty nicely. Although, it's marking all Problems as "info" and I'd love to crank that up to "error" 😁

image

RaZeR-RBI commented 3 years ago

I don't see any Problems picked up when running the default build task (this was created automatically by Code).

@AnthonyMastrean Not sure if this is still actual for you, but it seems to be the problemMatcher field value is wrong here - I think it should be $msCompile instead of $tsc (which, if I understand correctly, refers to the TypeScript compiler output parser).