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

GoDef that takes you to a file that's already open in another Vim doesn't work correctly #2504

Closed
theclapp opened this issue Sep 20, 2019 · 3 comments

Comments

@theclapp
Copy link

What did you do?

^] (aka :GoDef) on a Go type
The file that holds the type is being edited by another Vim. So, for example, a swapfile for that file exists.

What did you expect to happen?

Open the other file, with the cursor on the type.

What happened instead?

Error / exception:
Found a swap file by the name ... [etc]
and these messages:

Error detected while processing function 275[13]..278[26]..<SNR>77_definitionHandler[4]..<SNR>84_jump_to_declaration_cb[5]..go#def#jump_to_declaration:
line   86:
E325: ATTENTION
Error detected while processing function 275:
line   13:
E171: Missing :endif

(I believe the above is due to Vim throwing an exception while reading the new file. I don't think the :endif is actually missing.)

The new file opens with the cursor at the top of the file.

Configuration:

vim-go version:

Tip as of 9/20/2019.

vimrc you used to reproduce:

vimrc
call plug#begin()
Plug 'fatih/vim-go'
call plug#end()

That's it, the whole thing. I commented everything else out and was still able to reproduce this bug.

Vim version (first three lines from :version):

VIM - Vi IMproved 8.1 (2018 May 18, compiled Jul 21 2019 22:54:00)
macOS version
Included patches: 1-1722
Compiled by Homebrew
Huge version with MacVim GUI.

Go version (go version):

go version go1.13 darwin/amd64

Go environment

go env Output:
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/lmc/Library/Caches/go-build"
GOENV="/Users/lmc/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/lmc/src/goget"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/lmc/src/goget/src/github.com/theclapp/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/lmc/src/goget/src/github.com/theclapp/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/lmc/src/goget/src/github.com/huckridgesw/hucksh/go.mod"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/32/8nd008752lv7v3vsgzlrw6qr0000gn/T/go-build134479523=/tmp/go-build -gno-record-gcc-switches -fno-common"
@theclapp
Copy link
Author

I believe the root of the problem is in autoload/go/def.vim, in

function! go#def#jump_to_declaration(out, mode, bin_name) abort
" ...
        exec cmd fnameescape(fnamemodify(filename, ':.'))

Since there's an exception when opening the file, the rest of the function after that (and in the rest of the call stack) isn't executed.

I added these lines around that exec to set shortmess+=A (shortmess help):

      let local_shm = &shm
      set shm+=A
      try
        exec cmd fnameescape(fnamemodify(filename, ':.'))
      finally
        exec "set shm=" . local_shm
      endtry

This saves &shm, adds A (don't give the "ATTENTION" message when an existing swap file is found) loads the file, and then restores &shm.

And that seems to work. Or at least it successfully masks the error!

@bhcleek
Copy link
Collaborator

bhcleek commented Sep 21, 2019

Thank you for the bug report.

You're right that your solution masks the error. I'd like to find a way to show the message about the the swap file without also exiting the function prematurely, but so far my attempts have always result in being placed in an empty buffer (except for when choosing the Recover option) 🤔

@bhcleek
Copy link
Collaborator

bhcleek commented Sep 28, 2019

I've submitted a pull request, #2518, that mostly resolves this, but unless you choose the recover option when presented with the option of what to do about the swap file, for some reason the buffer it initially displays is sometimes empty. You can execute :edit to reload it when it's empty, and then it's fine. I know this isn't ideal, but I'm very reluctant to completely hide the message about the swap file.

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