OmniSharp / omnisharp-roslyn

OmniSharp server (HTTP, STDIO) based on Roslyn workspaces
MIT License
1.76k stars 420 forks source link

No documentation completion from standard framework libraries? #1667

Open CaerphillyMediaLtd opened 4 years ago

CaerphillyMediaLtd commented 4 years ago

I'm on Arch Linux, and have tried using both the HTTP and stdio implementations in both neovim and Visual Studio Code, but get this error in both. Anything that is documented in the local solution gets returned correctly in the documentation call, e.g.:

"Description": "Test class documentation.\n",

But when completing anything from the standard framework classes the Description's value is just an empty string:

"Description": "",

I've tried this with both a Mono framework application and a .NET Core 3.0.100, but neither return the documentation.

The actual class, function, etc. names and signatures are all returned.

I have msbuild-16-bin installed from the AUR, as well as dotnet which I have used to create a test solution, but that still does not work. Mono is on version 6.4.0.

I have also tried putting:

"MsBuild": {
    "UseLegacySdkResolver": true
}

in ~/.omnisharp/omnisharp.json, but this still doesn't seem to do anything?

Am I missing something, is there anyway to easily fix this?

nickspoons commented 4 years ago

I don't have the answer, I'm not entirely sure what is responsible for documentation, but here are some details from my similar archlinux system where I do have good documentation from the system libraries (e.g. system.Format() and System.Console.WriteLine())

  > dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.0.100
 Commit:    04339c3a26

Runtime Environment:
 OS Name:     arch
 OS Version:  
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /opt/dotnet/sdk/3.0.100/

Host (useful for support):
  Version: 3.0.0
  Commit:  7d57652f33

.NET Core SDKs installed:
  2.2.108 [/opt/dotnet/sdk]
  3.0.100 [/opt/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.NETCore.App 2.2.6 [/opt/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [/opt/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
  > /bin/ls -l /usr/sbin/dotnet
lrwxrwxrwx 1 root root 18 Nov 15 12:46 /usr/sbin/dotnet -> /opt/dotnet/dotnet

I have the following installed from the AUR:

  > pacman -Qm msbuild mono dotnet-sdk-bin dotnet-runtime-bin dotnet-host
msbuild-16-bin 16.3_xamarinxplat.2019.08.08.00.55_0xamarin2_ubuntu1804b1-1
mono-nightly 6.7.0.356-1
dotnet-sdk-bin 3.0.100-1
dotnet-runtime-bin 3.0.0-5
dotnet-host-bin 3.0.0-5

If I just create a .cs file by itself I get completion but no documentation. As soon as I put a simple .csproj like the following next to it and run dotnet build, I get documentation and signaturehelp.

  <Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
      <TargetFramework>netcoreapp3.0</TargetFramework>
      <IsPackable>false</IsPackable>
    </PropertyGroup>

  </Project>
CaerphillyMediaLtd commented 4 years ago

I made some questionable progress. If I do what you mentioned at the end of your post, then yes it works fine, both areas of suggestion appear. I can also see the System.Text.Json namespace which was added in .NET Core 3.0. But then when I generate a solution file using dotnet new sln, it suddenly loses the documentation, and also can no longer see the System.Text.Json namespace. This happens in both vscode and vim.

I could deal with this by just not using solution files, but unfortunately omnisharp-vim requires a solution file. So I do need a way to create a valid solution file which still allows documentation.

Edit: forgot to add the project to the solution, it's all working now. I'm still not exactly sure why previous projects are not working, but recreating their solutions seems to work. Thanks!

CaerphillyMediaLtd commented 4 years ago

Ok another problem, and maybe the root problem. It seems to be only Mono that is not loading the documentation. If I create a solution and add projects from a Mono project, then I can view new namespaces like System.Text.Json, but I still get no completion of documentation?

nickspoons commented 4 years ago

@CaerphillyMediaLtd OmniSharp-vim does not require a .sln, you can use let g:OmniSharp_start_without_solution = 1 to get it to use the current directory if no solution is found.

artkpv commented 4 years ago

Same story here since this issue, https://github.com/OmniSharp/omnisharp-vim/issues/533. No documentation still. I've tried changing .csproj, removing .sln. No docs. Though they are displayed for my types / methods (with <summary>). When I do go to definition, the source code that is displayed does not have doc strings. Arch Linux, here is what I have:

[N] ➜ pa -Q mono msbuild-16-bin dotnet-host-bin dotnet-runtime-bin dotnet-sdk-bin  
mono 6.4.0.198-1
msbuild-16-bin 16.3_xamarinxplat.2019.08.08.00.55_0xamarin2_ubuntu1804b1-1
dotnet-host-bin 3.0.0-5
dotnet-runtime-bin 3.0.0-5
dotnet-sdk-bin 3.0.100-1

[I] ➜ cat ~/.cache/omnisharp-vim/omnisharp-roslyn/OmniSharpInstall-version.txt 
OmniSharp v1.34.9

Update. Also the completion loads only after about 20-30 seconds everytime. Here what it writes :messages:

Server load notification for <path / to / solution.sln> not received after 30 seconds - continuing.
artkpv commented 4 years ago

I could fix that on my ArchLinux. Added this to .zshrc:

export MSBuildSDKsPath="/opt/dotnet/sdk/3.0.100/Sdks";

As advised at https://wiki.archlinux.org/index.php/.NET_Core#SDK_specified_could_not_be_found

Now documentation loads for all signatures and load time for a cs file of the O# server is quick, no ~30sec timeout.

artkpv commented 4 years ago

Another note about this issue. The problem is that server should be able to find ".csproj" file to be able to show doc as I understand. On my machine it is so. If I open isolated .cs file, O# loads and shows signatures but with no docs. For the project file it looks only in current dir of a buffer (:pwd) and its parent dir (only one parent directory, not all of them). See :h OmniSharp:

:OmniSharpStartServer {sln-or-dir} Starts an OmniSharp server. If no arguments are provided, this command will attempt to find a solution file located in a parent directory of the current buffer and start a server for that file. Alternatively, you can explicitly provide the path of a solution file or a directory to start the server for.

So practically, to see documentation, make sure O# server is loaded with correct directory and you have proper installation (it needs export MSBuildSDKsPath=.. as above).

nickspoons commented 4 years ago

@artkpv these are all very Vim and OmniSharp-vim specific things you are mentioning, and aren't related to how OmniSharp-roslyn interacts with dotnet to find documentation. The :OmniSharpStartServer docs you have linked are describing the way that OmniSharp-vim finds the .sln file, to pass it to OmniSharp-roslyn on startup. Also, those docs say "in a parent directory", meaning that all parent directories are searched, to the root directory.

artkpv commented 4 years ago

@nickspoons Strange, but it didn't find my csproj file or sln file two levels deep. I needed to run :OmniSharpStartServer ../../ to make it work.

adelarsq commented 4 years ago

Following this works fine, even the documentation:

Installing the language server (Linux):

    cd ~/Downloads
    rm -rf omnisharp-linux-x64.tar.gz
    wget https://github.com/OmniSharp/omnisharp-roslyn/releases/download/v1.34.12/omnisharp-linux-x64.tar.gz
    mkdir omnisharp
    mv omnisharp-linux-x64.tar.gz omnisharp
    cd omnisharp
    tar zxpvf omnisharp-linux-x64.tar.gz
    rm -rf omnisharp-linux-x64.tar.gz
    rm -rf ~/dev/omnisharp
    mv run omnisharp_lsp_run
    chmod +x omnisharp_lsp_run
    cd ..
    mv omnisharp ~/dev

Configure the PATH:

    export PATH="/home/MY_USER/dev/omnisharp:$PATH"

Then if you are using Vim with Coc use like that:

  "omnisharp": {
      "command": "omnisharp_lsp_run",
      "filetypes": ["cs","csx","cake","vb"],
      "args": ["-lsp"],
      "ignoredRootPaths": ["/","~"],
      "rootPatterns": ["*.sln"]
  },
artkpv commented 4 years ago

@adelarsq Tried your config. It does not work for me. Still no documentation which is via call CocAction('doHover'). See attached work session with coc.nvim, omnisharp. So far OmniSharp.vim looks the only working solution for C# dev under vim, imho.

2020-04-25_cocnvim_omnisharp.log

Update. One strange thing I noticed is that Omnisharp-Roslyn tries to resolve "Microsoft.Build.resources" of 15.1 while it ships with 16 version of MsBuild. See error from the log attached below:

[Info  - 4:48:29 PM] FAILURE: Could not locate '/usr/lib/mono/msbuild/Current/bin/Microsoft.Build.resources.dll'.
[Info  - 4:48:29 PM] Attempting to resolve 'Microsoft.Build.Tasks.Core.resources, Version=15.1.0.0, Culture=en-US, PublicKeyToken=b03f5f7f11d50a3a'
[Info  - 4:48:29 PM] FAILURE: Could not locate '/usr/lib/mono/msbuild/Current/bin/Microsoft.Build.Tasks.Core.resources.dll'.
artkpv commented 4 years ago

Still does not work. Tried updating all to the latest versions (vim, O#-vim, O#-roslyn, .Core). See logs for this session: create empty console app, run :OmniSharpDocumentation (O#-vim feature). No full docs, only signature. My guess is that O#-Roslyn could not detect which framework is it, because when I fetch documentation for my classes or some other packages it does show it. Pls help

art/Desktop/csvimtest on  vim_into_ide [!] via .NET 3.1.103 took 24s 
[I] ➜ pacman -Qs dotnet
local/dotnet-host 3.1.3.sdk103.2-1
    A generic driver for the .NET Core Command Line Interface
local/dotnet-runtime 3.1.3.sdk103.2-1
    The .NET Core runtime
local/dotnet-sdk 3.1.3.sdk103.2-1
    The .NET Core SDK

art/Desktop/csvimtest on  vim_into_ide [!] via .NET 3.1.103 
[I] ➜ dotnet --list-sdks 
3.1.103 [/usr/share/dotnet/sdk]

art/Desktop/csvimtest on  vim_into_ide [!] via .NET 3.1.103 
[I] ➜ dotnet --list-runtimes 
Microsoft.AspNetCore.App 3.1.3 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

art/Desktop/csvimtest on  vim_into_ide [!] via .NET 3.1.103 
[I] ➜ cat csvimtest.csproj 
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

</Project>

omnisharp-roslyn-session.log

n9v9 commented 4 years ago

@artkpv I also had no documentation on the standard library, only signatures. However, I found a comment on this issue which helped me to get documentation completion working.

I modified it slightly so that I did the following:

  1. Remove the installed packages sudo pacman -R dotnet-sdk dotnet-host dotnet-runtime
  2. Download the installation script from microsoft.
  3. Run the script chmod +x dotnet-install.sh && ./dotnet-install.sh. This will install the dotnet sdk to the folder $HOME/.dotnet.
  4. Add these variables to .zshrc:
    • export DOTNET_ROOT="$HOME/.dotnet"
    • export PATH="$DOTNET_ROOT:$PATH"

In my neovim config I have the following settings:

To test it I created a project with dotnet new console, switched into the folder and opened the generated Program.cs file. Using :OmniSharpGotoDefinition on a given stdlib method takes me to a source file somewhere in /tmp with the complete documentation above its signature.

Similar, while writing, the documentation does now pop up beside the method signature.

However using :OmniSharpDocumentation it only shows me the exceptions that the method might throw (but that's not that bad, because I can now use OmniSharpGotoDefinition to see the documentation).

As to why it does not work with the pacman packages, I don't know. Before I tried the aforementioned steps, I tried only step 4 by setting DOTNET_ROOT to the path where pacman installed it, which was /usr/share/dotnet/sdk/3.1.103/Sdks; but it did not work.

I hope this can help someone.

artkpv commented 4 years ago

@n9v9 Thanks! That really helped me to make it work though it didn't show docs after these steps done. Now I managed to make it work. :) Reinstalled dotnet, mono, OmniSharp, set environment vars and other several times. Here are tips for others if they don't have docs shown. In my case I think the reason was it used the mono msbuild tool somehow.

#region Assembly System.Console, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Console.dll
#endregion
akachida commented 3 years ago

@artkpv I also had no documentation on the standard library, only signatures. However, I found a comment on this issue which helped me to get documentation completion working.

I modified it slightly so that I did the following:

  1. Remove the installed packages sudo pacman -R dotnet-sdk dotnet-host dotnet-runtime
  2. Download the installation script from microsoft.
  3. Run the script chmod +x dotnet-install.sh && ./dotnet-install.sh. This will install the dotnet sdk to the folder $HOME/.dotnet.
  4. Add these variables to .zshrc:

    • export DOTNET_ROOT="$HOME/.dotnet"
    • export PATH="$DOTNET_ROOT:$PATH"

In my neovim config I have the following settings:

  • let g:OmniSharp_server_stdio=1
  • let g:omnicomplete_fetch_full_documentation=1

To test it I created a project with dotnet new console, switched into the folder and opened the generated Program.cs file. Using :OmniSharpGotoDefinition on a given stdlib method takes me to a source file somewhere in /tmp with the complete documentation above its signature.

Similar, while writing, the documentation does now pop up beside the method signature.

However using :OmniSharpDocumentation it only shows me the exceptions that the method might throw (but that's not that bad, because I can now use OmniSharpGotoDefinition to see the documentation).

As to why it does not work with the pacman packages, I don't know. Before I tried the aforementioned steps, I tried only step 4 by setting DOTNET_ROOT to the path where pacman installed it, which was /usr/share/dotnet/sdk/3.1.103/Sdks; but it did not work.

I hope this can help someone.

I installed the dotnet using the doc from microsoft using snap. So my dotnet folder was /var/lib/snapd/snap/dotnet-sdk/current I only follow this step:

  1. Add these variables to .zshrc:
    1. export DOTNET_ROOT="/var/lib/snapd/snap/dotnet-sdk/current"
    2. export PATH="$DOTNET_ROOT:$PATH"

And it worked, thanks.