Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OmniSharp-VIM, OmniSharp-Roslyn, and dotnet core on Ubuntu 16.10 - Syntax checking not recognizing C# 6 and requires solution file

I am trying to set up my Ubuntu machine for dotnet core development. I've painstakingly installed Omnisharp-vim and set it to work with the OmniSharp-Roslyn server. I also have Syntastic and YouCompleteMe installed. I am getting syntax checking and Intellisense. I have two problems though:

  1. Omnisharp-vim does not work without a solution file. Dotnet core projects don't have to have solutions files. How do I get around this?

  2. I am getting syntax error for valid C# 6 code. For instance, it does not recognize the nameof operator.

like image 515
Dale Alleshouse Avatar asked Nov 04 '16 21:11

Dale Alleshouse


1 Answers

How?

Add a valid global.json file to your root directory.

{}

Add two lines to the top of your vimrc file.

let g:OmniSharp_server_type = 'roslyn'
let g:OmniSharp_prefer_global_sln = 1

Why?

Those two OmniSharp settings tell omnisharp-vim to use Roslyn and to use the directory that contains a global.json file.

Here is the OmniSharp.vim file source-code that uses those variables.

if g:OmniSharp_server_type ==# 'roslyn' && g:OmniSharp_prefer_global_sln
  let global_solution_files = s:globpath(dir, 'global.json')
  call filter(global_solution_files, 'filereadable(v:val)')
  if !empty(global_solution_files)
    let solution_files = [dir]
    break
  endif
endif

If that does not work...

Try starting OmniSharp manually from the command line:

omnisharp-vim\omnisharp-roslyn\artifacts\scripts\OmniSharp.cmd -s C:\temp\

The C:\temp\ directory contains a new .NET Core project with a valid global.json file.

like image 99
Shaun Luttin Avatar answered Sep 19 '22 08:09

Shaun Luttin