OmniSharp / omnisharp-roslyn

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

Omnisharp vim wiht lsp-config gives errors #2169

Open tilupe opened 3 years ago

tilupe commented 3 years ago

Hi I tried to setup omnisharp-server with LSP in neovim, but somehow it doesen't want to work.

Setup: Windows 10 neovim-qt v0.5.0-dev+1353-g0a653f7ab Plugins used: lsp-config In my lua-file I set the server up like in the lsp-config - Doku

local pid = vim.fn.getpid() local omnisharp_bin = "C:/Users/Username/.cache/nvim/nlua/omnisharp-roslyn/OmniSharp.exe" require'lspconfig'.omnisharp.setup{ cmd = { omnisharp_bin, "--languageserver" , "--hostPID", tostring(pid) }; on_attach = on_attach, }

My lua-setup works with lua (goto etc,) and when I enter a .cs file and enter LspInfo it also shows that omnisharp is attached to this buffer (the root_bin is not the correct one, It tooke the first Project file eventhough the real root is 2 folder higher, but I am not sure if this is just a wrong name displayed)

Problem: When I try to use the different mappings: e.g. buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts)

Then with the GoToImplementation doesn't do anything while the reference sometimes opens a empty quickfix list. If I try to use the command mode with the cursor on a method for example :lua vim.lsp.buf.implementation() then I get an error "method not found - is not supported by any of the servers registered" When I try the code refactoring method I get NullPointerException OmniSharpDocumentationFormattingHandler.cs line 41\13

Do you know what I do wrong or can you reproduce this issue?

tilupe commented 3 years ago

Do you need more information or is this the wrong place to ask this question?

Swoogan commented 3 years ago

I have these functions working in my config with slightly different commands:

buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)

notice the addition of <cmd> at the start and <cr> at the end.

However, I do experience the issue that gi complains "method not found - is not supported by any of the servers registered."

aenichols commented 2 years ago

You may have to specify the root directory. Also currently I don’t believe omnisharp-roslyn supports decompilation so goto will not work always. If you need this you can try using the csharp-ls listed on nvim-lspconfig

local function on_cwd()
  return vim.loop.cwd()
end

local pid = vim.fn.getpid()
local omnisharp_bin = "C:/Users/Username/.cache/nvim/nlua/omnisharp-roslyn/OmniSharp.exe"
require'lspconfig'.omnisharp.setup {
    on_attach = on_attach,
    root_dir = on_cwd,
    cmd = { omnisharp_bin, "--languageserver" , "--hostPID", tostring(pid) };
    ...
}