I been battling to set up a C# language server (omnisharp) for neovim. The main problem is that I gotta use .NET Core 5.0.17 and omnisharp no longer ships with mono and MSBuild tools (mentioned in omnisharp-vscode repo announcement section).
When I try to edit a .cs file I get the message "Client 1 quit with exist code 150 and signal 0". When I check lsp.log
I get "[ERROR][2022-07-20 13:09:08] .../vim/lsp/rpc.lua:420 "rpc" "dotnet" "stderr" "You must install or update .NET to run this application.\n\nApp: /home/josh/.local/share/nvim/lsp_servers/omnisharp/omnisharp/OmniSharp.dll\nArchitecture: x64\nFramework: 'Microsoft.NETCore.App', version '6.0.0-preview.7.21317.1' (x64)\n.NET location: /opt/dotnet/\n\nThe following frameworks were found:\n 5.0.17 at [/opt/dotnet/shared/Microsoft.NETCore.App]\n\nLearn about framework resolution:\nhttps://aka.ms/dotnet/app-launch-failed\n\nTo install missing framework, download:\nhttps://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=6.0.0-preview.7.21317.1&arch=x64&rid=manjaro-x64\n"
In order to make Omnisharp work with .NET versions below 6.0 I have to do the following:
- Set
useModernNet = false
(mentioned in omnisharp-vscode repo requirement section) - Install Mono (mentioned in omnisharp-vscode repo requirement section).
- Due to my distro (manjaro) I also have to install mono-msbuild (mentioned in omnisharp-roslyn introduction secction)
In order to tackle the first one I generate a lsp/settings/omnisharp.lua
file for lsp installer to setup the cmp and to set useModernNet = false
following instructions from lsp config repo. I add such file to lsp/lsp-installer.lua
which is then called by lsp/init.lua
.
Hopefully someone can lead me to the solution or right direction to it. Thanks for even taking the time to read.
My neovim setup is here (credit to chris@machine for the setup found here)
nvim/lua/user/lsp/lsp-installer.lua
local status_ok, lsp_installer = pcall(require, "nvim-lsp-installer")
if not status_ok then
return
end
-- Register a handler that will be called for all installed servers.
-- Alternatively, you may also register handlers on specific server instances instead (see example below).
lsp_installer.on_server_ready(function(server)
local opts = {
on_attach = require("user.lsp.handlers").on_attach,
capabilities = require("user.lsp.handlers").capabilities,
}
if server.name == "jsonls" then
local jsonls_opts = require("user.lsp.settings.jsonls")
opts = vim.tbl_deep_extend("force", jsonls_opts, opts)
end
if server.name == "sumneko_lua" then
local sumneko_opts = require("user.lsp.settings.sumneko_lua")
opts = vim.tbl_deep_extend("force", sumneko_opts, opts)
end
--------------------------------ADDED CODE--------------------------------
if server.name == "omnisharp" then
local omnisharp_opts = require("user.lsp.settings.omnisharp")
opts = vim.tbl_deep_extend("force", omnisharp_opts, opts)
end
--------------------------------------------------------------------------
-- This setup() function is exactly the same as lspconfig's setup function.
-- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
server:setup(opts)
end)
nvim/lua/user/lsp/settings/omnisharp.lua
local pid = vim.fn.getpid()
local omnisharp_bin = "/home/josh/.local/share/nvim/lsp_servers/omnisharp/omnisharp/OmniSharp.dll"
return {
cmd = { omnisharp_bin, "--languageserver" , "--hostPID", tostring(pid) },
omnisharp = {
useModernNet = false,
monoPath = "/usr/bin/mono"
}
}
Tech stack
System (cat /etc/lsb-release)
DISTRIB_ID=ManjaroLinux
DISTRIB_RELEASE=21.3.1
DISTRIB_CODENAME=Ruah
DISTRIB_DESCRIPTION="Manjaro Linux"
.NET (dotnet --info)
.NET SDK (reflecting any global.json):
Version: 5.0.408
Commit: da985e2a23
Runtime Environment:
OS Name: manjaro
OS Version:
OS Platform: Linux
RID: linux-x64
Base Path: /opt/dotnet/sdk/5.0.408/
global.json file:
/home/josh/storage/Documents/csharp/global.json
Host:
Version: 6.0.7
Architecture: x64
Commit: 0ec02c8c96
.NET SDKs installed:
5.0.408 [/opt/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.17 [/opt/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.17 [/opt/dotnet/shared/Microsoft.NETCore.App]
Download .NET:
https://aka.ms/dotnet-download
Learn about .NET Runtimes and SDKs:
https://aka.ms/dotnet/runtimes-sdk-info
Neovim (nvim --version)
NVIM v0.7.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by builduser
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/share/nvim"
Run :checkhealth for more info
Mono (mono --version)
Mono JIT compiler version 6.12.0 (makepkg/ed0788bf61f Sun Apr 24 04:25:18 PM UTC 2022)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
Interpreter: yes
LLVM: supported, not enabled.
Suspend: hybrid
GC: sgen (concurrent by default)
MSBuild (msbuild -version)
Microsoft (R) Build Engine version 16.10.1 for Mono
Copyright (C) Microsoft Corporation. All rights reserved.
16.10.1.15601%