fatih / vim-go

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

go-build open quickfix in a new buffer #3049

Closed ianzhang366 closed 4 years ago

ianzhang366 commented 4 years ago

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

Recently, I'm seeing the :GoBuild command is somehow open the quickfix window in a new buffer.

What did you expect to happen?

What I did was, first add some random line in the go file, then do <leader>b

It will open the quickfix with error info at the bottom of the current window/buffer, which is expected.

image

image

Then enter some changes or move curse around at the line of the error, these actions somehow will open the quick fix in a window

image

What happened instead?

I'm running, vim-go, coc and tmux on itemr2.

Configuration (MUST fill this out):

vim-go version:

vimrc you used to reproduce:

vimrc
" set up where to hight
let g:go_highlight_types = 1
let g:go_highlight_fields = 1

let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1

let g:go_list_type = "quickfix"

let g:go_fmt_experimental = 1
let g:go_fmt_fail_silently = 1 " this error is only gofmt error...not compile
let g:go_fmt_command = 'goimports' " vim-go

let g:go_gopls_enabled= 0
let g:go_def_mapping_enabled = 0

let g:go_auto_type_info = 0 " vim-go
let g:go_addtags_transform = "camelcase"

" GoMetaLinter settings
let g:go_metalinter_autosave = 0
let g:go_metalinter_command = "golangci-lint run -c /Users/ianzhang/.config/nvim/golangci.yml"

" set up the sign
let g:ale_sign_warning = '⚠'

nnoremap fc :GoDecls

" shortcut for the quickfix
map  :cnext
map  :cprevious

" shortcut for GoBuild and run
autocmd FileType go nmap n  (go-debug-next)
autocmd FileType go nmap c (go-coverage-toggle)
autocmd FileType go nmap b (go-build) 

" set up tab as other editor
autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4 
autocmd BufWritePre *.go :call CocAction('runCommand', 'editor.action.organizeImport')

Vim version (first three lines from :version):

NVIM v0.4.4 Build type: Release LuaJIT 2.0.5

Go version (go version):

go version go1.15 darwin/amd64

Go environment

go env Output:

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="$HOME/Library/Caches/go-build"
GOENV="$HOME/Library/Application Support/go/env"
GOEXE=""
GOFLAGS="-ldflags=-compressdwarf=false"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="$HOME/Documents/learngo/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="$HOME/Documents/learngo"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.15/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.15/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="$HOME/Documents/learngo/src/github.com/open-cluster-management/multicloud-operators-subscription/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/9n/tmq2936s5y349yc4222n49tc0000gn/T/go-build602657876=/tmp/go-build -gno-record-gcc-switches -fno-common"

gopls version

gopls version Output:

golang.org/x/tools/gopls v0.5.1
    golang.org/x/tools/gopls@v0.5.1 h1:AF3Uh7HF08SZpKFfgJO6zfF3bbxyDXWqdkK4kMXiQ1o=

vim-go configuration:

vim-go configuration
g:go_auto_type_info = 0
g:go_fmt_fail_silently = 1
g:go_list_type = 'quickfix'
g:go_highlight_function_calls = 1
g:go_highlight_fields = 1
g:go_gopls_enabled = 0
g:go_metalinter_command = 'golangci-lint run -c /Users/ianzhang/.config/nvim/golangci.yml'
g:go_def_mapping_enabled = 0
g:go_addtags_transform = 'camelcase'
g:go_highlight_functions = 1
g:go_metalinter_autosave = 0
g:go_highlight_types = 1
g:go_fmt_command = 'goimports'
g:go_jump_to_error = 1
g:go_fmt_experimental = 1
g:go_loaded_gosnippets = 1
g:go_loaded_install = 1

filetype detection configuration:

filetype detection
filetype detection:ON  plugin:ON  indent:ON
bhcleek commented 4 years ago

I've seen this once before, but we never got to the bottom of it.

Is the vimrc file you provided the full vimrc, or have you elided portions?

If we want to figure out what's going on here, can you please try duplicating this issue with as minimal vimrc file as possible and without any Vim plugins other than vim-go?

ianzhang366 commented 4 years ago

Hi, @bhcleek thanks for your reply.

Here's the full vimrc

"""""plugins""""""""
call plug#begin('~/.vim/plugged')
"color 
Plug 'gruvbox-community/gruvbox'

Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'tpope/vim-fugitive'

Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'mbbill/undotree'

" Zoom in and out of a specific split pane (similar to tmux).
Plug 'dhruvasagar/vim-zoom'

" search select word in google
Plug 'szw/vim-g'

" Automatically show Vim's complete menu while typing.
" Plug 'vim-scripts/AutoComplPop'

"IDE
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }

call plug#end()
""""end of plugins"""""""

syntax on

set nocompatible
set shell=/bin/zsh

set encoding=utf-8
set termguicolors
set guicursor= "i:blinkwait700-blinkon400-blinkoff250

set noerrorbells
" Use spaces instead of tabs
set tabstop=4 softtabstop=4
set shiftwidth=4
set expandtab
set smartindent

set nu
set relativenumber

" " When searching try to be smart about cases 
set noswapfile

set nobackup
set undodir=~/.vim/undodir
set undofile
"  Makes search act like search in modern browsers
"set smartcase
set ignorecase
set incsearch 
" " Highlight search results
set hlsearch
" Show matching brackets when text indicator is over them
set showmatch 

" set up column ruler
set colorcolumn=80
highlight ColorColumn ctermbg=0 guibg=lightgrey

" set up spell check
set spell
set spelllang=en_us

"" switch to the open buffer directory
set autochdir
set autoread
set autowrite

" handle folding

" " Be smart when using tabs ;)
set completeopt=menuone,noinsert,noselect

set list lcs=trail:-,tab:\|\ ,space:·

set laststatus=2

set textwidth=80

set wildmode=full
"make sure the quickfix window highlight is not too messy
hi QuickFixLine cterm=None ctermbg=256 guibg=#ffff00

""""key mapping""""j
let mapleader = ","
nmap <leader>w :w!<cr>

map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
"""end of key mapping""""
" use default explore
let g:netrw_banner=0 "disable Explore banner
nnoremap <leader>e :Ex<CR>

"""resize window"""
nnoremap <S-Up> <C-w>+
nnoremap <S-Down> <C-w>-
nnoremap <S-Right> <C-w>>
nnoremap <S-Left> <C-w><

" -----------------------------------------------------------------------------
" Basic autocommands
" -----------------------------------------------------------------------------

" Update a buffer's contents on focus if it changed outside of Vim.
au FocusGained,BufEnter,CursorHold * :checktime

" Press * to search for the term under the cursor or a visual selection and
" then press a key below to replace all instances of it in the current file.
nnoremap <Leader>r :%s///g<Left><Left>
nnoremap <Leader>rc :%s///gc<Left><Left><Left>

" The same as above but instead of acting on the whole file it will be
" restricted to the previously visually selected range. You can do that by
" pressing *, visually selecting the range you want it to apply to and then
" press a key below to replace all instances of it in the current selection.
xnoremap <Leader>r :s///g<Left><Left>
xnoremap <Leader>rc :s///gc<Left><Left><Left>

" Type a replacement term and press . to repeat the replacement again. Useful
" for replacing a few instances of the term (comparable to multiple cursors).
nnoremap <silent> s* :let @/='\<'.expand('<cword>').'\>'<CR>cgn
xnoremap <silent> s* "sy:let @/=@s<CR>cgn

" Clear search highlights.
nnoremap <leader><space> :let @/=''<CR>

"""""""""""""""""""python"""""""""""""""""""
autocmd BufNewFile,BufRead *.py set noexpandtab tabstop=4 shiftwidth=4 

""""""""""""""""""end of python""""""""""""""""""

"editor color
let g:gruvbox_contrast_dark = 'hard'
if exists('+termguicolors')
    let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
    let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
let g:gruvbox_invert_selection='0'

colorscheme gruvbox
set background=dark "set light mode of colorscheme

""""""""""""""""""""""""""""""
" => Status line
" """"""""""""""""""""""""""""""
" " Always show the status line
"" Format the status line

""""""airline""""""""
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#show_buffers = 0  " do not show open
let g:airline#extensions#tabline#formatter = 'short_path'
let g:airline#extensions#tabline#tab_nr_type = 1
let g:airline#extensions#tabline#show_splits = 0
let g:airline_detect_spelllang = 0
let g:airline_detect_spell = 0
let g:airline_theme='badwolf'
""""""end of airline""""

"""vim-fugitive"""""
nmap <leader>gh :diffget //3<CR>
nmap <leader>gl :diffget //2<CR>
nmap <leader>gs :Gstatus<CR>
"""end vim-fugitive"""""

"""""""""""""fzf"""""""""""""""""
let $FZF_DEFAULT_OPTS='--reverse'
let g:fzf_layout = { 'window': { 'width': 0.8, 'height': 0.8 } }

" Always enable preview window on the right with 60% width
let g:fzf_preview_window = 'right:62%'

" Customize fzf colors to match your color scheme.
let g:fzf_colors =
\ { 'fg':      ['fg', 'Normal'],
  \ 'bg':      ['bg', 'Normal'],
  \ 'hl':      ['fg', 'Comment'],
  \ 'fg+':     ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
  \ 'bg+':     ['bg', 'CursorLine', 'CursorColumn'],
  \ 'hl+':     ['fg', 'Statement'],
  \ 'info':    ['fg', 'PreProc'],
  \ 'prompt':  ['fg', 'Conditional'],
  \ 'pointer': ['fg', 'Exception'],
  \ 'marker':  ['fg', 'Keyword'],
  \ 'spinner': ['fg', 'Label'],
  \ 'header':  ['fg', 'Comment'] }

let g:fzf_action = {
  \ 'ctrl-t': 'tab split',
  \ 'ctrl-b': 'split',
  \ 'ctrl-v': 'vsplit',
  \ 'ctrl-y': {lines -> setreg('*', join(lines, "\n"))}}

nnoremap \ :Rg<CR>
nnoremap <leader>cs :CocSearch<space>
nnoremap <C-T> :Files<cr>
nnoremap <C-F> :GFiles<CR>
nnoremap <leader>p :pwd<CR>

" Allow passing optional flags into the Rg command.
function! RipgrepFzf(query, fullscreen)
  let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case -- %s || true'
  let initial_command = printf(command_fmt, shellescape(a:query))
  let reload_command = printf(command_fmt, '{q}')
  let spec = {'options': ['--phony', '--preview-window', down:40, '--query', a:query, '--bind', 'change:reload:'.reload_command]}
  call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen)
endfunction

command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0)

"""""end of fzf""""""

"""""""""" set up the vim-go
" set up where to hight
let g:go_highlight_types = 1
let g:go_highlight_fields = 1

let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1

let g:go_fmt_experimental = 1
let g:go_fmt_fail_silently = 1 " this error is only gofmt error...not compile
let g:go_fmt_command = 'goimports' " vim-go

let g:go_gopls_enabled= 0
let g:go_def_mapping_enabled = 0

let g:go_auto_type_info = 0 " vim-go
let g:go_list_type = "quickfix"
let g:go_addtags_transform = "camelcase"

" GoMetaLinter settings
let g:go_metalinter_autosave = 0
let g:go_metalinter_command = "golangci-lint run -c /Users/ianzhang/.config/nvim/golangci.yml"

" set up the sign
let g:ale_sign_warning = '⚠'

nnoremap <leader>fc :GoDecls<CR>

" shortcut for the quickfix
map <C-n> :cnext<CR>
map <C-m> :cprevious<CR>

" shortcut for GoBuild and run
autocmd FileType go nmap <leader>n  <Plug>(go-debug-next)
autocmd FileType go nmap <Leader>c <Plug>(go-coverage-toggle)

" set up tab as other editor
autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4 
autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR>
autocmd BufWritePre *.go :call CocAction('runCommand', 'editor.action.organizeImport')

" 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 <leader>b :<C-u>call <SID>build_go_files()<CR>

"""""end of vim-go lange"""""

"""""undotree"""""""
nnoremap <leader>u :UndotreeShow<CR>
""""end of undotree""""""""

"""""for markdown set up"""""
au BufNewFile,BufFilePre,BufRead *.md set filetype=markdown
let g:vim_markdown_folding_disabled = 1

""""""end of markdown""""""

"""""""""""coc.vim set up"""""""""""
let g:coc_global_extensions = [
  \ 'coc-snippets',
  \ 'coc-pairs',
  \ 'coc-prettier', 
  \ 'coc-json', 
  \ 'coc-yank',
  \ 'coc-yaml',
  \ 'coc-python',
  \ 'coc-dictionary',
  \ 'coc-git'
  \ ]
" TextEdit might fail if hidden is not set.
set hidden

" Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup

" Give more space for displaying messages.
set cmdheight=2

" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=30

" Don't pass messages to |ins-completion-menu|.
set shortmess+=c

" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("patch-8.1.1564")
  " Recently vim can merge signcolumn and number column into one
  set signcolumn=number
else
  set signcolumn=yes
endif

" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction

" Use <c-space> to trigger completion.
if has('nvim')
  inoremap <silent><expr> <c-space> coc#refresh()
else
  inoremap <silent><expr> <c-@> coc#refresh()
endif

" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current
" position. Coc only does snippet and additional edit on confirm.
" <cr> could be remapped by other vim plugin, try `:verbose imap <CR>`.
if exists('*complete_info')
  inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
else
  inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
endif

" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)

" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>

function! s:show_documentation()
  if (index(['vim','help'], &filetype) >= 0)
    execute 'h '.expand('<cword>')
  else
    call CocActionAsync('doHover')
  endif
endfunction

" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')

" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)

" Formatting selected code.
xmap <leader>f  <Plug>(coc-format-selected)
nmap <leader>f  <Plug>(coc-format-selected)

augroup mygroup
  autocmd!
  " Setup formatexpr specified filetype(s).
  autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  " Update signature help on jump placeholder.
  autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end

" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a  <Plug>(coc-codeaction-selected)
nmap <leader>a  <Plug>(coc-codeaction-selected)

" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac  <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf  <Plug>(coc-fix-current)

" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)

" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of language server.
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)

" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')

" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call     CocAction('fold', <f-args>)

" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR   :call     CocAction('runCommand', 'editor.action.organizeImport')

" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}

" Mappings for CoCList
" Show all diagnostics.
nnoremap <silent><nowait> <space>a  :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent><nowait> <space>e  :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>c  :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>o  :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>s  :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent><nowait> <space>j  :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent><nowait> <space>k  :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent><nowait> <space>p  :<C-u>CocListResume<CR>
""""""""""""end of coc.vim""""""""""""

I also went to minimal vimrc only with vim-go, I wasn't able to reproduce the issue.

Then I started adding plugins back one by one till the above settings, I'm still not able to reproduce the issue as well.

The only different thing might relate to this, I can remember of was the most recent macOS big Sur beta update. Right after the update, the issue showed up. Before the update, everything worked fine with the above vimrc.

If you need more input please let me know.

If I see this again, I will do the same thing and get back to you.]

Again thanks for your time and effortt

bhcleek commented 4 years ago

Since you can't duplicate this now, how do you feel about closing this?

ianzhang366 commented 4 years ago

sure, let's close this one, if it happens again, I will reopen