dag / vim-fish

Vim support for editing fish scripts
MIT License
432 stars 59 forks source link

Completion is broken #50

Open MaxGyver83 opened 3 years ago

MaxGyver83 commented 3 years ago

Sometimes, when I edit fish files, I get this error many times:

Error detected while processing function fish#Complete:
line    8:
E484: Can't open file /tmp/vCliDT0/13
Press ENTER or type command to continue

What I did:

vim /tmp/test.fish
iif test -e "/ca

Then this error occurs after every character I type.

I also have vim-mucomplete installed. So vim tries to autocomplete.

MaxGyver83 commented 3 years ago

Meanwhile I know this issue has nothing to do with vim-mucomplete. This is how to reproduce:

Create a file named ~/.vim/fish-test.vim:

set nocompatible
set runtimepath=$VIMRUNTIME
set runtimepath+=~/.vim/pack/plugins/start/vim-fish
set omnifunc=fish#Complete

Run vim -u ~/.vim/fish-test.vim /tmp/test.fish. Switch to insert mode and type "te. Press Ctrl-x Ctrl-o for autocompletion. This causes the error from my initial post.

I found a similar issue in another plugin: https://github.com/kristijanhusak/vim-js-file-import/issues/31

Apparently, it has to do with doubles quotes in fish. This patch doesn't fix this issue but at least it occurs less often:

diff --git a/autoload/fish.vim b/autoload/fish.vim
index 2c4d894..199e155 100644
--- a/autoload/fish.vim
+++ b/autoload/fish.vim
@@ -48,9 +48,10 @@ function! fish#Complete(findstart, base)
         if empty(a:base)
             return []
         endif
+        let l:base = substitute(a:base, '"', "'", "")
         let l:results = []
         let l:completions =
-                    \ system('fish -c "complete -C'.shellescape(a:base).'"')
+                    \ system('fish -c "complete -C'.shellescape(l:base).'"')
         let l:cmd = substitute(a:base, '\v\S+$', '', '')
         for l:line in split(l:completions, '\n')
             let l:tokens = split(l:line, '\t')