1
0
mirror of https://github.com/golang/go synced 2024-11-05 17:36:15 -07:00
go/gopls/doc/vim.md
Ellison Leão cd5a53e07f gopls/docs: adding nvim-lsp option in gopls README file
Change-Id: Ic44210e227559c8e1cd5cf1350cde69e2817f5e3
GitHub-Last-Rev: c020218392160d03a9448eda62e098fe0c91a063
GitHub-Pull-Request: golang/tools#221
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227442
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-07 19:18:07 +00:00

3.2 KiB

Vim / Neovim

vim-go

Use vim-go ver 1.20+, with the following configuration:

let g:go_def_mode='gopls'
let g:go_info_mode='gopls'

LanguageClient-neovim

Use LanguageClient-neovim, with the following configuration:

" Launch gopls when Go files are in use
let g:LanguageClient_serverCommands = {
       \ 'go': ['gopls']
       \ }
" Run gofmt on save
autocmd BufWritePre *.go :call LanguageClient#textDocument_formatting_sync()

Ale

Use ale:

let g:ale_linters = {
	\ 'go': ['gopls'],
	\}

see this issue

vim-lsp

Use prabirshrestha/vim-lsp, with the following configuration:

augroup LspGo
  au!
  autocmd User lsp_setup call lsp#register_server({
      \ 'name': 'go-lang',
      \ 'cmd': {server_info->['gopls']},
      \ 'whitelist': ['go'],
      \ })
  autocmd FileType go setlocal omnifunc=lsp#complete
  "autocmd FileType go nmap <buffer> gd <plug>(lsp-definition)
  "autocmd FileType go nmap <buffer> ,n <plug>(lsp-next-error)
  "autocmd FileType go nmap <buffer> ,p <plug>(lsp-previous-error)
augroup END

vim-lsc

Use natebosch/vim-lsc, with the following configuration:

let g:lsc_server_commands = {
\  "go": {
\    "command": "gopls serve",
\    "log_level": -1,
\    "suppress_stderr": v:true,
\  },
\}

The log_level and suppress_stderr parts are needed to prevent breakage from logging. See issues #180 and #213.

coc.nvim

Use coc.nvim, with the following coc-settings.json configuration:

  "languageserver": {
    "golang": {
      "command": "gopls",
      "rootPatterns": ["go.mod", ".vim/", ".git/", ".hg/"],
      "filetypes": ["go"],
      "initializationOptions": {
        "usePlaceholders": true
      }
    }
  }

Other settings can be added in initializationOptions too.

The editor.action.organizeImport code action will auto-format code and add missing imports. To run this automatically on save, add the following line to your init.vim:

autocmd BufWritePre *.go :call CocAction('runCommand', 'editor.action.organizeImport')

govim

In vim classic only, use the experimental govim, simply follow the install steps.

nvim-lsp

To use the new builtin lsp client from neovim, using nvim-lsp, follow the install steps neovim/nvim-lsp and check the gopls configuration.