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

'await' function in autoload/go/promise.vim takes a lot of time while saving a file #3286

Closed
suhas-bn-1412 opened this issue Aug 22, 2021 · 5 comments

Comments

@suhas-bn-1412
Copy link

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

I have installed vim-go as a plugin for my vim. After I edit any go files, and save and quit vim, it takes very long time to close.

What did you expect to happen?

I expected it to close immediately

What happened instead?

It takes lot of time as long as 44 seconds to quit

This was the log printed in the vim profile I created. We can see that await functions runs for 17 seconds.

FUNCTION  <SNR>95_await()
    Defined: ~/.vim/plugged/vim-go/autoload/go/promise.vim:37
Called 2 times
Total time:  17.197947
 Self time:  17.194680

count  total (s)   self (s)
    2              0.000018   let l:timer = timer_start(a:timeout, function('s:setretval', [a:default], self))
  345              0.001395   while !has_key(self, 'retval')
  343  17.195654  17.192387     sleep 50m
  345              0.000717   endwhile
    2              0.000006   call timer_stop(l:timer)

    2              0.000004   if get(self, 'exception', 0)
                                throw self.retval
    2              0.000001   endif
    2              0.000003   return self.retval

How can I resolve this?

Configuration (MUST fill this out):

vim-go version: v1.25

vimrc you used to reproduce:

vimrc
" install vim-plug
if empty(glob('~/.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 --sync | source ~/.vimrc
endif

"------------------------------------------------------------------------------
" Plug installed plugins

call plug#begin('~/.vim/plugged')

" Golang syntax highlighting, auto completions
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }

" NERDtree for file browsing
Plug 'preservim/nerdtree'

" CtrlP for fuzzy file search
Plug 'ctrlpvim/ctrlp.vim'

" Botton line (vim status bar)
Plug 'itchyny/lightline.vim'

" Vim-fugitive for git workflow
Plug 'tpope/vim-fugitive'

" Color scheme
Plug 'gryf/wombat256grf'

call plug#end()
"------------------------------------------------------------------------------

" Turn on syntax highlighting
syntax on

" Backapce should work over everything
set backspace=indent,eol,start

" Show line numbers
set number

" tab uses this many spaces
set tabstop=8

" Status bar
set laststatus=2

" Last line
set showmode
set showcmd

" colorscheme
colorscheme wombat256grf
"colorscheme monokai

" Any vertical splits to happen on right
set splitright

" Any horizontal splits to happen at bottom
set splitbelow


" Enable to copy to clipboard for operations like yank, delete, change and put
" http://stackoverflow.com/questions/20186975/vim-mac-how-to-copy-to-clipboard-without-pbcopy
if has('unnamedplus')
  set clipboard^=unnamed
  set clipboard^=unnamedplus
endif

" This enables us to undo files even if you exit Vim.
if has('persistent_undo')
  set undofile
  set undodir=~/.config/vim/tmp/undo//
endif

" Turn on highlighting for searched string
set hls

" Set output encoding shown in terminal  to utf-8 ()
set encoding=utf-8

" Set file encoding to utf-8
set fileencoding=utf-8


"------------------------------------------------------------------------------
" User defined commands
"
" Command to see the changes done in current session
" template: coomand <desired_alias> <vim_command>
command Diff w !diff % -    " Show changes that are not written yet
"------------------------------------------------------------------------------


"------------------------------------------------------------------------------
" NERDtree
nnoremap <F1> :NERDTreeToggle<CR>
nnoremap <F2> :NERDTree<CR>
let g:NERDTreeDirArrowExpandable = '>'
let g:NERDTreeDirArrowCollapsible = '^'
"------------------------------------------------------------------------------



"------------------------------------------------------------------------------
" lightline -> status bar
if !has('gui_running')
          set t_Co=256
endif
let g:lightline = {
      \ 'colorscheme': 'wombat',
      \ 'active': {
      \   'left': [ [ 'mode', 'paste' ],
      \             [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
      \ },
      \ 'component_function': {
      \   'gitbranch': 'FugitiveHead'
      \ },
      \ }
"------------------------------------------------------------------------------



"------------------------------------------------------------------------------
" gopls
let g:go_def_mode='godef'
let g:go_info_mode='gopls'
" vim slows down because of vim-go
let g:go_debug=['shell-commands']
"------------------------------------------------------------------------------



"------------------------------------------------------------------------------
" Solve any issues caused by plugins
"
"
" Vim taking time to load
" https://stackoverflow.com/questions/14635295/vim-takes-a-very-long-time-to-start-up
set clipboard=exclude:.*
"------------------------------------------------------------------------------

Vim version (first three lines from :version):

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Mar 8 2021 09:58:42)

Go version (go version):

go version go1.13.7 linux/amd64

Go environment

go env Output:
GO111MODULE=""
GOARCH="amd64"
GOBIN="/home/snataraj/go//bin/"
GOCACHE="/home/snataraj/.cache/go-build"
GOENV="/home/snataraj/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/snataraj/go/"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/net/wtl-netapp-2/vol/VIEW/swbuild_snap_view/vobs/fw-tools/gitrepos_data/golang_master_1/golang-1.13.7"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/net/wtl-netapp-2/vol/VIEW/swbuild_snap_view/vobs/fw-tools/gitrepos_data/golang_master_1/golang-1.13.7/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
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-build641193532=/tmp/go-build -gno-record-gcc-switches"

gopls version

gopls version Output:
golang.org/x/tools/gopls v0.6.11
    golang.org/x/tools/gopls@v0.6.11 h1:7S2k0xuVYc3secjy2uz0n+fGYxGJU6gXsLOmQ/r1HoI=
@bhcleek
Copy link
Collaborator

bhcleek commented Aug 22, 2021

How large is your GOPATH? Is it always slow, or only when you save shortly after starting up Vim?

@bhcleek
Copy link
Collaborator

bhcleek commented Aug 22, 2021

FWIW, I suspect this is due to vim-go waiting on gopls to complete some operations. You may want to follow golang/go#45363.

Until that issue is fully resolved, there are a few things you can do to workaround this problem or at least improve the experience if I'm right about gopls being the culprit:

  1. update gopls using :GoUpdateBinaries gopls. There have been a number of performance improvements since the version you're currently using.
  2. consider using gofmt or goimports instead of gopls for g:go_fmt_command.
  3. As an alternative to using 2., turn off automatic formatting and import adjustment w/ let g:go_fmt_autosave=0 and let g:go_imports_autosave=0.
  4. As another alternative to 2. and 3., save and quit using :noautocmd wq (see :help :noautocmd).

@suhas-bn-1412
Copy link
Author

suhas-bn-1412 commented Aug 23, 2021

Using 'goimports' for go_fmt_command worked.

So what do I miss if my go_fmt_command is goimports instead of gopls?

@bhcleek
Copy link
Collaborator

bhcleek commented Aug 23, 2021

The implementation when using gofmt or goimports is a bit clunkier, and you'll notice problems if you use folds.

@bhcleek bhcleek closed this as completed Aug 28, 2021
@namelessnotion
Copy link

I had this issue and performing the update :GoUpdateBinaries gopls fixed the slow time while saving.

Repository owner deleted a comment from dicklejuicw12 Nov 24, 2023
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

3 participants