OmniSharp / omnisharp-vim

Vim omnicompletion (intellisense) and more for C#
http://www.omnisharp.net
MIT License
1.7k stars 169 forks source link

OmniSharpCodeFormat is replacing tabs for spaces #724

Closed jedielson closed 3 years ago

jedielson commented 3 years ago

Here is my nvim data:

NVIM v0.5.0
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe /DWIN32 /D_WINDOWS /W3 -DNVIM_TS_HAS_SET_MATCH_LIMIT /MD /Zi /O2 /Ob1 /DNDEBUG /W3 -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -DWIN32 -D_WIN32_WINNT=0x0600 -DINCLUDE_GENERATED_DECLARATIONS -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -ID:/a/neovim/neovim/build/config -ID:/a/neovim/neovim/src -ID:/a/neovim/neovim/nvim-deps/usr/include -ID:/a/neovim/neovim/build/src/nvim/auto -ID:/a/neovim/neovim/build/include
Compiled by runneradmin@fv-az152-786

Features: -acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM\sysinit.vim"
  fall-back for $VIM: "C:/Program Files/nvim/share/nvim"

Run :checkhealth for more info

Here is my ftplugin/cs.vim file:

nnoremap <ESC> :echo "HELLO"<CR>

" ALE
let g:ale_linters = { 'cs' : ['OmniSharp'] }

" OmniSharp
let g:omnicomplete_fetch_full_documentation = 1
let g:OmniSharp_autoselect_existing_sln = 1
let g:OmniSharp_popup_position = 'peek'
let g:OmniSharp_highlighting = 3
let g:OmniSharp_diagnostic_exclude_paths = [ 'Temp[/\\]', 'obj[/\\]', '\.nuget[/\\]' ]
let g:OmniSharp_fzf_options = { 'down': '10' }

nmap gd <Plug>(omnisharp_go_to_definition)
nmap <Leader><Space> <Plug>(omnisharp_code_actions)
xmap <Leader><Space> <Plug>(omnisharp_code_actions)
nmap <F2> <Plug>(omnisharp_rename)
"nmap <Leader>cf <Plug>(omnisharp_code_format)
nmap <C-k><C-c> <Plug>(omnisharp_code_format)
nmap <Leader>fi <Plug>(omnisharp_find_implementations)
nmap <Leader>fs <Plug>(omnisharp_find_symbol)
nmap <Leader>fu <Plug>(omnisharp_find_usages)
nmap <Leader>dc <Plug>(omnisharp_documentation)
nmap <Leader>cc <Plug>(omnisharp_global_code_check)
nmap <Leader>rt <Plug>(omnisharp_run_test)
nmap <Leader>rT <Plug>(omnisharp_run_tests_in_file)
nmap <Leader>ss <Plug>(omnisharp_start_server)
nmap <Leader>sp <Plug>(omnisharp_stop_server)
nmap <C-\> <Plug>(omnisharp_signature_help)
imap <C-\> <Plug>(omnisharp_signature_help)

" Text/Indent
set autoindent
set noexpandtab
set smarttab
set shiftwidth=4
set tabstop=4
set ai
set si
set nowrap

autocmd BufWritePre *.cs :OmniSharpCodeFormat

This is my plug file

call plug#begin(path.'/nvim/autoload/plugged')
" File Explorer
"Plug 'preservim/nerdtree'
"
Plug 'neovim/nvim-lspconfig'

" Omnisharp
Plug 'OmniSharp/omnisharp-vim'

" Themes
Plug 'joshdick/onedark.vim'
"Plug 'iCyMind/NeoSolarized'
Plug 'ryanoasis/vim-devicons'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'

" Completion
Plug 'neoclide/coc.nvim', {'do': 'yarn install --frozen-lockfile'}
Plug 'sheerun/vim-polyglot'

" File Management
Plug 'mhinz/vim-startify'

" Git Integration
Plug 'mhinz/vim-signify'

" Maps key to fast actions
Plug 'liuchengxu/vim-which-key'

" Commentary
Plug 'tpope/vim-commentary'

" Better terminal integration
Plug 'voldikss/vim-floaterm'

" Autopairs
Plug 'jiangmiao/auto-pairs'

" EditConfig
Plug 'editorconfig/editorconfig-vim'

" Snippets
Plug 'honza/vim-snippets'

Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'airblade/vim-rooter'

Plug 'dense-analysis/ale'
call plug#end()

And here is my init.vim


lua << EOF
 local nvim_lsp = require('lspconfig')

 local on_attach = function(client, bufferNumber)
    require('completion').on_attach(client)
 end

 local pid = vim.fn.getpid()
 local omnisharp_bin = "C:\\ProgramData\\chocolatey\\bin\\OmniSharp.exe"
 nvim_lsp.omnisharp.setup({ cmd = { omnisharp_bin, "--languageserver" , "--hostPID", tostring(pid) } })

EOF

The .editorconfig looks like

# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
############################### 
# Core EditorConfig Options   # 
############################### 
root = true
# All files 
[*] 
indent_style = tab
indent_size = tab
insert_final_newline = false
# Yaml
[*.yaml] 
indent_style = space
indent_size = 2
# Code files 
[*.{cs,csx,vb,vbx}] 
charset = utf-8-bom 

When I use :OmniSharpCodeFormat all tabs of my file are being replaced by spaces. But I expected them to be keeped.

nickspoons commented 3 years ago

This is a server-side action and is handled by OmniSharp-roslyn, not OmniSharp-vim.

Create a ~/.omnisharp/omnisharp.json file like this:

{
  "FormattingOptions": {
    "EnableEditorConfigSupport": true
  }
}

See the OmniSharp-roslyn Configuration options for more options.

jedielson commented 3 years ago

Thank you so much.

It worked pretty well!!!

nickspoons commented 3 years ago

Great! Glad to hear it.