-
Notifications
You must be signed in to change notification settings - Fork 310
Servers Go
B.E edited this page Sep 28, 2022
·
30 revisions
Since January 2021 gopls is the official language server for Go.
To install it:
go install golang.org/x/tools/gopls@latestif executable('gopls')
au User lsp_setup call lsp#register_server({
\ 'name': 'gopls',
\ 'cmd': {server_info->['gopls', '-remote=auto']},
\ 'allowlist': ['go'],
\ })
autocmd BufWritePre *.go LspDocumentFormatSync
endifThe purpose of the -remote=auto option is to prevent launching the same server multiple times if it was already started by some other plugin, which will often be the case, since vim-go is widely used.
If you are also using vim-go, you need to disable the completion provided by it, which is enabled by default. Add this to your ~/.vimrc:
let g:go_code_completion_enabled = 1If you are a Plug user you may also register the gopls LSP server using:
Plug 'prabirshrestha/vim-lsp'
...
Plug 'piec/vim-lsp-gopls'