OmniSharp / omnisharp-vim

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

Running omnisharp-vim with omnisharp-roslyn on a unsupported platform #306

Closed ghost closed 5 years ago

ghost commented 7 years ago

I thought I might share my findings regarding this issue as it might help others in their pursuit of building and using a working omnisharp-roslyn server for completion.

Output dotnet --info:

.NET Command Line Tools (1.0.4)

Product Information:
 Version:            1.0.4
 Commit SHA-1 hash:  af1e6684fd

Runtime Environment:
 OS Name:     arch
 OS Version:  
 OS Platform: Linux
 RID:         ubuntu.16.10-x64
 Base Path:   /opt/dotnet/sdk/1.0.4

The problem:

Build failing using the prodvided ./build.sh script as mentioned in the README.md under the Installation section:

If you are planning to use OmniSharp-Roslyn, run the following commands:

cd ~/.vim/bundle/omnisharp-vim/omnisharp-roslyn
./build.sh

The error:

omnisharp-vim/omnisharp-roslyn/.dotnet/dotnet-install.sh: line 70: VERSION_ID: unbound variable
An error occurred when executing task 'BuildEnvironment'.
Error: Failed to Install .NET Core SDK 1.0.1

Failing block of code:

As mentioned in the error, the failing part seems to be this block of code. It was also mentioned here that this was the problem regarding a failing build.

The fixed seemed easy to me. I just had to provide a fallback case like this:

*)
    echo "ubuntu"
    return 0
;;

Should look like a fairly simple workaround right? Well not so much, as the dotnet-install.sh script seems to be either pulled in through NuGet or is code generated and the changes made to the script will be lost...

Seperating the concerns:

Given the problems with the build.shscript for the omnisharp-roslyn server coming with the omnisharp-vim I thought I would seperate the concerns and try to get a working omnisharp-roslyn server. This turned out to be rather easy.

If you are running Arch Linux there is a super simple PKGBUILD in the aur. For other distro's it's as easy as downloading the binaries and moving them to a proper location. Done! Try running the OmniSharp.exe at your binary installation location.

cd your/binaries/installation/location
./OmniSharp.exe

And... One big fat error...

OmniSharp: 
System.DllNotFoundException: System.Native
  at (wrapper managed-to-native) Interop+Sys:GetUnixNamePrivate ()
  at Interop+Sys.GetUnixName () [0x00000] in <2c0705c248b844f597694acdb70b3a23>:0 
  at System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform (System.Runtime.InteropServices.OSPlatform osPlatform) [0x00009] in <2c0705c248b844f597694acdb70b3a23>:0 
  at Microsoft.Extensions.Logging.Console.ConsoleLogger..ctor (System.String name, System.Func`3[T1,T2,TResult] filter, System.Boolean includeScopes) [0x00051] in <e9a418d09ae748d6a3f11d651b9e1106>:0 
  at Microsoft.Extensions.Logging.Console.ConsoleLoggerProvider.CreateLoggerImplementation (System.String name) [0x00019] in <e9a418d09ae748d6a3f11d651b9e1106>:0 
  at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (TKey key, System.Func`2[T,TResult] valueFactory) [0x0002e] in <73ee1b14c2fa4d61b481096ff3d8d6d7>:0 
  at Microsoft.Extensions.Logging.Console.ConsoleLoggerProvider.CreateLogger (System.String name) [0x00000] in <e9a418d09ae748d6a3f11d651b9e1106>:0 
  at Microsoft.Extensions.Logging.Logger.AddProvider (Microsoft.Extensions.Logging.ILoggerProvider provider) [0x00000] in <7f94c143dddc47f8b60fd6e1fd86a745>:0 
  at Microsoft.Extensions.Logging.LoggerFactory.AddProvider (Microsoft.Extensions.Logging.ILoggerProvider provider) [0x00061] in <7f94c143dddc47f8b60fd6e1fd86a745>:0 
  at Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddConsole (Microsoft.Extensions.Logging.ILoggerFactory factory, System.Func`3[T1,T2,TResult] filter, System.Boolean includeScopes) [0x00008] in <e9a418d09ae748d6a3f11d651b9e1106>:0 
  at Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddConsole (Microsoft.Extensions.Logging.ILoggerFactory factory, System.Func`3[T1,T2,TResult] filter) [0x00000] in <e9a418d09ae748d6a3f11d651b9e1106>:0 
  at OmniSharp.Startup.Configure (Microsoft.AspNetCore.Builder.IApplicationBuilder app, System.IServiceProvider serviceProvider, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, OmniSharp.Stdio.Services.ISharedTextWriter writer, OmniSharp.Services.IAssemblyLoader loader, Microsoft.Extensions.Options.IOptionsMonitor`1[TOptions] options) [0x00032] in <372033fc0ebc4984ad95c71bb1d0cc59>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <73ee1b14c2fa4d61b481096ff3d8d6d7>:0 
--- End of stack trace from previous location where exception was thrown ---
  at Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize () [0x00008] in <24af31b64ae843689736582353a19b3a>:0 
  at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build () [0x0008a] in <24af31b64ae843689736582353a19b3a>:0 
  at OmniSharp.Program+<>c__DisplayClass1_0.<Run>b__1 () [0x00196] in <372033fc0ebc4984ad95c71bb1d0cc59>:0 
  at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute (System.String[] args) [0x0035b] in <e56ebbc3ed87488b8e26736bbadaa5d3>:0 
  at OmniSharp.Program.Run (System.String[] args) [0x001ae] in <372033fc0ebc4984ad95c71bb1d0cc59>:0 
  at OmniSharp.Program.Main (System.String[] args) [0x0001c] in <372033fc0ebc4984ad95c71bb1d0cc59>:0 

At the moment I was getting a little frustrated... Surely I wouldn't be the only one with this problem...

After a few minutes digging around issues here and at omnisharp-roslyn I came acros this issue, where the author and several other people seemed to have the same problem. @DustinCampbell provided a fix, that was as easy as removing the System.Runtime.InteropServices.RuntimeInformation.dll from the installation directory of your omnisharp-roslyn server.

Now trying to run:

cd your/binaries/installation/location
./OmniSharp.exe

Resulted in a working omnisharp-roslyn server:

OmniSharp: 
info: OmniSharp.Startup[0]
      Omnisharp server running on port '2000' at location '/opt/omnisharp-roslyn' on host -1.
info: OmniSharp.DotNet.DotNetProjectSystem[0]
      Initializing in /opt/omnisharp-roslyn
info: OmniSharp.DotNet.DotNetProjectSystem[0]
      Auto package restore: True
info: OmniSharp.DotNet.DotNetProjectSystem[0]
      Update workspace context
info: OmniSharp.DotNet.DotNetProjectSystem[0]
      Resolving projects references
info: OmniSharp.MSBuild.MSBuildProjectSystem[0]
      MSBUILD_EXE_PATH environment variable set to /opt/omnisharp-roslyn/msbuild/MSBuild.dll
info: OmniSharp.MSBuild.MSBuildProjectSystem[0]
      MSBuildExtensionsPath environment variable set to /opt/omnisharp-roslyn/msbuild
info: OmniSharp.MSBuild.MSBuildProjectSystem[0]
      MSBuild will use local OmniSharp installation.
info: OmniSharp.MSBuild.MSBuildProjectSystem[0]
      No solution files found in '/opt/omnisharp-roslyn'
info: OmniSharp.Script.ScriptProjectSystem[0]
      Detecting CSX files in '/opt/omnisharp-roslyn'.
info: OmniSharp.Script.ScriptProjectSystem[0]
      Could not find any CSX files
info: OmniSharp.Startup[0]
      Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
info: OmniSharp.Startup[0]
      Configuration finished.

The only things left to do now was making it work together with omnisharp-vim. I used tpope/vim-dispatch to start things automatically, but this should also work manually.

1) Go to your omnisharp-vim plugin directory 2) Change directory to omnisharp-roslyn/artifacts/scripts 3) Symbolic link all your filles in omnisharp-roslyn installation directory (The directory with the OmniSharp.exe binary) to this directory. 4) Symbolic link the OmniSharp.exe -> Omnisharp 5) Done, have fun with this awesome piece of software :)

For me it looks this:

cd /home/sjors/Victoria/victoria_dotfiles/vim/plugged/omnisharp-vim/omnisharp-roslyn/artifacts/scripts
ln -s /opt/omnisharp-roslyn/* . 
ln -s OmniSharp.exe Omnisharp
DDoSolitary commented 7 years ago

It works! Thank you very much.

nickspoons commented 6 years ago

Hi @SirJls, I've found this issue to be very helpful in the past, but I think it is now obsolete with the current recommendation to use roslyn binaries instead of installing from source, and the automatic installer which does that for you when no server or g:OmniSharp_server_path has been set.

Are you happy for me to close this issue?