OmniSharp / omnisharp-vim

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

Ale don't work when i open file by fzf. #765

Closed Tutarala closed 2 years ago

Tutarala commented 2 years ago

If i use the default command like :FZF in vim, it's OK.

But fzf will found all filetypes in my project. So i try to limit the Seaching by using specify command like that :

let g:fd_command = 'fd --type f -e cs -e json -e ts -e effect -e chunk --exclude={.git,node_modules,vendor,build,library,temp,settings,packages,local}'
command! -bang -nargs=* QFiles call fzf#run(fzf#wrap({'source': g:fd_command, 'dir': fnamemodify(getcwd(), ':~:.\')}))

And i open cs file in fzf split window, then Ale won't work any more.But if open it by other way like NERDTree is OK. By the way, I use this function in mac, it is working good too.

I think the issue is not in the Ale, cause i try to use syntastic it block in the same way. Is there anyone has the same issue like me? Or there is any function can instead of mine?

nickspoons commented 2 years ago

I can't reproduce this.

asciicast

Can you make sure the file you are opening with your :QFiles command is in a project/solution that has a running server? I like to keep the project/solution name in my statusline (it's just called "tmp" in the screencast above, bottom right) which can help with this, using vim-sharpenup.

Alternatively, check the current server name with this command:

:echo OmniSharp#GetHost(bufnr('%')).sln_or_dir

If this isn't the issue, you'll need to provide more information so I can see what you mean.

Tutarala commented 2 years ago

Thanks for your reply. And i watched your recording video, i think you can't find this issue in Linux or Mac OS. I sure that the issue just happen in Windows(GVIM). I have spent a lot of time to figure out this issue, and i guess it's a file path issue. (\ and /) Using :FZF 20220318-155516

Using :QFiles 20220318-155512

https://user-images.githubusercontent.com/12286040/158961781-bd70aad7-cfa8-4435-8969-10193203a0e5.mp4

nickspoons commented 2 years ago

I can't reproduce this in Windows either

Tutarala commented 2 years ago

This is my vimrc file. And my system os is Windows11.

" Vim with all enhancements

let g:isWin = 0
if (has("win32") || has("win95") || has("win64") || has("win32"))
    let g:isWin = 1
endif

call plug#begin('~/.vim/plugged')
Plug 'scrooloose/nerdtree'
Plug 'jistr/vim-nerdtree-tabs'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'dense-analysis/ale'
Plug 'OmniSharp/omnisharp-vim'
Plug 'nickspoons/vim-sharpenup'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
call plug#end()

map <leader>t :NERDTreeToggle<CR>
let g:NERDTreeChDirMode = 2
let NERDTreeShowLineNumbers=1
let NERDTreeShowHidden=1
let NERDTreeWinSize=40
let g:nerdtree_tabs_open_on_console_startup=1
let NERDTreeIgnore=['\.pyc','\~$','\.swp','\.meta']
let NERDTreeShowBookmarks=1

noremap <c-p> :Buffers<CR>
noremap <leader>p :FZF<CR>
noremap ` :FZF<CR>
let g:fzf_layout = { 'up': '~40%' }
let g:fzf_buffers_jump = 1
let g:fzf_action = {
  \ 'enter': 'edit',
  \ 'ctrl-x': 'split',
  \ 'ctrl-v': 'vsplit' }
let g:rg_command = '
  \ rg --column --line-number --no-heading --fixed-strings --ignore-case --no-ignore --hidden --follow --color "always"
  \ -g "*.{json,cs,ts,effect,chunk}"
  \ -g "!{.git,node_modules,vendor,build,library,temp,settings,packages,local}/*" '

command! -bang -nargs=* F call fzf#vim#grep(g:rg_command .shellescape(<q-args>), 1, <bang>0)

function! s:shortpath()
  let short = fnamemodify(getcwd(), ':~:.')
  if !has('win32unix')
    let short = pathshorten(short)
  endif
  let slash = (!&shellslash) ? '\' : '/'
  return empty(short) ? '~'.slash : short . (short =~ escape(slash, '\').'$' ? '' : slash)
endfunction

let g:fd_command = 'fd --type f -e cs -e json -e ts -e effect -e chunk --exclude={.git,node_modules,vendor,build,library,temp,settings,packages,local}'
command! -bang -nargs=* QFiles call fzf#run(fzf#wrap({'source': g:fd_command, 'dir': fnamemodify(getcwd(), ':~:.\')}))

command! -bang -nargs=* CSFiles call fzf#vim#files(fnamemodify(getcwd(), ':~:.'))

let g:OmniSharp_server_stdio = 1
let g:OmniSharp_selector_ui = 'fzf'    " Use fzf
let g:OmniSharp_selector_findusages = 'fzf'
let g:OmniSharp_selector_findmember = 'fzf'
let g:OmniSharp_loglevel = 'DEBUG'
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 nnoremap <buffer> <Leader>gd :OmniSharpGotoDefinition<CR>
    autocmd FileType cs nnoremap <buffer> <Leader>fi :OmniSharpFindImplementations<CR>
    autocmd FileType cs nnoremap <buffer> <Leader>fs :OmniSharpFindSymbol<CR>
    autocmd FileType cs nnoremap <buffer> <Leader>fu :OmniSharpFindUsages<CR>

    " Finds members in the current buffer
    autocmd FileType cs nnoremap <buffer> <Leader>fm :OmniSharpFindMembers<CR>

    autocmd FileType cs nnoremap <buffer> <Leader>fx :OmniSharpFixUsings<CR>
    autocmd FileType cs nnoremap <buffer> <Leader>tt :OmniSharpTypeLookup<CR>
    autocmd FileType cs nnoremap <buffer> <Leader>dc :OmniSharpDocumentation<CR>
    autocmd FileType cs nnoremap <buffer> <Leader>rs :OmniSharpRestartServer<CR>
    autocmd FileType cs nmap <silent> <buffer> <Leader>qq <Plug>(omnisharp_preview_definition)
    autocmd FileType cs nmap <silent> <buffer> <Leader>qw <Plug>(omnisharp_preview_implementations)
    autocmd FileType cs nnoremap <buffer> <C-\> :OmniSharpSignatureHelp<CR>
    autocmd FileType cs inoremap <buffer> <C-\> <C-o>:OmniSharpSignatureHelp<CR>

    " Navigate up and down by method/property/field
    autocmd FileType cs nnoremap <buffer> <C-k> :OmniSharpNavigateUp<CR>
    autocmd FileType cs nnoremap <buffer> <C-j> :OmniSharpNavigateDown<CR>

    " Find all code errors/warnings for the current solution and populate the quickfix window
    autocmd FileType cs nnoremap <buffer> <Leader>cc :OmniSharpGlobalCodeCheck<CR>
augroup END

" asynccomplete
let g:asyncomplete_auto_popup = 1
" allow modifying the completeopt variable, or it will
" be overridden all the time
let g:asyncomplete_auto_completeopt = 1
set completeopt=menuone,noinsert,noselect,preview

" ALE: {{{
let g:ale_sign_error = '*'
let g:ale_sign_warning = '*'
let g:ale_sign_info = '^'
let g:ale_sign_style_error = '^'
let g:ale_sign_style_warning = '^'

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

Is there any problem in my config file?

nickspoons commented 2 years ago

I don't think there's anything in particular wrong with your .vimrc but even using that, I can't reproduce your problem.

After opening the files in your example, first one using :FZF and then one using :QFiles, what is the full name of the files you have opened?

:echo fnameescape(expand('%:p'))

Does refreshing the files with :e change anything?

Tutarala commented 2 years ago

:echo fnameescape(expand('%:p')) 20220321-102942 20220321-102948 Then,I'm refreshing the files with :e, but it didn't change anything. It's so weird. If you can't reproduce my problem, it might be a bug in my system environment. Well, it seems that i need to reset my system.

nickspoons commented 2 years ago

Have you looked at the server logs? That might give some clue. :OmniSharpOpenLog. Also, as this is a Unity project and therefore .NET Framework, I just want to double check ... both files are definitely referenced in the .csproj file?

Tutarala commented 2 years ago

I check the server logs, But i can't find anything. By the way, i think files are including by the .csproj file. 20220321-113103

It dosn't matter witch file you are opening. It depends witch command you are using. And if you Open "TestA.cs" by :FZF at first, then you open it again by :QFiles.It will be ok.But not the reverse way. It seems some problem let the server can't follow the file when i use QFiles.

nickspoons commented 2 years ago

I was never able to reproduce this problem.

Looking at it again, I wonder if the issue was that your working directory was not the project root? Perhaps that combined with this part of your custom command was causing the problem, and causing OmniSharp-roslyn to not recognise the file as part of the solution:

fnamemodify(getcwd(), ':~:.\')

It would be easier to debug with a log, particularly a full debug log.

I'm going to choose this for now as I can't reproduce and don't have any more information to work with. If you're still experiencing the problem, try this in your .vimrc:

let g:OmniSharp_loglevel = 'debug'

Then restart vim and trigger the error, then open the log and post it here.