2

I've tried several ways to make it work but there seems to be no easy way. Yes, there are a ton of plugins, configurations. But they do not work right as per Oct 2019.

  • OmniSharp-Vim client needs configuration, it covers only C# and it lists plugins integration that does not work anymore (try choosing it for linting in ALE).
  • YouCompeleteMe should work but it is large and seems bloated.
  • Deoplete don't have source for C# and configurations I found are out of date.
  • Coc.nvim does not even list C# and 'unofficial' configurations have issues (like this). Besides Coc.nvim seems to be an alien from VS Code.
  • LanguageClient-neovim I didn't find sensible configuration and it seems because C# LSP server needs .sln file.

So this seems that csharpers should go to VS (or Rider) and that is when MS proposed LSP. How do you make IDE like from nvim to work with C#?

Basically the client should start server like this and use LSP.

~/.cache/omnisharp-vim/omnisharp-roslyn/run -s <PATH TO SLN OR DIR>
fannheyward
  • 18,599
  • 12
  • 71
  • 109
Artyom
  • 3,507
  • 2
  • 34
  • 67

2 Answers2

7

I just got omnisharp / ale working successfully with a clean install. You may want to completely uninstall omnisharp (~\AppData\Local\omnisharp-vim or ~/.omnisharp) just in case you have old versions.

You didn't mention your OS; I have this working in both Windows 10 and Mac OS. If you're using Mac OS make sure you brew install libuv first.

My Environment

  • Windows 10 (v1903) and Mac OS 10.14.6
  • Vim 8.1.2244
  • dotnet core 3.1 - I'd expect 3.0 to work as well

Instructions

First off, I'm using vim-plug as my plugin manager to handle installation. I installed it in both Windows and Mac OS using the bash/powershell snippets in vim-plug's README.

Then I added the following to my vimrc (~\_vimrc on Windows, ~/.vimrc on Mac OS):

"vim-plug config
call plug#begin()
Plug 'OmniSharp/omnisharp-vim'
Plug 'dense-analysis/ale'
call plug#end()

" plugin config
let g:OmniSharp_server_stdio = 1

Restart vim, and run :PlugInstall. It will clone omnisharp and ale for you.

Next, find some C# solution, and ensure the solution builds at the commandline (e.g. dotnet build should complete without errors). You also need a SLN file if you don't already have one (dotnet new sln and then dotnet sln add MyProj.csproj)

Choose a C# file and open it in vim. You should see the following notification:

omnisharp installation

If the install doesn't autostart, you can start it with :OmniSharpInstall. The install takes a minute or two of downloading in a terminal window. After the installation is complete, reopen vim and execute :cd \path\to\my\solution to ensure the working directory inside vim is correct. Then open a file with e.g. :e MyProj\Program.cs.

The server will be started automatically; don't manually start it. I get a lot of syntax errors for the first few seconds while the server is starting, after that I don't have any errors.

To pull up the autocomplete, type something like Console. then hit Ctrl-x o:

vim with autocomplete

The above screenshot has vim-airline for the bottom bar -- that's not part of omnisharp and isn't required.

The above screenshots are Windows, but it's also working fine in Mac OS:

mac os

My full vimrc is available here and the source code I'm testing with is available here.

Will
  • 2,086
  • 23
  • 30
  • Yeah, I ended up with somewhat similar configuration. As I see in your vim config you don't have handy keys configuration for OmniSharp (GoTo, Documentation, Hover, etc.) so it is not finished. Just compare with YouCompleteMe where we have TAB worked from the beginning. And your configuration only works for C# whereas I was interested in config to work with other languages (say JS, Python). Here is more about my config - https://github.com/OmniSharp/omnisharp-vim/issues/533#issuecomment-551970249 – Artyom Nov 10 '19 at 18:00
  • Understood, thanks for clarifying. I read your original question as specific to c# autocompletion, so my answer was focused on that. – Will Nov 11 '19 at 13:34
  • 2
    Nice to see a dracula user in action! – D. Ben Knoble Dec 18 '19 at 20:35
0

So far here is my setting for this using Deoplete, OmniSharp and ALE (full config at https://github.com/artkpv/dotfiles/blob/master/.config/nvim/vimrc) :

" Install Deoplete and OmniSharp:
" - OmniSharp/omnisharp-vim    " for LSP support (like start OmniSharp server) and code actions, etc
" - Shougo/deoplete.nvim       " for better autocompletion
" - dense-analysis/ale         " for highlights

function SetCSSettings()

    " Use deoplete.
    call deoplete#enable()

    " Use smartcase.
    call deoplete#custom#option('smart_case', v:true)

    " Use OmniSharp-vim omnifunc 
    call deoplete#custom#source('omni', 'functions', { 'cs':  'OmniSharp#Complete' })

    " Set how Deoplete filters omnifunc output.
    call deoplete#custom#var('omni', 'input_patterns', {
        \ 'cs': '[^. *\t]\.\w*',
        \})

    " ... then goes your mappings for :OmniSharp* functions, see its doc
endfunction

augroup csharp_commands
    autocmd!

    " Use smartcase.
    " call deoplete#custom#option('smart_case', v:true) 
    autocmd FileType cs call SetCSSettings()

augroup END
Artyom
  • 3,507
  • 2
  • 34
  • 67