diff --git a/autoload/SpaceVim/layers/lang/csharp.vim b/autoload/SpaceVim/layers/lang/csharp.vim index b9eb98c50..f91e21c73 100644 --- a/autoload/SpaceVim/layers/lang/csharp.vim +++ b/autoload/SpaceVim/layers/lang/csharp.vim @@ -32,35 +32,21 @@ function! SpaceVim#layers#lang#csharp#plugins() abort let plugins = [] - call add(plugins, ['OmniSharp/omnisharp-vim', {'on_ft' : 'cs'}]) - - if has('nvim') - call add(plugins, ['autozimu/deoplete-omnisharp', {'on_ft' : 'cs'}]) - else - call add(plugins, ['tpope/vim-dispatch', {'on_ft' : 'cs'}]) - endif - + call add(plugins, ['OmniSharp/omnisharp-vim', { 'on_ft' : 'cs' } ]) return plugins endfunction +function! SpaceVim#layers#lang#csharp#set_variable(var) abort + if has_key(a:var, 'highlight_types') + let g:OmniSharp_highlight_types = a:var.highlight_types + endif +endfunction + function! SpaceVim#layers#lang#csharp#config() abort " Get Code Issues and syntax errors let g:syntastic_cs_checkers = ['syntax', 'semantic', 'issues'] - augroup spacevim_csharp - autocmd! - - if !has('nvim') - " Set autocomplete function to OmniSharp by default - autocmd FileType cs setlocal omnifunc=OmniSharp#Complete - endif - - " Automatically add new cs files to the nearest project on save - autocmd BufWritePost *.cs call OmniSharp#AddToProject() - - " Show type information automatically when the cursor stops moving - autocmd CursorHold *.cs call OmniSharp#TypeLookupWithoutDocumentation() - augroup END + autocmd FileType cs setlocal omnifunc=OmniSharp#Complete call SpaceVim#mapping#space#regesit_lang_mappings('cs', function('s:language_specified_mappings')) endfunction @@ -102,6 +88,18 @@ function! s:language_specified_mappings() abort \ 'OmniSharpFindMembers', \ 'find members in the current buffer', 1) + " Code action + let g:_spacevim_mappings_space.l.c = {'name' : '+Code action'} + call SpaceVim#mapping#space#langSPC('nmap', ['l', 'c', 'f'], + \ 'OmniSharpFixUsings', + \ 'Fix using', 1) + call SpaceVim#mapping#space#langSPC('nmap', ['l', 'c', 'a'], + \ 'OmniSharpGetCodeActions', + \ 'Contextual code actions', 1) + call SpaceVim#mapping#space#langSPC('nmap', ['l', 'c', 'c'], + \ 'OmniSharpGlobalCodeCheck', + \ 'Find all code errors/warnings for the current solution', 1) + " Server interaction let g:_spacevim_mappings_space.l.s = {'name' : '+Server interaction'} call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 'r'], diff --git a/config/plugins/deoplete.vim b/config/plugins/deoplete.vim index 1dc91499a..2e9121ba1 100644 --- a/config/plugins/deoplete.vim +++ b/config/plugins/deoplete.vim @@ -113,6 +113,9 @@ call deoplete#custom#var('omni', 'input_patterns', { \ ], \}) +" c# +call deoplete#custom#option('sources', {'cs': ['omnisharp']}) + " public settings call deoplete#custom#source('_', 'matchers', ['matcher_full_fuzzy']) call deoplete#custom#source('file/include', 'matchers', ['matcher_head']) diff --git a/docs/layers/lang/csharp.md b/docs/layers/lang/csharp.md index cf4fe6260..b9abcc74f 100644 --- a/docs/layers/lang/csharp.md +++ b/docs/layers/lang/csharp.md @@ -21,33 +21,19 @@ This layer is for csharp development. ## Install -### Layer - To use this configuration layer, update custom configuration file with: ```toml [[layers]] name = "lang#csharp" + highlight_types = 0 ``` -### OmniSharp Server - -You must build the *OmniSharp Server* before using this layer's features. - -After all plugins installed, *cd* to the directory `$SPACEVIM_PLUGIN_BUNDLE_DIR/repos/github.com/OmniSharp/omnisharp-vim/server` (by default `$HOME/.cache/vimfiles/repos/github.com/OmniSharp/omnisharp-vim/server`, and then run - -``` -xbuild -``` -for macOS and linux, or - -``` -msbuild -``` -for Windows. - -For more information, please read this [link](https://github.com/OmniSharp/omnisharp-vim#installation). +When opening a cs file at first time, it will popup a window and ask whether install the OmniSharp +server or not, enter 'Y' to confirm. +If you choose "coc" as your auto completion engine, you must run ":CocInstall coc-omnisharp" +to install the extension. ## Key bindings @@ -63,6 +49,9 @@ For more information, please read this [link](https://github.com/OmniSharp/omnis | `SPC l g s` | find symbols | | `SPC l g u` | find usages of symbol under cursor | | `SPC l g m` | find members in the current buffer | +| `SPC l c f` | fix using | +| `SPC l c a` | contextual code actions | +| `SPC l c c` | find all code errors/warnings for the current solution| | `SPC l s r` | reload the solution | | `SPC l s s` | start the OmniSharp server | | `SPC l s S` | stop the OmniSharp server |