Close #2179 - Add support for gopls
This commit is contained in:
parent
042b351b7a
commit
2e8c8085a6
6 changed files with 184 additions and 86 deletions
30
ale_linters/go/gopls.vim
Normal file
30
ale_linters/go/gopls.vim
Normal file
|
@ -0,0 +1,30 @@
|
|||
" Author: w0rp <devw0rp@gmail.com>
|
||||
" Author: Jerko Steiner <https://github.com/jeremija>
|
||||
" Description: https://github.com/saibing/gopls
|
||||
|
||||
call ale#Set('go_gopls_executable', 'gopls')
|
||||
call ale#Set('go_gopls_options', '--mode stdio')
|
||||
|
||||
function! ale_linters#go#gopls#GetCommand(buffer) abort
|
||||
return '%e' . ale#Pad(ale#Var(a:buffer, 'go_gopls_options'))
|
||||
endfunction
|
||||
|
||||
function! ale_linters#go#gopls#FindProjectRoot(buffer) abort
|
||||
let l:project_root = ale#path#FindNearestFile(a:buffer, 'go.mod')
|
||||
let l:mods = ':h'
|
||||
|
||||
if empty(l:project_root)
|
||||
let l:project_root = ale#path#FindNearestDirectory(a:buffer, '.git')
|
||||
let l:mods = ':h:h'
|
||||
endif
|
||||
|
||||
return !empty(l:project_root) ? fnamemodify(l:project_root, l:mods) : ''
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('go', {
|
||||
\ 'name': 'gopls',
|
||||
\ 'lsp': 'stdio',
|
||||
\ 'executable': {b -> ale#Var(b, 'go_gopls_executable')},
|
||||
\ 'command': function('ale_linters#go#gopls#GetCommand'),
|
||||
\ 'project_root': function('ale_linters#go#gopls#FindProjectRoot'),
|
||||
\})
|
179
doc/ale-go.txt
179
doc/ale-go.txt
|
@ -30,6 +30,23 @@ g:ale_go_go_executable *g:ale_go_go_options*
|
|||
the `gomod` fixer.
|
||||
|
||||
|
||||
===============================================================================
|
||||
bingo *ale-go-bingo*
|
||||
|
||||
g:ale_go_bingo_executable *g:ale_go_bingo_executable*
|
||||
*b:ale_go_bingo_executable*
|
||||
Type: |String|
|
||||
Default: `'bingo'`
|
||||
|
||||
Location of the bingo binary file.
|
||||
|
||||
|
||||
g:ale_go_bingo_options *g:ale_go_bingo_options*
|
||||
*b:ale_go_bingo_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
|
||||
===============================================================================
|
||||
gobuild *ale-go-gobuild*
|
||||
|
||||
|
@ -53,6 +70,60 @@ g:ale_go_gofmt_options *g:ale_go_gofmt_options*
|
|||
This variable can be set to pass additional options to the gofmt fixer.
|
||||
|
||||
|
||||
===============================================================================
|
||||
golangci-lint *ale-go-golangci-lint*
|
||||
|
||||
`golangci-lint` is a `lint_file` linter, which only lints files that are
|
||||
written to disk. This differs from the default behavior of linting the buffer.
|
||||
See: |ale-lint-file|
|
||||
|
||||
g:ale_go_golangci_lint_executable *g:ale_go_golangci_lint_executable*
|
||||
*b:ale_go_golangci_lint_executable*
|
||||
Type: |String|
|
||||
Default: `'golangci-lint'`
|
||||
|
||||
The executable that will be run for golangci-lint.
|
||||
|
||||
|
||||
g:ale_go_golangci_lint_options *g:ale_go_golangci_lint_options*
|
||||
*b:ale_go_golangci_lint_options*
|
||||
Type: |String|
|
||||
Default: `'--enable-all'`
|
||||
|
||||
This variable can be changed to alter the command-line arguments to the
|
||||
golangci-lint invocation.
|
||||
|
||||
|
||||
g:ale_go_golangci_lint_package *g:ale_go_golangci_lint_package*
|
||||
*b:ale_go_golangci_lint_package*
|
||||
Type: |Number|
|
||||
Default: `0`
|
||||
|
||||
When set to `1`, the whole Go package will be checked instead of only the
|
||||
current file.
|
||||
|
||||
|
||||
===============================================================================
|
||||
golangserver *ale-go-golangserver*
|
||||
|
||||
g:ale_go_langserver_executable *g:ale_go_langserver_executable*
|
||||
*b:ale_go_langserver_executable*
|
||||
Type: |String|
|
||||
Default: `'go-langserver'`
|
||||
|
||||
Location of the go-langserver binary file.
|
||||
|
||||
|
||||
g:ale_go_langserver_options *g:ale_go_langserver_options*
|
||||
*b:ale_go_langserver_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
Additional options passed to the go-langserver command. Note that the
|
||||
`-gocodecompletion` option is ignored because it is handled automatically
|
||||
by the |g:ale_completion_enabled| variable.
|
||||
|
||||
|
||||
===============================================================================
|
||||
golint *ale-go-golint*
|
||||
|
||||
|
@ -72,17 +143,6 @@ g:ale_go_golint_options *g:ale_go_golint_options*
|
|||
This variable can be set to pass additional options to the golint linter.
|
||||
|
||||
|
||||
===============================================================================
|
||||
govet *ale-go-govet*
|
||||
|
||||
g:ale_go_govet_options *g:ale_go_govet_options*
|
||||
*b:ale_go_govet_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
This variable can be set to pass additional options to the go vet linter.
|
||||
|
||||
|
||||
===============================================================================
|
||||
gometalinter *ale-go-gometalinter*
|
||||
|
||||
|
@ -121,6 +181,34 @@ g:ale_go_gometalinter_lint_package *g:ale_go_gometalinter_lint_package*
|
|||
current file.
|
||||
|
||||
|
||||
===============================================================================
|
||||
gopls *ale-go-gopls*
|
||||
|
||||
g:ale_go_gopls_executable *g:ale_go_gopls_executable*
|
||||
*b:ale_go_gopls_executable*
|
||||
Type: |String|
|
||||
Default: `'gopls'`
|
||||
|
||||
Location of the gopls binary file.
|
||||
|
||||
|
||||
g:ale_go_gopls_options *g:ale_go_gopls_options*
|
||||
*b:ale_go_gopls_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
|
||||
===============================================================================
|
||||
govet *ale-go-govet*
|
||||
|
||||
g:ale_go_govet_options *g:ale_go_govet_options*
|
||||
*b:ale_go_govet_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
This variable can be set to pass additional options to the go vet linter.
|
||||
|
||||
|
||||
===============================================================================
|
||||
staticcheck *ale-go-staticcheck*
|
||||
|
||||
|
@ -142,74 +230,5 @@ g:ale_go_staticcheck_lint_package *g:ale_go_staticcheck_lint_package*
|
|||
current file.
|
||||
|
||||
|
||||
===============================================================================
|
||||
golangserver *ale-go-golangserver*
|
||||
|
||||
g:ale_go_langserver_executable *g:ale_go_langserver_executable*
|
||||
*b:ale_go_langserver_executable*
|
||||
Type: |String|
|
||||
Default: `'go-langserver'`
|
||||
|
||||
Location of the go-langserver binary file.
|
||||
|
||||
g:ale_go_langserver_options *g:ale_go_langserver_options*
|
||||
*b:ale_go_langserver_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
Additional options passed to the go-langserver command. Note that the
|
||||
`-gocodecompletion` option is ignored because it is handled automatically
|
||||
by the |g:ale_completion_enabled| variable.
|
||||
|
||||
|
||||
===============================================================================
|
||||
golangci-lint *ale-go-golangci-lint*
|
||||
|
||||
`golangci-lint` is a `lint_file` linter, which only lints files that are
|
||||
written to disk. This differs from the default behavior of linting the buffer.
|
||||
See: |ale-lint-file|
|
||||
|
||||
g:ale_go_golangci_lint_executable *g:ale_go_golangci_lint_executable*
|
||||
*b:ale_go_golangci_lint_executable*
|
||||
Type: |String|
|
||||
Default: `'golangci-lint'`
|
||||
|
||||
The executable that will be run for golangci-lint.
|
||||
|
||||
|
||||
g:ale_go_golangci_lint_options *g:ale_go_golangci_lint_options*
|
||||
*b:ale_go_golangci_lint_options*
|
||||
Type: |String|
|
||||
Default: `'--enable-all'`
|
||||
|
||||
This variable can be changed to alter the command-line arguments to the
|
||||
golangci-lint invocation.
|
||||
|
||||
|
||||
g:ale_go_golangci_lint_package *g:ale_go_golangci_lint_package*
|
||||
*b:ale_go_golangci_lint_package*
|
||||
Type: |Number|
|
||||
Default: `0`
|
||||
|
||||
When set to `1`, the whole Go package will be checked instead of only the
|
||||
current file.
|
||||
|
||||
|
||||
===============================================================================
|
||||
bingo *ale-go-bingo*
|
||||
|
||||
g:ale_go_bingo_executable *g:ale_go_bingo_executable*
|
||||
*b:ale_go_bingo_executable*
|
||||
Type: |String|
|
||||
Default: `'go-bingo'`
|
||||
|
||||
Location of the go-bingo binary file.
|
||||
|
||||
g:ale_go_bingo_options *g:ale_go_bingo_options*
|
||||
*b:ale_go_bingo_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
|
||||
===============================================================================
|
||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||
|
|
|
@ -153,6 +153,7 @@ Notes:
|
|||
* `golint`
|
||||
* `gometalinter`!!
|
||||
* `go mod`!!
|
||||
* `gopls`
|
||||
* `gosimple`!!
|
||||
* `gotype`!!
|
||||
* `go vet`!!
|
||||
|
|
13
doc/ale.txt
13
doc/ale.txt
|
@ -1934,15 +1934,16 @@ documented in additional help files.
|
|||
glslang...............................|ale-glsl-glslang|
|
||||
glslls................................|ale-glsl-glslls|
|
||||
go......................................|ale-go-options|
|
||||
bingo.................................|ale-go-bingo|
|
||||
gobuild...............................|ale-go-gobuild|
|
||||
gofmt.................................|ale-go-gofmt|
|
||||
golint................................|ale-go-golint|
|
||||
govet.................................|ale-go-govet|
|
||||
gometalinter..........................|ale-go-gometalinter|
|
||||
staticcheck...........................|ale-go-staticcheck|
|
||||
golangserver..........................|ale-go-golangserver|
|
||||
golangci-lint.........................|ale-go-golangci-lint|
|
||||
bingo.................................|ale-go-bingo|
|
||||
golangserver..........................|ale-go-golangserver|
|
||||
golint................................|ale-go-golint|
|
||||
gometalinter..........................|ale-go-gometalinter|
|
||||
gopls.................................|ale-go-gopls|
|
||||
govet.................................|ale-go-govet|
|
||||
staticcheck...........................|ale-go-staticcheck|
|
||||
graphql.................................|ale-graphql-options|
|
||||
eslint................................|ale-graphql-eslint|
|
||||
gqlint................................|ale-graphql-gqlint|
|
||||
|
|
|
@ -162,6 +162,7 @@ formatting.
|
|||
* [golint](https://godoc.org/github.com/golang/lint)
|
||||
* [gometalinter](https://github.com/alecthomas/gometalinter) :warning: :floppy_disk:
|
||||
* [go mod](https://golang.org/cmd/go/) :warning: :floppy_disk:
|
||||
* [gopls](https://github.com/golang/go/wiki/gopls) :warning:
|
||||
* [gosimple](https://github.com/dominikh/go-tools/tree/master/cmd/gosimple) :warning: :floppy_disk:
|
||||
* [gotype](https://godoc.org/golang.org/x/tools/cmd/gotype) :warning: :floppy_disk:
|
||||
* [go vet](https://golang.org/cmd/vet/) :floppy_disk:
|
||||
|
|
46
test/command_callback/test_gopls_command_callback.vader
Normal file
46
test/command_callback/test_gopls_command_callback.vader
Normal file
|
@ -0,0 +1,46 @@
|
|||
Before:
|
||||
call ale#assert#SetUpLinterTest('go', 'gopls')
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
if isdirectory(g:dir . '/.git')
|
||||
call delete(g:dir . '/.git', 'd')
|
||||
endif
|
||||
|
||||
unlet! b:ale_completion_enabled
|
||||
|
||||
call ale#assert#TearDownLinterTest()
|
||||
|
||||
Execute(should set correct defaults):
|
||||
AssertLinter 'gopls', ale#Escape('gopls') . ' --mode stdio'
|
||||
|
||||
Execute(should configure gopls callback executable):
|
||||
let b:ale_go_gopls_executable = 'boo'
|
||||
let b:ale_go_gopls_options = ''
|
||||
|
||||
AssertLinter 'boo', ale#Escape('boo')
|
||||
|
||||
Execute(should set gopls options):
|
||||
call ale#test#SetFilename('go_paths/go1/prj1/file.go')
|
||||
" let b:ale_completion_enabled = 1
|
||||
let b:ale_go_gopls_options = ''
|
||||
|
||||
AssertLinter 'gopls',
|
||||
\ ale#Escape('gopls') . ''
|
||||
|
||||
let b:ale_go_gopls_options = '--mode stdio --trace'
|
||||
|
||||
AssertLinter 'gopls',
|
||||
\ ale#Escape('gopls') . ' --mode stdio --trace'
|
||||
|
||||
Execute(Should return directory for 'go.mod' if found in parent directory):
|
||||
call ale#test#SetFilename('../go_files/test.go')
|
||||
|
||||
AssertLSPProject ale#path#Simplify(g:dir . '/../go_files')
|
||||
|
||||
Execute(Should return nearest directory with '.git' if found in parent directory):
|
||||
call ale#test#SetFilename('test.go')
|
||||
call mkdir(g:dir . '/.git')
|
||||
|
||||
AssertLSPProject g:dir
|
Reference in a new issue