Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use literal newline in order to properly split the string #3358

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sbatial
Copy link

@sbatial sbatial commented Feb 16, 2022

This should fix go#tool#Files() and go#tool#Imports() as described by my comment in #3300.

All tests passed. 👍 🚀

@sbatial sbatial marked this pull request as ready for review February 16, 2022 16:30
@bhcleek
Copy link
Collaborator

bhcleek commented Feb 16, 2022

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?

@bhcleek
Copy link
Collaborator

bhcleek commented Feb 16, 2022

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).

@bhcleek
Copy link
Collaborator

bhcleek commented Feb 16, 2022

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.

@sbatial
Copy link
Author

sbatial commented Feb 17, 2022

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.

@sbatial
Copy link
Author

sbatial commented Feb 26, 2022

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 using printf "\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.

@bhcleek
Copy link
Collaborator

bhcleek commented Feb 26, 2022

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 using printf "\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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants