fatih / vim-go

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

`:GoCoverage` doesn't work with go1.9 #1421

Closed weirdgiraffe closed 7 years ago

weirdgiraffe commented 7 years ago

Behavior

I've intalled go1.9.linux-amd64. Then I've tried to use :GoCoverage as usualy but from now on I constantly get the following error:

vim-go: [test] PASS
Error detected while processing function go#coverage#Buffer[61]..go#coverage#overlay:
line   57:
E28: No such highlight group name: goCoverageNormalText

I expect :GoCoverage to work as before

Steps to reproduce:

  1. follow go installation instructions at https://golang.org/doc/install
  2. save provided vimrc as ~/issuevimrc
  3. go to tar package folder cd /usr/local/go/src/archive/tar
  4. start vim vim -u ~/issuevimrc common.go, issue :PlugInstall command, then quit vim.
  5. start vim vim -u ~/issuevimrc common.go, issue :GoInstallBinaries , then quit vim.
  6. start vim vim -u ~/issuevimrc common.go, issue :GoCoverage command in vim.

Configuration

vimrc

" vim:ts=2:sw=2:et
set nocompatible               " disable vi
set backspace=indent,eol,start " make backspace full functional
" disable Ex mode
nnoremap Q <Nop>
nnoremap gQ <Nop>
" fix undo (http://vim.wikia.com/wiki/Recover_from_accidental_Ctrl-U)
inoremap <c-u> <c-g>u<c-u>
inoremap <c-w> <c-g>u<c-w>
" restore terminal screen after quit
if has("terminfo")
  let &t_Sf = "\ESC[3%p1%dm"
  let &t_Sb = "\ESC[4%p1%dm"
else
  let &t_Sf = "\ESC[3%dm"
  let &t_Sb = "\ESC[4%dm"
endif
syntax enable             " enable syntax highlighting

" vim-plug {{{
" Automatically install Vim-Plug if it is not yet installed
if empty(glob($HOME.'/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall | source $MYVIMRC
endif

call plug#begin($HOME.'/.vim/plugged')
Plug 'fatih/vim-go', {'for': 'go', 'do': ':GoInstallBinaries'}
call plug#end()
" vim-plug }}}

" vim-go {{{
let g:go_fmt_command = "goimports"
let g:go_fmt_autosave = 1
let g:go_gocode_unimported_packages = 1
let g:go_template_autocreate = 0
let g:go_auto_type_info = 1
let g:go_addtags_transform = "snakecase"
let g:go_def_reuse_buffer = 1
au FileType go nmap <leader>q <Plug>(go-build)
au FileType go nmap <leader>w <Plug>(go-test)
au FileType go nmap <leader>e <Plug>(go-coverage)
au FileType go nmap <leader>r <Plug>(go-referrers)
au FileType go nmap <leader>t <Plug>(go-def-vertical)
" vim-go }}}

vim version

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Nov 24 2016 16:44:48)
Included patches: 1-1689
Extra patches: 8.0.0056
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by pkg-vim-maintainers@lists.alioth.debian.org
Huge version without GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +tag_binary
+arabic          +file_in_path    +mouse_sgr       +tag_old_static
+autocmd         +find_in_path    -mouse_sysmouse  -tag_any_white
-balloon_eval    +float           +mouse_urxvt     +tcl
-browse          +folding         +mouse_xterm     +terminfo
++builtin_terms  -footer          +multi_byte      +termresponse
+byte_offset     +fork()          +multi_lang      +textobjects
+channel         +gettext         -mzscheme        +timers
+cindent         -hangul_input    +netbeans_intg   +title
-clientserver    +iconv           +packages        -toolbar
-clipboard       +insert_expand   +path_extra      +user_commands
+cmdline_compl   +job             +perl            +vertsplit
+cmdline_hist    +jumplist        +persistent_undo +virtualedit
+cmdline_info    +keymap          +postscript      +visual
+comments        +langmap         +printer         +visualextra
+conceal         +libcall         +profile         +viminfo
+cryptv          +linebreak       -python          +vreplace
+cscope          +lispindent      +python3         +wildignore
+cursorbind      +listcmds        +quickfix        +wildmenu
+cursorshape     +localmap        +reltime         +windows
+dialog_con      +lua             +rightleft       +writebackup
+diff            +menu            +ruby            -X11
+digraphs        +mksession       +scrollbind      -xfontset
-dnd             +modify_fname    +signs           -xim
-ebcdic          +mouse           +smartindent     -xsmp
+emacs_tags      -mouseshape      +startuptime     -xterm_clipboard
+eval            +mouse_dec       +statusline      -xterm_save
+ex_extra        +mouse_gpm       -sun_workshop    -xpm
+extra_search    -mouse_jsbterm   +syntax
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -Wdate-time  -g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E  -Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl  -L/usr/lib -llua5.2 -Wl,-E  -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/x86_64-linux-gnu/perl/5.22/CORE -lperl -ldl -lm -lpthread -lcrypt  -L/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu -lpython3.5m -lpthread -ldl -lutil -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lieee -lm -lruby-2.3 -lpthread -lgmp -ldl -lcrypt -lm

vim-go version

~/.vim/plugged/vim-go master user@computer
❯ git l
52c5b1f  (HEAD -> master, origin/master, origin/HEAD) fmt: fix backwards compatibility with getqflist (2 weeks ago) Fatih Arslan <ftharsln@gmail.com>

go version

~/.vim/plugged/vim-go master user@computer
❯ go version
go version go1.9 linux/amd64
weirdgiraffe commented 7 years ago

I've deduced the problem to a single line in vimrc - syntax enable. Without this line :GoCoverage works

arp242 commented 7 years ago

Now that the Go 1.9 has landed in the Arch packages I tested this with Go 1.9, and as far as I can see it works fine for me, either with my own vimrc or yours. These are the test files I used:

~/go/src/a/a.go:

package a

func tested() string {
        return "X"
}

func untested() string {
        return "X"
}

~/go/src/a/a_test.go:

package a

import "testing"

func TestTested(t *testing.T) {
        _ = tested()
}

I'm not sure why a Go 1.9 upgrade would break this, either. Maybe try using syntax on instead of syntax enable?

fatih commented 7 years ago

I've deduced the problem to a single line in vimrc - syntax enable. Without this line :GoCoverage works

I have Go 1.9 and syntax enable in my vimrc and it totally works. Can you please update to Vim 8.0 ? Vim 7.4.x is not up to date with latest bug fixes and we develop against the latest vim version.

weirdgiraffe commented 7 years ago

@fatih , it is an interesting case. With vim 8 and following config coverage works well:

set nocompatible
set backspace=indent,eol,start
set encoding=utf-8
nnoremap Q <Nop>
nnoremap gQ <Nop>
if empty(glob($HOME.'/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall | source $MYVIMRC
endif
call plug#begin($HOME.'/.vim/plugged')
Plug 'fatih/vim-go', {'for': 'go', 'do': ':GoInstallBinaries'}
call plug#end()
syntax enable

but if I enable syntax before vim-go plugin I'm getting the same error.

Error detected while processing function 2[2]..<SNR>39_coverage_callback[2]..go#coverage#overlay:
line   57:
E28: No such highlight group name: goCoverageNormalText

Looks like this issue is not about go1.9 but about the order of vim instructions in vimrc. I'm about to close this issue, should I create a new one about syntax enable ?

jsfaint commented 6 years ago

I have the same issue and it not happen all the time, on the same environment. That's weird. deepinscreenshot_select-area_20171123102826

jsfaint commented 6 years ago

Oh, I found the root cause.

Because I lazy loaded vim-go in vimrc After modify the vim-plug setting from

Plug 'fatih/vim-go', {'on': ['GoInstallBinaries', 'GoUpdateBinaries', 'GoPath'], 'for': 'go'}

to

Plug 'fatih/vim-go'

It works fine now. Sorry for the interruption.

arp242 commented 6 years ago

Oh, the problem with that is that Plug will load the plugin on an autocmd event (e.g. FileType), but vim-go also uses the same event, but by the time vim-go is loaded it has missed the events.

This is something vim-plug can improve on perhaps by manually firing the events again; don't know ... but in general, you don't want to use for: ... with filetype-specific plugins (such as vim-go).

akfaew commented 9 months ago

I am affected by this on the latest Ubuntu, when putting vim-go in ~/.vim/pack/plugins/start/vim-go (no explicit load command)