fatih / vim-go

Go development plugin for Vim
https://www.patreon.com/bhcleek
Other
15.99k stars 1.45k forks source link

GoDef hangs if target file not open in buffer #2864

Closed pauldthomson closed 4 years ago

pauldthomson commented 4 years ago

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

Went to a symbol in a Go file, ran the :GoDef command

What did you expect to happen?

File containing the definition is opened in a new buffer

What happened instead?

The new buffer is opened, but vim doesn't jump to the buffer. Instead it seems to hang. Pressing ctrl-c then kills whatever is hanging and vim jumps to the definition in the newly opened buffer. The :messages command shows this:

vim-go: [definition] SUCCESS
"pkg/controller/table/table_controller.go" 128L, 4640C
vim-go: Vim:Interrupt

where the Vim:Interrupt is from me pressing ctrl-c

This doesn't happen if the target file is already open in another buffer i.e. once the buffer is loaded, :GoDef works as expected.

Configuration (MUST fill this out):

vim-go version:

13af5df

vimrc you used to reproduce:

vimrc
" =========================
" Vim built in config
" =========================
filetype plugin indent on
syntax on
set cursorline
set number
set relativenumber
set autowrite
set encoding=utf-8
set tabstop=4 
set expandtab 
set shiftwidth=4 
set smarttab
set showmatch
set hlsearch
set incsearch
set ignorecase
set smartcase
set noerrorbells
set visualbell
set splitbelow
set splitright

"Get the 2-space YAML as the default when hit carriage return after the colon
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab

" Disable arrowkeys in insert and normal modes
noremap  
noremap  
noremap  
noremap  
inoremap     
inoremap   
inoremap   
inoremap  

" Move visual selection
vnoremap J :m '>+1gv=gv
vnoremap K :m '<-2gv=gv

" Map leader to space
let mapleader="\"

" Always show statusline
set laststatus=2

" Allow backspacing over everything in insert mode
set backspace=indent,eol,start

" Use jk to exit insert mode 
inoremap jk 

" Use ctrl+hjkl to navigate splits
nnoremap  
nnoremap  
nnoremap  
nnoremap  

" Save buffer
nnoremap w :w

" Copy to system clipboard in visual mode
vmap y "+y

" Paste from system clipboard
nmap p "+p

" =========================
" NERDTree
" =========================

" Toggle NERDTree
map  :NERDTreeToggle

" Show hidden files in NERDTree
let NERDTreeShowHidden=1

" =========================
" vim-java
" =========================

" Java syntax
let g:java_highlight_functions = 1

" =========================
" Colourscheme
" =========================
colorscheme codedark

" =========================
" vim-airline
" =========================
let g:airline_theme = 'codedark'
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#formatter = 'unique_tail_improved'

" =========================
" vim-gitgutter
" =========================
" To make gitgutter diff markers show faster
set updatetime=100

" =========================
" vim-fugitive
" =========================
" Open fugitive diff in verticle splits
set diffopt+=vertical

" =========================
" fzf
" =========================
set rtp+=/usr/local/opt/fzf

" fzf files
nnoremap f :Files

" fzf lines in file
nnoremap / :BLines

" fzf vim commands
nnoremap c :Commands

" Open fzf buffers list
nnoremap e :Buffers

" Use ripgrep
nnoremap r :Rg

if executable('rg')
  let $FZF_DEFAULT_COMMAND = 'rg --files --hidden --follow --glob "!.git/*"'
endif

" =========================
" vim-terraform
" =========================
" Format terraform
let g:terraform_fmt_on_save = 1
let g:tereraform_align = 1

" =========================
" coc.nvim
" =========================
" Use  for trigger completion and navigate to next complete item
function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~ '\s'
endfunction

inoremap  
      \ pumvisible() ? "\" :
      \ check_back_space() ? "\" :
      \ coc#refresh()
inoremap  pumvisible() ? "\" : "\"

" Coc rename
nmap  (coc-rename)

" Use enter to select completion
inoremap   pumvisible() ? "\" : "\u\"

" Remap keys for gotos
nmap  gd (coc-definition)
nmap  gy (coc-type-definition)
nmap  gi (coc-implementation)
nmap  gr (coc-references)

" =========================
" vim-go
" =========================
" Highlighting
let g:go_highlight_build_constraints = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_operators = 1
let g:go_highlight_structs = 1
let g:go_highlight_types = 1

" Show info about type or method
let g:go_auto_type_info = 1

" Run :GoBuild or :GoTestCompile based on the go file
function! s:build_go_files()
  let l:file = expand('%')
  if l:file =~# '^\f\+_test\.go$'
    call go#test#Test(0, 1)
  elseif l:file =~# '^\f\+\.go$'
    call go#cmd#Build(0)
  endif
endfunction

autocmd FileType go nmap b :call build_go_files()
autocmd FileType go nmap t  (go-test)

" Run goimports on save
let g:go_fmt_command = "goimports"

" Control how to open buffer when alternating between test and src
autocmd Filetype go command! -bang A call go#alternate#Switch(0, 'edit')
autocmd Filetype go command! -bang AV call go#alternate#Switch(0, 'vsplit')
autocmd Filetype go command! -bang AS call go#alternate#Switch(0, 'split')
autocmd Filetype go command! -bang AT call go#alternate#Switch(0, 'tabe')
autocmd Filetype go nmap gav (go-alternate-vertical)
autocmd Filetype go nmap ga (go-alternate-edit)
autocmd Filetype go nmap  :GoDecls
autocmd FileType go nmap  :GoTest
autocmd FileType go nmap  :GoTestFunc
autocmd FileType go nmap  :GoReferrers

" Automatically highlight same identifiers (functions, variables etc)
let g:go_auto_sameids = 1

" Use gopls everywhere I can
let g:go_def_mode = 'gopls'
let g:go_info_mode = 'gopls'
let g:go_rename_command = 'gopls'
let g:go_gopls_complete_unimported = 1

" =========================
" indentLine
" =========================
" Scrolling performance
let g:indentLine_faster     = 1
let g:indentLine_setConceal = 0

Vim version (first three lines from :version):

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Apr 19 2020 22:39:33) macOS version Included patches: 1-600

Go version (go version):

go version go1.14.2 darwin/amd64

Go environment

go env Output:

GO111MODULE=""
GOARCH="amd64"
GOBIN="/usr/local/go/bin"
GOCACHE="/Users/pthomson/Library/Caches/go-build"
GOENV="/Users/pthomson/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY="github.com/tyro-private"
GONOSUMDB="github.com/tyro-private"
GOOS="darwin"
GOPATH="/Users/pthomson/go"
GOPRIVATE="github.com/tyro-private"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.2_1/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.2_1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/1n/fg0y62lj3sz31db9vtvbym006nsw3r/T/go-build755232971=/tmp/go-build -gno-record-gcc-switches -fno-common"

gopls version

gopls version Output:

golang.org/x/tools/gopls 0.4.0
    golang.org/x/tools/gopls@v0.4.0 h1:G4+YP9kaV4dJb79J5MobyApxX493Qa6VoiTceUmxqik=
bhcleek commented 4 years ago

I use :GoDef frequently without problems. Does it ever work for you? Can you provide a simple reproduction case?

pauldthomson commented 4 years ago

It started a couple of weeks ago. It seems to always hang if the target is in a new file, and that file isn't yet loaded in a buffer. If the file is loaded, it works fine.

How would you like me to provide the case? Sample repo or just screen record the behaviour?

bhcleek commented 4 years ago

if the target is in a new file, and that file isn't yet loaded in a buffer.

If it's a new file relative to what?

How would you like me to provide the case? Sample repo or just screen record the behaviour?

A sample repo is ideal.

I'll help you get to the bottom of this, and gopls is the preferred option, but you might be interested to know that you can set g:go_def_mode to use godef or guru to jump to definitions instead of gopls, too.

pauldthomson commented 4 years ago

If it's a new file relative to what?

Relative to the symbol whose definition I'm wanting to jump to. E.g. if I had this in file-1.go

f.someFunction()

and someFunction() was defined in file-2.go, then running :GoDef on that function would cause the hang, but only if file-2.go wasn't already open in another buffer.

I'll help you get to the bottom of this, and gopls is the preferred option, but you might be interested to know that you can set g:go_def_mode to use godef or guru to jump to definitions instead of gopls, too.

I could give that a shot, but I don't think it's gopls, the definition seems to be found, the file containing the definition is opened in another buffer, but it hangs before switching to that buffer/tab.

As for a repo, in https://github.com/schemahero/schemahero, if I go to this file/line: https://github.com/schemahero/schemahero/blob/841b9e897f278e34e9b04a041e9968eb1b5b0d8c/pkg/controller/table/reconile_table.go#L199 and run :GoDef on r.getPlanPod(), I can replicate the behaviour.

bhcleek commented 4 years ago

I'm able to jump to the definiton of r.getPlanPod, though on the first attempt there is a delay.

pauldthomson commented 4 years ago

Hmmm. OK I fired up another computer and it also worked fine (all my dotfiles are in git so the setup is somewhat the same).

I guess at this point the only thing I can think of is something about my Go setup or Vim? I'll close this issue anyway. Thanks for your help and sorry for misleading :)

pauldthomson commented 4 years ago

Seems it's Vim. My other computer was running 8.2.500 and the one with the issue had 8.2.600. Just updated the former and it now suffers the same issue.