Use literal newline in order to properly split the string
This should fix go#tool#Files() and go#tool#Imports() as described by my comment in #3300.
All tests passed. :+1: :rocket:
I'm not sure that this solves the problem or that it doesn't introduce a new one on some OSes.
In any case, I can't duplicate #3300 at all, and I don't see any reason that the current form would be a problem.
Can you duplicate the problem described in #3300 with Vim or only with Neovim?
I'd also be interested in knowing what you see for these go list commands on master when g:go_debug is set to ['shell-commands'] (e.g. let g:go_debug=['shell-commands'] in your vimrc).
FWIW, I can duplicate the issue with Neovim, but not with Vim. It seems like the issue here may be how Neovim is handling escaped characters when it invokes external commands.
Ah that's interesting. I thought this was a Windows/Linux thing. I actually didn't try it with Vim.
I'll try it with Vim, but if you can only reproduce it with Neovim it is probably a nvim issue.
I will also look into go list.
Yes, it seems as if it has to do with the escaping in neovim.
Ok, so.
I looked into it and I get the same error with vim as well (I am on master. The complete config file I load for vim as well as nvim is
let data_dir = '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin(data_dir . '/plugged')
Plug 'fatih/vim-go', { 'for': 'go', 'do': ':GoUpdateBinaries' }
call plug#end()
let g:go_debug=['shell-commands']
I dug around quite some time and thought I could pin it down but I couldn't settle on a definitive result.
Some findings:
- when using
split(l:out, '\\n')the newline character is properly cut off - when running the command logged by setting the go_debug variable:
go list -f '{{range $f := .GoFiles}}{{$.Dir}}/{{$f}}{{end}}{{printf "\\n"}}{{range $f := .CgoFiles}}{{$.Dir}}/{{$f}}{{printf "\\n"}}{{end}}'manually in a shell I get the same result, but when usingprintf "\n"(in sh) instead it works fine
But regarding your concerns it could break compatibility on other OS: My fix uses basically the same code as in go#util#Deps which works just fine. Given that this works I wouldn't expect any problems in the other functions.
Unfortunately I can't test it on any non-Linux OS right now to see how it behaves there.
when running the command logged by setting the go_debug variable:
go list -f '{{range $f := .GoFiles}}{{$.Dir}}/{{$f}}{{end}}{{printf "\\n"}}{{range $f := .CgoFiles}}{{$.Dir}}/{{$f}}{{printf "\\n"}}{{end}}'manually in a shell I get the same result, but when usingprintf "\n"(in sh) instead it works fine
My first inclination was that what you're seeing logged is escaped for logging purposes, so it makes sense that you'd see \\n instead of \n there. But I tested that hypothesis, and I don't see \\n in the output, I only see \n. I think that may point us to the root cause for this behavior.
I wonder if the behavior you're seeing has something to do with the shell options that vim-go sets (or that it doesn't set!)?
In a go file, what does :set output for you?