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

Template creation and BufNewFile rules do not contemplate non-modifiable buffers #2096

Closed
mixedCase opened this issue Dec 17, 2018 · 3 comments

Comments

@mixedCase
Copy link
Contributor

What did you do? (required. The issue will be closed when not provided.)

Tried to open a .go file in a non-modifiable buffer, specifically, vim-gina's Blame's.

What did you expect to happen?

vim-go not to interfere.

What happened instead?

vim-go attempted to set fileencoding, and when patching that out, attempts to instantiate the go template.

Configuration (MUST fill this out):

  • vim-go version: 1896764

  • vimrc you used to reproduce (use a minimal vimrc with other plugins disabled; do not link to a 2,000 line vimrc):

Assuming vim-plugged installed:

call plug#begin('~/.config/nvim/plugged')
Plug 'fatih/vim-go', { 'for': 'go' }
Plug 'lambdalisue/gina.vim'
call plug#end()

Open a .go file, run :Gina blame, first time works, try again, next time fails.

  • Vim version (first three lines from :version):
NVIM v0.3.1
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/cc -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -Wconversion -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -Wno-array-bounds -D
INCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/build/neovim/src/build/config -I/build/neovim/src/neovim-0.3.1/src -I/usr/include -I/build/neovim/src/build/src/nvim/auto -I/build/neovim/src/build/include
  • Go version (go version):

go version go1.11.3 linux/amd64

  • Go environment (go env):
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mixedcase/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mixedcase/.go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build209011493=/tmp/go-build -gno-record-gcc-switches"
@bhcleek
Copy link
Collaborator

bhcleek commented Dec 22, 2018

I've create a non-modifiable Go file whose fileformat is dos and have no problems opening it. Can you construct a basic test case to demonstrate that this is a problem with vim-go and not a problem with something that vim-gina is doing?

vim-go attempted to set fileencoding, and when patching that out, attempts to instantiate the go template.

vim-go doesn't read in the Go template unless the file is a new buffer. Even so, it doesn't attempt to write the buffer afterward; what problem did you actually experience?

@mixedCase
Copy link
Contributor Author

@bhcleek Pretty much as described in the "Configuration" section of the OP. Some more context: The errors in particular that occur when I say it "fails" is vim telling me that it can't set fileencoding (as vim-go attempts to do) because the buffer is not modifiable:

Error detected while processing BufNewFile Auto commands for "*.go":                                                                                                                                                                                                                                                           
E21: Cannot make changes, 'modifiable' is off: fileencoding=utf-8                                                                                                                                                                                                                                                              
Press ENTER or type command to continue     

And when I patch that behavior to only do so when the buffer is modifiable (as seen in the gofiletype.vim change from the PR), it gives me the following:

Error detected while processing function <SNR>81_template_autocreate[3]..go#template#create:                                                                                                                                                                                                                                   
line   24:                                                                                                                                                                                                                                                                                                                     
E21: Cannot make changes, 'modifiable' is off: keepalt 0r /home/mixedcase/code/sw/dotfiles/.config/nvim/plugged/vim-go/templates/hello_world.go                                                                                                                                                                                
Press ENTER or type command to continue    

Which gets solved with the other check added in the PR.

From what I've been able to tell vim-gina seems to create a new "file" which is set to non-modifiable on creation, and vim-go assumes (in both the fileencoding set that is changed in the PR and the call to template_autocreate which is in

autocmd BufNewFile *.go call s:template_autocreate()
) that BufNewFile implies a modifiable buffer. Without encountering this edge-case, I guess the rule makes perfect sense. In fact I've found someone that hit the same issue when setting up autocommand rules in his .vimrc: https://stackoverflow.com/questions/11392941/disabling-autocommands-for-help-buffers

I'm sorry I couldn't provide a simpler test case that doesn't involve gina nor mentioned the specific errors, I was a bit hurried so I thought the patch and issue description would suffice. Truth be told, I'm not sure how I could create a simpler test case. I tried to look at gina's codebase to see where the blame command creates the buffer but couldn't make much sense of it since I'm only vaguely familiar with Vimscript. Please let me know if I could be of further assistance.

@bhcleek
Copy link
Collaborator

bhcleek commented Dec 24, 2018

Open a .go file, run :Gina blame, first time works, try again, next time fails.

This fact points to something odd in gina.vim.

Ultimately, I see this as being a problem with the way gina.vim is functioning; it's using .go as the extension for buffers that should not be treated as Go buffers. vim-fugitive has similar functionality and cause no problems. This has been brought up before with gina.vim, but lambdalisue/vim-gina#82 was closed without a proper resolution.

This PR has prompted me to take a closer look at ftdetect/gofiletype.vim, ftplugin/go.vim, and plugin/go.vim; I think we should make some more significant changes there so that the right options are set in ftplugin/go.vim and undo_ftplugin is configured correctly.

Thanks for all the feedback. For now, I think we can leave this issue open; I'll likely refactor the files I mentioned in the near future.

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

No branches or pull requests

2 participants