mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-12 17:55:41 +08:00
feat(lang#go): add lsp support for golang
This commit is contained in:
parent
d5d2f1e066
commit
5c68676c53
@ -9,7 +9,16 @@
|
|||||||
""
|
""
|
||||||
" @section lang#go, layers-lang-go
|
" @section lang#go, layers-lang-go
|
||||||
" @parentsection layers
|
" @parentsection layers
|
||||||
" This layer includes code completion and syntax checking for Go development.
|
" The `lang#go` layer includes code completion and syntax checking for
|
||||||
|
" Go development. This layer is not enabled by default, to enable it:
|
||||||
|
" >
|
||||||
|
" [[layers]]
|
||||||
|
" name = 'go'
|
||||||
|
" <
|
||||||
|
" @subsection layer options
|
||||||
|
" 1. `enabled_linters`: set a list of enabled lint for golang. by default this
|
||||||
|
" option is `['golint']`. The available linters includes: `go`,
|
||||||
|
" `gometalinter`
|
||||||
"
|
"
|
||||||
" @subsection Mappings
|
" @subsection Mappings
|
||||||
" >
|
" >
|
||||||
@ -38,6 +47,20 @@
|
|||||||
" normal SPC l v freevars
|
" normal SPC l v freevars
|
||||||
" normal SPC l r go run
|
" normal SPC l r go run
|
||||||
" <
|
" <
|
||||||
|
" If the lsp layer is enabled for go, the following key bindings can
|
||||||
|
" be used:
|
||||||
|
" >
|
||||||
|
" key binding Description
|
||||||
|
" g D jump to type definition
|
||||||
|
" SPC l e rename symbol
|
||||||
|
" SPC l x show references
|
||||||
|
" SPC l s show line diagnostics
|
||||||
|
" SPC l d show document
|
||||||
|
" K show document
|
||||||
|
" SPC l w l list workspace folder
|
||||||
|
" SPC l w a add workspace folder
|
||||||
|
" SPC l w r remove workspace folder
|
||||||
|
" <
|
||||||
|
|
||||||
|
|
||||||
function! SpaceVim#layers#lang#go#plugins() abort
|
function! SpaceVim#layers#lang#go#plugins() abort
|
||||||
@ -58,6 +81,9 @@ function! SpaceVim#layers#lang#go#config() abort
|
|||||||
let g:go_fmt_command = 'gopls'
|
let g:go_fmt_command = 'gopls'
|
||||||
let g:syntastic_go_checkers = ['golint', 'govet']
|
let g:syntastic_go_checkers = ['golint', 'govet']
|
||||||
let g:syntastic_mode_map = { 'mode': 'active', 'passive_filetypes': ['go'] }
|
let g:syntastic_mode_map = { 'mode': 'active', 'passive_filetypes': ['go'] }
|
||||||
|
" neomake config:
|
||||||
|
let g:neomake_go_gometalinter_remove_invalid_entries = 1
|
||||||
|
let g:neomake_go_go_remove_invalid_entries = 1
|
||||||
let g:neomake_go_gometalinter_args = ['--disable-all']
|
let g:neomake_go_gometalinter_args = ['--disable-all']
|
||||||
let g:go_snippet_engine = 'neosnippet'
|
let g:go_snippet_engine = 'neosnippet'
|
||||||
let g:go_rename_command = 'gopls'
|
let g:go_rename_command = 'gopls'
|
||||||
@ -73,7 +99,12 @@ function! SpaceVim#layers#lang#go#config() abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:go_to_def() abort
|
function! s:go_to_def() abort
|
||||||
|
if SpaceVim#layers#lsp#check_filetype('go')
|
||||||
|
\ || SpaceVim#layers#lsp#check_server('gopls')
|
||||||
|
call SpaceVim#lsp#go_to_def()
|
||||||
|
else
|
||||||
call go#def#Jump('', 0)
|
call go#def#Jump('', 0)
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:language_specified_mappings() abort
|
function! s:language_specified_mappings() abort
|
||||||
@ -145,6 +176,27 @@ function! s:language_specified_mappings() abort
|
|||||||
\ ':GoFreevars',
|
\ ':GoFreevars',
|
||||||
\ 'freevars', 1)
|
\ 'freevars', 1)
|
||||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','r'], 'call SpaceVim#plugins#runner#open()', 'execute current file', 1)
|
call SpaceVim#mapping#space#langSPC('nmap', ['l','r'], 'call SpaceVim#plugins#runner#open()', 'execute current file', 1)
|
||||||
|
if SpaceVim#layers#lsp#check_filetype('go')
|
||||||
|
\ || SpaceVim#layers#lsp#check_server('gopls')
|
||||||
|
nnoremap <silent><buffer> K :call SpaceVim#lsp#show_doc()<CR>
|
||||||
|
nnoremap <silent><buffer> gD :<C-u>call SpaceVim#lsp#go_to_typedef()<Cr>
|
||||||
|
|
||||||
|
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'],
|
||||||
|
\ 'call SpaceVim#lsp#show_doc()', 'show-document', 1)
|
||||||
|
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'x'],
|
||||||
|
\ 'call SpaceVim#lsp#references()', 'show-references', 1)
|
||||||
|
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'e'],
|
||||||
|
\ 'call SpaceVim#lsp#rename()', 'rename-symbol', 1)
|
||||||
|
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 's'],
|
||||||
|
\ 'call SpaceVim#lsp#show_line_diagnostics()', 'show-line-diagnostics', 1)
|
||||||
|
let g:_spacevim_mappings_space.l.w = {'name' : '+Workspace'}
|
||||||
|
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'w', 'l'],
|
||||||
|
\ 'call SpaceVim#lsp#list_workspace_folder()', 'list-workspace-folder', 1)
|
||||||
|
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'w', 'a'],
|
||||||
|
\ 'call SpaceVim#lsp#add_workspace_folder()', 'add-workspace-folder', 1)
|
||||||
|
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'w', 'r'],
|
||||||
|
\ 'call SpaceVim#lsp#remove_workspace_folder()', 'remove-workspace-folder', 1)
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! SpaceVim#layers#lang#go#health() abort
|
function! SpaceVim#layers#lang#go#health() abort
|
||||||
|
@ -2407,7 +2407,15 @@ This layer also provides REPL support for goby, the key bindings are:
|
|||||||
==============================================================================
|
==============================================================================
|
||||||
LANG#GO *SpaceVim-layers-lang-go*
|
LANG#GO *SpaceVim-layers-lang-go*
|
||||||
|
|
||||||
This layer includes code completion and syntax checking for Go development.
|
The `lang#go` layer includes code completion and syntax checking for Go
|
||||||
|
development. This layer is not enabled by default, to enable it:
|
||||||
|
>
|
||||||
|
[[layers]]
|
||||||
|
name = 'go'
|
||||||
|
<
|
||||||
|
LAYER OPTIONS
|
||||||
|
1. `enabled_linters`: set a list of enabled lint for golang. by default this
|
||||||
|
option is `['golint']`. The available linters includes: `go`, `gometalinter`
|
||||||
|
|
||||||
MAPPINGS
|
MAPPINGS
|
||||||
|
|
||||||
@ -2437,6 +2445,19 @@ MAPPINGS
|
|||||||
normal SPC l v freevars
|
normal SPC l v freevars
|
||||||
normal SPC l r go run
|
normal SPC l r go run
|
||||||
<
|
<
|
||||||
|
If the lsp layer is enabled for go, the following key bindings can be used:
|
||||||
|
>
|
||||||
|
key binding Description
|
||||||
|
g D jump to type definition
|
||||||
|
SPC l e rename symbol
|
||||||
|
SPC l x show references
|
||||||
|
SPC l s show line diagnostics
|
||||||
|
SPC l d show document
|
||||||
|
K show document
|
||||||
|
SPC l w l list workspace folder
|
||||||
|
SPC l w a add workspace folder
|
||||||
|
SPC l w r remove workspace folder
|
||||||
|
<
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
LANG#GOBY *SpaceVim-layers-lang-goby*
|
LANG#GOBY *SpaceVim-layers-lang-goby*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user