OmniSharp / omnisharp-vim

Vim omnicompletion (intellisense) and more for C#
http://www.omnisharp.net
MIT License
1.72k stars 168 forks source link

Roslyn analyzers not working #828

Closed WhiteBlackGoose closed 1 year ago

WhiteBlackGoose commented 1 year ago

Hello, and thanks for this amazing plugin.

For some reason, cannot get roslyn analyzers to work.

Repro:

dotnet add package Microsoft.CodeAnalysis.PublicApiAnalyzers

and Program.cs:

Console.Write("Hewo");
public class Aaa {
    public int Aaaa() => 4;
}

Tried net6 and net7 as TFM.

If you use dotnet build, it will complain about new API added. But no linting in the editor

Software versions

Latest omnisharp-vim and latest O# server

$ nvim --version
NVIM v0.9.0-dev-441+g5c9bf0ea7
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by goose@samsung-debian

.../omnisharp-vim
$ git rev-parse HEAD
0b643d4564207e85d19b94180e6ab2e89e7f9c50

$ dotnet --list-sdks
6.0.306 [/home/goose/programs/dotnet-folder/sdk]
7.0.100 [/home/goose/programs/dotnet-folder/sdk]

$ uname -a
Linux samsung-debian 5.10.0-18-amd64 #1 SMP Debian 5.10.140-1 (2022-09-02) x86_64 GNU/Linux
nickspoons commented 1 year ago

Hi @WhiteBlackGoose, sorry for the slow response, it's tricky to find a spare moment at this time of year.

scrot_2022-12-24_120133

When I open your example program in OmniSharp-vim, I do get ALE diagnostics from the analyzer, and you can see them here listed in the quickfix list as the result of running :OmniSharpGlobalCodeCheck.

My dotnet --info looks like this:

❯ dotnet --info
.NET SDK:
 Version:   7.0.101
 Commit:    bb24aafa11

Runtime Environment:
 OS Name:     pop
 OS Version:  22.04
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/7.0.101/

Host:
  Version:      7.0.1
  Architecture: x64
  Commit:       97203d38ba

.NET SDKs installed:
  6.0.404 [/usr/share/dotnet/sdk]
  7.0.100-preview.4.22252.9 [/usr/share/dotnet/sdk]
  7.0.101 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.12 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0-preview.4.22251.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.12 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0-preview.4.22229.4 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/usr/lib/dotnet/dotnet6-6.0.108]

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

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

I installed the dotnet 7 dependencies with sudo apt install dotnet-runtime-7.0 dotnet-runtime-deps-7.0 dotnet-sdk-7.0 on Pop_OS!, which is derived from Ubuntu which is derived from Debian, so I'm not sure if you'd have the same packages available exactly but maybe?

WhiteBlackGoose commented 1 year ago

sorry for the slow response, it's tricky to find a spare moment at this time of year

This is no problem, happy holidays!

I installed the dotnet 7 dependencies with sudo apt install dotnet-runtime-7.0 dotnet-runtime-deps-7.0 dotnet-sdk-7.0 on Pop_OS!, which is derived from Ubuntu which is derived from Debian, so I'm not sure if you'd have the same packages available exactly but maybe?

.NET is not packaged for debian, so I used zip archives. Hmmm

nickspoons commented 1 year ago

Oh right I'm using a PPA, sorry. I can find it later but it's the Microsoft one so should be easy enough to find

nickspoons commented 1 year ago

@WhiteBlackGoose I think you just follow the dotnet 7 installation instructions here (download and install a .deb from Microsoft):

https://learn.microsoft.com/en-us/dotnet/core/install/linux-debian

WhiteBlackGoose commented 1 year ago

oops, I moved to NixOS recently :smile:

I'll let you know if it works for nix as soon as I get SDK to work (am trying to, right now)

WhiteBlackGoose commented 1 year ago

Tried using my repro. Still doesn't work for me (still no desired diagnostics). Tried with TFM=net6 because omnisharp-roslyn is packed with it (I'll package it with .net 7 when I'll have time)

nickspoons commented 1 year ago

Hi @WhiteBlackGoose, I just realised that I have EnableAnalyzersSupport: true in my global omnisharp.json config, and perhaps that's the missing key here. I don't know why it isn't set to true by default. So if you don't already have it, try creating a ~/.omnisharp/omnisharp.json file with the following contents:

{
   "FormattingOptions": {
      "EnableEditorConfigSupport": true
   },
   "RoslynExtensionsOptions": {
      "EnableAnalyzersSupport": true
   }
}

For more info see: https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration-Options#roslyn-extensions-options

WhiteBlackGoose commented 1 year ago

Aye, that worked! Thank you so much!