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

gopls stuck #2603

Closed
jockech opened this issue Nov 27, 2019 · 43 comments
Closed

gopls stuck #2603

jockech opened this issue Nov 27, 2019 · 43 comments

Comments

@jockech
Copy link

jockech commented Nov 27, 2019

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

I want to use vim-go to code sth like fmt.Println("hello world"). Once I type ., the bottom says vim-go: initialized gopls and then it stuck forever.

What did you expect to happen?

What happened instead?

Configuration (MUST fill this out):

vim-go version:

v1.21

vimrc you used to reproduce (use a minimal vimrc with other plugins disabled; do not link to a 2,000 line vimrc):

vimrc
call plug#begin()
Plug 'cappyzawa/starlark.vim'
Plug 'fatih/vim-go'
" Support for nova color scheme.
Plug 'trevordmiller/nova-vim'
" Automatically adds closing parentheses, quotes, etc.
Plug 'jiangmiao/auto-pairs'
call plug#end()

" Search down into subfolders.
" Provides auto-completion for all file-related tasks.
set path+=**

" Display all matching files when we tab complete.
set wildmenu

"""GO SETTINGS_"""

" Save file automatically when running GoBuild (and more generally, :make).
set autowrite

" Only use quickfix menu, not location list.
let g:go_list_type = "quickfix"

" Map go-build and go-test to easy to type shortcuts.
autocmd FileType go nmap t (go-test)
autocmd FileType go nmap b (go-build)

" Shortcut for GoAlternate.
autocmd Filetype go command! -bang A call go#alternate#Switch(0, 'edit')

" Automatically display GoInfo.
let g:go_auto_type_info = 1
" Automatically highlight all instances of a variable.
let g:go_auto_sameids = 1

" Run go-fmt on save.
let g:go_fmt_autosave = 1

" ==== COLORS ====

set background=light
syntax on
colorscheme nova
let g:nova_transparent = 1

" ==== MISC ====

" Enables loading plugin files for specific file types.
filetype plugin on

" Display line numbers in gutter.
set number

" Display the full file path
set laststatus=2

" Enable mouse.
set mouse=a

" Highlight all search pattern matches.
set hlsearch

" Don’t update screen during macro and script execution.
set lazyredraw

" Wrap long lines to fit in the window.
set wrap
" Don't linebreak in the middle of a word.
set linebreak
" Don't know what this one does.
set nolist

" ==== CURSOR ====

" Highlight cursor line.
set cursorline

" Display line / column number of cursor.
set ruler

" ==== TABS ====

" Defaults.
set autoindent
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab

filetype plugin indent on

" 4 spaces.
au FileType python setlocal ts=4 sts=4 sw=4 et
au FileType javascript setlocal ts=4 sts=4 sw=4 et

" 2 spaces.
au FileType html setlocal ts=2 sts=2 sw=2 et
au FileType yaml setlocal ts=2 sts=2 sw=2 et
au FileType bash setlocal ts=2 sts=2 sw=2 et

" ==== COMPLETION ====

let g:deoplete#enable_at_startup = 1

" Completion window in insert mode.
set completeopt-=preview

" Smart tab completion. See https://vim.fandom.com/wiki/Smart_mapping_for_tab_completion.
function! Smart_TabComplete()
let line = getline('.') " current line

let substr = strpart(line, -1, col('.')+1) " from the start of the current
" line to one character right
" of the cursor
let substr = matchstr(substr, "[^ \t]*$") " word till cursor
if (strlen(substr)==0) " nothing to match on empty string
return "<tab>"
endif
let has_period = match(substr, '.') != -1 " position of period, if any
let has_slash = match(substr, '/') != -1 " position of slash, if any
if (!has_period && !has_slash)
return "<C-X><C-P>" " existing text matching
elseif ( has_slash )
return "<C-X><C-F>" " file matching
else
return "<C-X><C-O>" " plugin matching
endif
endfunction

inoremap =Smart_TabComplete()

" ==== GO ====

" Speed up vim-go. No need to highlight everything.
let g:go_highlight_build_constraints = 0
let g:go_highlight_extra_types = 0
let g:go_highlight_fields = 0
let g:go_highlight_functions = 0
let g:go_highlight_methods = 0
let g:go_highlight_operators = 0
let g:go_highlight_structs = 0
let g:go_highlight_types = 0

" ==== MACROS ====

set backspace=indent,eol,start

let mapleader=","

" Previous buffer.
nnoremap l :e #

" Search and replace hovered word.
nnoremap s :.,$s/<>//gc

" Search and replace highlighted text.
xnoremap s y:.,$s/"//gc

" Unhighlight.
nnoremap n :noh

" For shitty typists.
nmap ; :

" Keep search results centered.
nnoremap n nzz
nnoremap N Nzz

" Go macros.
au FileType go nmap i :GoImports
au FileType go nmap f :GoFmt
au FileType go nmap b :GoBuild
au FileType go nmap d :GoDef
au FileType go nmap e :GoTest

" Zooms current window. Exit it with :wq
nnoremap z :tabnew %

" Don't use monorepo Go wrapper.
let $USE_SYSTEM_GO=1

Vim version (first three lines from :version):

VIM - Vi IMproved 8.1 (2018 May 18, compiled Oct 15 2019 10:12:50)
macOS version
Included patches: 1-2150

Go version (go version):

go version go1.13 darwin/amd64

Go environment

go env Output:
```
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xiaoweic/Library/Caches/go-build"
GOENV="/Users/xiaoweic/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/xiaoweic/go-code"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13/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/sd/xjjfgwh54vz073j9r_2260kr0000gn/T/go-build630995246=/tmp/go-build -gno-record-gcc-switches -fno-common"
```
@bhcleek
Copy link
Collaborator

bhcleek commented Nov 27, 2019

What do you mean by "it stuck forever"? What behavior are you actually seeing?

@jockech
Copy link
Author

jockech commented Nov 27, 2019

What do you mean by "it stuck forever"? What behavior are you actually seeing?
It just shows initialize gopls and I can't operate on vim anymore.

@bhcleek
Copy link
Collaborator

bhcleek commented Nov 27, 2019

What version of gopls are you using? You can tell with gopls version.

@jockech
Copy link
Author

jockech commented Dec 2, 2019

golang.org/x/tools/gopls 0.2.0
golang.org/x/tools/gopls@v0.2.1 h1:qXHEqJw4CqROYvoDXinY1ZOkyAFS+jcPOvLRK76dvwY=

@bhcleek
Copy link
Collaborator

bhcleek commented Dec 3, 2019

🤔 That should work fine. Can you try clearing your cache using go clean -cache?

@yuankang
Copy link

I had the same problem.

@mehranz
Copy link

mehranz commented Dec 10, 2019

I had same thing too. it was working properly until hours ago but now I don't know what happened!!

@skalle
Copy link

skalle commented Dec 12, 2019

This is happening to me too, it's stuck forever at:

vim-go: initializing gopls

go clean -cache did not help.

Only way I've found to edit Go files atm is:

let g:go_gopls_enabled = 0

@skalle
Copy link

skalle commented Dec 13, 2019

Turns out the Go environment was modified for the project I was in , :GoInstallBinaries inside of that env. made things working again.

@bhcleek
Copy link
Collaborator

bhcleek commented Dec 13, 2019

The gopls output would be useful for me to figure out what's happening. Please add let g:go_debug=['lsp'] to your vimrc and paste the contents of the __GOLSP_LOG__ window. Hopefully that will shed some light on things.

@mehranz
Copy link

mehranz commented Dec 14, 2019

It's just fixed by installing gopls by my Os's package manager. I'm running on fedora and I installed gopls by this command:
sudo dnf install golang-x-tools-gopls
and now everything works perfectly!

@wangjian-pg
Copy link

I worked on macOs Catalina and had the same problem.

@bhcleek
Copy link
Collaborator

bhcleek commented Dec 19, 2019

@XavierCheng1996 are you able to provide the gopls output I asked for last week (#2603 (comment))?

@ta3pks
Copy link

ta3pks commented Dec 20, 2019

I have the same situation

@jockech
Copy link
Author

jockech commented Dec 20, 2019

@XavierCheng1996 are you able to provide the gopls output I asked for last week (#2603 (comment))?

sorry for late response. I have updated my vimrc and now it works.

@bhcleek
Copy link
Collaborator

bhcleek commented Dec 20, 2019

How did you update your vimrc? FWIW, I would not expect adding let g:go_debug=['lsp'] to affect this error. If it did, then the problem isn't really solved. If you did something else, then I and others would be interested to know what you did.

@jockech
Copy link
Author

jockech commented Dec 21, 2019

How did you update your vimrc? FWIW, I would not expect adding let g:go_debug=['lsp'] to affect this error. If it did, then the problem isn't really solved. If you did something else, then I and others would be interested to know what you did.

I have updated it in the above post. meanwhile, I encounter another error like

Error detected while processing function go#referrers#Referrers:
line    6:
E117: Unknown function: go#config#GoplsEnabled

@bhcleek
Copy link
Collaborator

bhcleek commented Dec 21, 2019

I get "Unknown function: go#config#..." error when I open a Go file.~
explains the error you're seeing now.

@jockech
Copy link
Author

jockech commented Dec 23, 2019

I get "Unknown function: go#config#..." error when I open a Go file.~

explains the error you're seeing now.

I'm trying to use GoReferrers for a function

@bhcleek
Copy link
Collaborator

bhcleek commented Dec 23, 2019

I understand. Did you review the section of the FAQ that I linked?

@jockech
Copy link
Author

jockech commented Dec 23, 2019

I understand. Did you review the section of the FAQ that I linked?

Sorry, where is the link 😄

@bhcleek
Copy link
Collaborator

bhcleek commented Dec 23, 2019

In #2603 (comment)

@bhcleek
Copy link
Collaborator

bhcleek commented Dec 23, 2019

@XavierCheng1996 the section of the FAQ I linked implies that it's only relevant to opening a file. The solution, though, will apply to your case, too.

@jockech
Copy link
Author

jockech commented Dec 23, 2019

@XavierCheng1996 the section of the FAQ I linked implies that it's only relevant to opening a file. The solution, though, will apply to your case, too.

thanks, looking👀

@jockech
Copy link
Author

jockech commented Dec 23, 2019

I have checked the faq and I haven't used vim-polyglot and it just says

E117: Unknown function: go#config#GoplsEnabled

@bhcleek
Copy link
Collaborator

bhcleek commented Dec 23, 2019

Then you likely have multiple versions of vim-go installed. Can you run :verbose function go#config#FmtAutosave? It will tell you where the function named go#config#FmtAutosave was last set from. That should be within path to vim-go on your machine. Where does it say it was set from? And where do you have vim-go installed to?

Also, I just noticed that your new error shouldn't happen at all from v1.21, because the go#config#GoplsEnabled function did not exist and there were no calls to it in v1.21. Have you updated vim-go since you created this issue?

@jockech
Copy link
Author

jockech commented Dec 23, 2019

run :verbose function go#config#FmtAutosave . and the output is

  function go#config#FmtAutosave() abort
        Last set from ~/.vim/pack/plugins/start/vim-go/autoload/go/config.vim line 305
1      return get(g:, "go_fmt_autosave", 1)
   endfunction

I think I pull the lates version to /Users/[username]/.vim/bundle/vim-go and have created the issue. so it looks like it's the compatibility issue between guru and vim-go?

@jockech
Copy link
Author

jockech commented Dec 23, 2019

Meanwhile if I use the GoCallers the error will be like

vim-go: [callees] FAIL
vim-go: /Users/username/gocode/pkg/mod/github.com/stretchr/testify@v1.2.2/require/require.go:9:9: co
uld not import github.com/stretchr/testify/assert (cannot find package "github.com/stretchr/testify/
assert" in any of:
vim-go:         /usr/local/Cellar/go/1.13.4/libexec/src/github.com/stretchr/testify/assert (from $GO
ROOT)
vim-go:         /Users/username/gocode/src/github.com/stretchr/testify/assert (from $GOPATH))
vim-go: guru: couldn't load packages due to errors: github.com/stretchr/testify/require

and I have already run go build ...

@bhcleek
Copy link
Collaborator

bhcleek commented Dec 23, 2019

If you've installed vim-go to /Users/[username]/.vim/bundle/vim-go and are seeing Last set from ~/.vim/pack/plugins/start/vim-go/autoload/go/config.vim from :verbose function go#config#FmtAutosave, then that means that you have two versions of vim-go installed, and vim is only loading the one in ~/.vim/pack/plugins/start/vim-go.

Make sure to clear out any copies of vim-go that you don't want to use before continuing further.

This is not a compatibility problem between guru and vim-go as far as I can tell.

@jockech
Copy link
Author

jockech commented Dec 26, 2019

Ic thanks~

@jockech
Copy link
Author

jockech commented Dec 26, 2019

I have deleted the one under bundle but still sees the error Last set from ~/.vim/pack/plugins/start/vim-go/autoload/go/config.vim here.

@bhcleek
Copy link
Collaborator

bhcleek commented Dec 27, 2019

You've deleted the copy under bundle and you are still seeing

Error detected while processing function go#referrers#Referrers:
line    6:
E117: Unknown function: go#config#GoplsEnabled

?

Do you still have Plug 'fatih/vim-go' in your vimrc? If so, then it's going to reinstall vim-go under bundle again, and you'll be back to where you were before you deleted the copy under bundle.

You'll need to decide whether you want to use Plug to manage vim-go or whether you want to use Vim's package management and make the necessary modifications to your system to avoid having multiple copies of vim-go present.

@jockech
Copy link
Author

jockech commented Jan 2, 2020

I see. thanks for your help!

@jockech jockech closed this as completed Jan 2, 2020
@cuihaikuo
Copy link

Have you solved this problem?

@bartenbach
Copy link

Did anyone ever fix this problem? I don't see where a solution was ever identified for this problem.

@Jinof
Copy link

Jinof commented Apr 13, 2020

Did anyone ever fix this problem? I don't see where a solution was ever identified for this problem.

Maybe you can install gopls yourself.
go get golang.org/x/tools/gopls@latest
It works for me.

@bartenbach
Copy link

@Jinof Thanks, it does load now correctly.

@Vanclief
Copy link

Having same issue, attempted both go clean -cache and go get golang.org/x/tools/gopls@latest. This issue started happening after updating from go 1.12 to 1.14.

@mayankshah1607
Copy link

Hello! I'm facing a very similar issue. gopls is stuck for a while, after which vim becomes very unresponsive even though gopls is no longer consuming resources

@vijaysy
Copy link

vijaysy commented Jul 1, 2020

Hello!
export GO111MODULE=on
go get golang.org/x/tools/gopls@latest
Worked with this.
FYI
go version go1.14.4 darwin/amd64

@MartinezCatriel
Copy link

go get golang.org/x/tools/gopls@latest

This worked fine for me.
I'm using vim-go.

@CadeMichael
Copy link

I was having the same issue but removed gopls installed by vim-go and reinstalled from my package manager and it worked.

@jbpadgett
Copy link

I'm using ASDF to manage Go versions on a Mac and when I updated from Go 1.18 to 1.19 for a project this happened to me. The solution was to do this from within VIM:
:GoUpdateBinaries

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