OmniSharp / omnisharp-vim

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

Find Usages isn't working #818

Closed matthewblott closed 1 year ago

matthewblott commented 1 year ago

Macbook Pro M1 macOS Monterey Neovim Mono installed (official installation) .NET 6.0 installed (official installation)

Here is a screenshot of the error:

Screenshot 2022-10-16 at 20 39 19

Here is the stack trace:

Error detected while processing function OmniSharp#proc#neovimOutHandler[21]..OmniSharp#stdio#HandleResponse[42]..<SNR>177_StdioFindRH[4]..<SNR>177_CBFindUsages[13]..OmniSharp#locations#SetQuickfix[5]..<S
NR>178_SetQuickfixFromDict[1]..BufWinEnter Autocommands for "*"..function 192[2]..193[4]..203[15]..function OmniSharp#proc#neovimOutHandler[21]..OmniSharp#stdio#HandleResponse[42]..<SNR>177_StdioFindRH[4]
..<SNR>177_CBFindUsages[13]..OmniSharp#locations#SetQuickfix[5]..<SNR>178_SetQuickfixFromDict[1]..BufWinEnter Autocommands for "*"..function 192[2]..193[4]..203:
line    6:
E788: Not allowed to edit another buffer now
Press ENTER or type command to continue
Error detected while processing function OmniSharp#proc#neovimOutHandler[21]..OmniSharp#stdio#HandleResponse[42]..<SNR>177_StdioFindRH[4]..<SNR>177_CBFindUsages[13]..OmniSharp#locations#SetQuickfix[5]..<S
NR>178_SetQuickfixFromDict[1]..BufWinEnter Autocommands for "*"..function 192[2]..193:
line    4:
E170: Missing :endfor
Press ENTER or type command to continue
Error detected while processing function OmniSharp#proc#neovimOutHandler[21]..OmniSharp#stdio#HandleResponse[42]..<SNR>177_StdioFindRH[4]..<SNR>177_CBFindUsages[13]..OmniSharp#locations#SetQuickfix[5]..<S
NR>178_SetQuickfixFromDict:
line    1:
E171: Missing :endif
Press ENTER or type command to continue
Error detected while processing function OmniSharp#proc#neovimOutHandler[21]..OmniSharp#stdio#HandleResponse[42]..<SNR>177_StdioFindRH[4]..<SNR>177_CBFindUsages:
line   13:
E171: Missing :endif
Press ENTER or type command to continue
Error detected while processing function OmniSharp#proc#neovimOutHandler[21]..OmniSharp#stdio#HandleResponse[42]..<SNR>177_StdioFindRH:
line    4:
E171: Missing :endif
Press ENTER or type command to continue
Error detected while processing function OmniSharp#proc#neovimOutHandler[21]..OmniSharp#stdio#HandleResponse:
line   42:
E171: Missing :endif
Press ENTER or type command to continue
Error detected while processing function OmniSharp#proc#neovimOutHandler:
line   21:
E170: Missing :endfor
Press ENTER or type command to continue

I did dig into the Vim files and have a look to see if there was anything obvious but it's not my area and I was getting a bit lost. I don't have any other issues at the moment and my Neovim installation is pretty recent. I tried turning off other plugins to see if it had any effect (it didn't). Online searches didn't tell me anything I could understand either. Any help appreciated :-)

nickspoons commented 1 year ago

What version of neovim is this? What omnisharp settings do you have in your config?

matthewblott commented 1 year ago

Neovim 0.8.0 OmniSharp Roslyn 1.39.1

The OmniSharp settings I have are the same as those on the home page of this website. I haven't changed anything.

matthewblott commented 1 year ago

Here is the full contents of my init.vim file:

" =====
" Modes
" =====

" c command-line
" i insert
" n normal
" o operator pending
" s select
" v visual and select
" x visual

" ===================
" Plugin Settings
" ===================

filetype plugin on

" ===================
" Plugins
" ===================

call plug#begin()

" CSS colour preview
Plug 'ap/vim-css-color'

Plug 'dense-analysis/ale'

Plug 'evanleck/vim-svelte', {'branch': 'main'}

Plug 'jiangmiao/auto-pairs'

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

Plug 'junegunn/fzf.vim'

" Extends " and @ to see register contents
"Plug 'junegunn/vim-peekaboo'

Plug 'mattn/emmet-vim'

" Auto-completion
Plug 'neoclide/coc.nvim'

Plug 'OmniSharp/omnisharp-vim'

Plug 'pangloss/vim-javascript'

Plug 'preservim/nerdcommenter'

Plug 'preservim/nerdtree'

" For use with ctags
Plug 'preservim/tagbar'

" Adds file icons to NERDTree
Plug 'ryanoasis/vim-devicons'

" Opens an interactive terminal with :Terminal
Plug 'tc50cal/vim-terminal'

" To change surrounding apostrophe to a tag: cs'<strong>
Plug 'tpope/vim-surround'

Plug 'valloric/MatchTagAlways'

Plug 'vim-autoformat/vim-autoformat'

Plug 'vim-airline/vim-airline'

Plug 'vim-syntastic/syntastic'

Plug 'vim-vdebug/vdebug'

call plug#end()

" ===================
" Leader
" ===================

let mapleader = " "

" ===================
" Theming
" ===================

syntax on
colorscheme monokai

" ========
" Mappings
" ========

inoremap kj <ESC>
nnoremap <Right> :vertical resize +1<CR>
nnoremap <Left> :vertical resize -1<CR>
nnoremap <Down> :resize +1<CR>
nnoremap <Up> :resize -1<CR>
nnoremap <leader>f 1z=             " replace misspelled word with the first entry in the replacement list
nnoremap <leader>s :set spell!<CR> " toggle spellcheck
nnoremap <leader>w :set list!<CR>  " toggle whitespace characters
nnoremap <leader>q :q!<CR>         " quit without saving
nnoremap a $A
nnoremap <C-n> :NERDTreeToggle<CR>
nnoremap o o<ESC>
nnoremap <S-o> O<ESC>
nnoremap <Tab> <C-W>W

" Coc
inoremap <expr> <cr> coc#pum#visible() ? coc#pum#confirm() : "\<CR>"

" ========
" Settings
" ========

set clipboard=unnamed               " allows clipboard use with OS
set relativenumber number           " show line numbers
set nocompatible                    " prevents vi compatibility which can disable some vim functionality
set noswapfile                      " disable the swapfile
set backspace=indent,eol,start
set hidden                          " prevents save prompt when buffer changes
set hlsearch                        " highlight all results
set ignorecase                      " ignore case in search
set incsearch                       " show search results as you type
"set spell! spelllang=en_gb
"set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:?~P?
set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:_
set grepprg=rg\ --vimgrep\ --smart-case\ --follow
set tabstop=2
set shiftwidth=2
set expandtab

" ===================
" Ale
" ===================

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

" ===================
" NERDTree
" ===================

let NERDTreeAutoDeleteBuffer=1

" Open the existing NERDTree on each new tab.
autocmd BufWinEnter * if getcmdwintype() == '' | silent NERDTreeMirror | endif

" Start NERDTree when Vim is started without file arguments.
"autocmd StdinReadPre * let s:std_in=1
"autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | endif

" Start NERDTree. If a file is specified, move the cursor to its window.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif

" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif

" Fix for this issue: https://github.com/preservim/nerdtree/issues/1321
let g:NERDTreeMinimalMenu=1

" ===================
" OmniSharp
" ===================

" Don't autoselect first omnicomplete option, show options even if there is only
" one (so the preview documentation is accessible). Remove 'preview', 'popup'
" and 'popuphidden' if you don't want to see any documentation whatsoever.
" Note that neovim does not support `popuphidden` or `popup` yet:
" https://github.com/neovim/neovim/issues/10996
if has('patch-8.1.1880')
  set completeopt=longest,menuone,popuphidden
  "" Highlight the completion documentation popup background/foreground the same as
  "" the completion menu itself, for better readability with highlighted
  "" documentation.
  set completepopup=highlight:Pmenu,border:off
else
  set completeopt=longest,menuone,preview
  "" Set desired preview window height for viewing documentation.
  set previewheight=5
endif

" Tell ALE to use OmniSharp for linting C# files, and no other linters.
let g:ale_linters = { 'cs': ['OmniSharp'] }

augroup omnisharp_commands
  autocmd!

  "" Show type information automatically when the cursor stops moving.
  "" Note that the type is echoed to the Vim command line, and will overwrite
  "" any other messages in this space including e.g. ALE linting messages.
  autocmd CursorHold *.cs OmniSharpTypeLookup

  "" The following commands are contextual, based on the cursor position.
  autocmd FileType cs nmap <silent> <buffer> gd <Plug>(omnisharp_go_to_definition)
  autocmd FileType cs nmap <silent> <buffer> <Leader>osfu <Plug>(omnisharp_find_usages)
  autocmd FileType cs nmap <silent> <buffer> <Leader>osfi <Plug>(omnisharp_find_implementations)
  autocmd FileType cs nmap <silent> <buffer> <Leader>ospd <Plug>(omnisharp_preview_definition)
  autocmd FileType cs nmap <silent> <buffer> <Leader>ospi <Plug>(omnisharp_preview_implementations)
  autocmd FileType cs nmap <silent> <buffer> <Leader>ost <Plug>(omnisharp_type_lookup)
  autocmd FileType cs nmap <silent> <buffer> <Leader>osd <Plug>(omnisharp_documentation)
  autocmd FileType cs nmap <silent> <buffer> <Leader>osfs <Plug>(omnisharp_find_symbol)
  autocmd FileType cs nmap <silent> <buffer> <Leader>osfx <Plug>(omnisharp_fix_usings)
  autocmd FileType cs nmap <silent> <buffer> <C-\> <Plug>(omnisharp_signature_help)
  autocmd FileType cs imap <silent> <buffer> <C-\> <Plug>(omnisharp_signature_help)

  "" Navigate up and down by method/property/field
  autocmd FileType cs nmap <silent> <buffer> [[ <Plug>(omnisharp_navigate_up)
  autocmd FileType cs nmap <silent> <buffer> ]] <Plug>(omnisharp_navigate_down)
  "" Find all code errors/warnings for the current solution and populate the quickfix window
  autocmd FileType cs nmap <silent> <buffer> <Leader>osgcc <Plug>(omnisharp_global_code_check)
  "" Contextual code actions (uses fzf, vim-clap, CtrlP or unite.vim selector when available)
  autocmd FileType cs nmap <silent> <buffer> <Leader>osca <Plug>(omnisharp_code_actions)
  autocmd FileType cs xmap <silent> <buffer> <Leader>osca <Plug>(omnisharp_code_actions)
  "" Repeat the last code action performed (does not use a selector)
  autocmd FileType cs nmap <silent> <buffer> <Leader>os. <Plug>(omnisharp_code_action_repeat)
  autocmd FileType cs xmap <silent> <buffer> <Leader>os. <Plug>(omnisharp_code_action_repeat)

  autocmd FileType cs nmap <silent> <buffer> <Leader>os= <Plug>(omnisharp_code_format)

  autocmd FileType cs nmap <silent> <buffer> <Leader>osnm <Plug>(omnisharp_rename)

  autocmd FileType cs nmap <silent> <buffer> <Leader>osre <Plug>(omnisharp_restart_server)
  autocmd FileType cs nmap <silent> <buffer> <Leader>osst <Plug>(omnisharp_start_server)
  autocmd FileType cs nmap <silent> <buffer> <Leader>ossp <Plug>(omnisharp_stop_server)
augroup END

"" Enable snippet completion, using the ultisnips plugin
"" let g:OmniSharp_want_snippet=1

" For more settings see:
" https://github.com/thousandtyone/nvimsettingsandmods/blob/main/init.vim
nickspoons commented 1 year ago

Oh yep I can repro in nvim 0.6 actually

nickspoons commented 1 year ago

Sorry I spoke too soon, that was a plugin conflict. I did see that error "E788: Not allowed to edit another buffer now" but not after removing the vim9 plugin. I've tried with nvim 0.6, 0.7 and 0.9. I'll keep digging.

matthewblott commented 1 year ago

Ha, I thought that seemed a bit quick!

nickspoons commented 1 year ago

You say this doesn't occur with your other plugins disabled? Could you try it without your custom autocommands? Just comment out these lines:

autocmd BufWinEnter * if getcmdwintype() == '' | silent NERDTreeMirror | endif

" Start NERDTree when Vim is started without file arguments.
"autocmd StdinReadPre * let s:std_in=1
"autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | endif

" Start NERDTree. If a file is specified, move the cursor to its window.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif

" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
nickspoons commented 1 year ago

The error message says it's happening during an autocmd execution so I wonder if one of these is doing it - most likely the first one

matthewblott commented 1 year ago

Yes it is the first line:

autocmd BufWinEnter * if getcmdwintype() == '' | silent NERDTreeMirror | endif

The only plugin I didn't try to remove was NERDTree - it's so ubiquitous I didn't think it could possibly be an issue (sorry, brain fart).

nickspoons commented 1 year ago

OK. I think you can probably trigger this error by just opening a fresh vim/nvim and running :copen.

nickspoons commented 1 year ago

You could try to extend your conditional to exclude quickfix buffers:

autocmd BufWinEnter * if &buftype != 'quickfix' && getcmdwintype() == '' | silent NERDTreeMirror | endif
matthewblott commented 1 year ago

Yeah, I'll have a play around. It's not a showstopper to have NERDTree not display. In fact it might be better not to display it as it isn't clear what tab files are open. I'm just used to having a file tree coming from other editors! I'd say you can close this, I suspect this is pretty much an edge case. Thanks again for your help!

nickspoons commented 1 year ago

I don't think this even has anything really to do with NERDTree itself, it's just a bad autocmd recommendation from the NERDTree README. I just found 2 issues relating to it: https://github.com/preservim/nerdtree/issues/1271 and https://github.com/preservim/nerdtree/issues/1275. My suggestion above turns out to be exactly what others have found. The sensible thing is to fix the README suggestion.

nickspoons commented 1 year ago

I made a PR to fix the NERDTree README