summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/go/gopls.vim30
-rw-r--r--doc/ale-go.txt165
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt9
-rw-r--r--supported-tools.md1
-rw-r--r--test/command_callback/test_gopls_command_callback.vader46
6 files changed, 175 insertions, 77 deletions
diff --git a/ale_linters/go/gopls.vim b/ale_linters/go/gopls.vim
new file mode 100644
index 00000000..c411dc2b
--- /dev/null
+++ b/ale_linters/go/gopls.vim
@@ -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'),
+\})
diff --git a/doc/ale-go.txt b/doc/ale-go.txt
index 3fbc6fb9..611e3fdd 100644
--- a/doc/ale-go.txt
+++ b/doc/ale-go.txt
@@ -31,6 +31,23 @@ g:ale_go_go_executable *g:ale_go_go_options*
===============================================================================
+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*
g:ale_go_gobuild_options *g:ale_go_gobuild_options*
@@ -54,6 +71,60 @@ g:ale_go_gofmt_options *g:ale_go_gofmt_options*
===============================================================================
+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*
g:ale_go_golint_executable *g:ale_go_golint_executable*
@@ -73,17 +144,6 @@ g:ale_go_golint_options *g:ale_go_golint_options*
===============================================================================
-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*
`gometalinter` is a `lint_file` linter, which only lints files that are
@@ -122,72 +182,47 @@ g:ale_go_gometalinter_lint_package *g:ale_go_gometalinter_lint_package*
===============================================================================
-staticcheck *ale-go-staticcheck*
+gopls *ale-go-gopls*
-g:ale_go_staticcheck_options *g:ale_go_staticcheck_options*
- *b:ale_go_staticcheck_options*
+g:ale_go_gopls_executable *g:ale_go_gopls_executable*
+ *b:ale_go_gopls_executable*
Type: |String|
- Default: `''`
-
- This variable can be set to pass additional options to the staticcheck
- linter.
+ Default: `'gopls'`
+ Location of the gopls binary file.
-g:ale_go_staticcheck_lint_package *g:ale_go_staticcheck_lint_package*
- *b:ale_go_staticcheck_lint_package*
- Type: |Number|
- Default: `0`
- When set to `1`, the whole Go package will be checked instead of only the
- current file.
+g:ale_go_gopls_options *g:ale_go_gopls_options*
+ *b:ale_go_gopls_options*
+ Type: |String|
+ Default: `''`
===============================================================================
-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.
+govet *ale-go-govet*
-g:ale_go_langserver_options *g:ale_go_langserver_options*
- *b:ale_go_langserver_options*
+g:ale_go_govet_options *g:ale_go_govet_options*
+ *b:ale_go_govet_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.
+ This variable can be set to pass additional options to the go vet linter.
===============================================================================
-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.
-
+staticcheck *ale-go-staticcheck*
-g:ale_go_golangci_lint_options *g:ale_go_golangci_lint_options*
- *b:ale_go_golangci_lint_options*
+g:ale_go_staticcheck_options *g:ale_go_staticcheck_options*
+ *b:ale_go_staticcheck_options*
Type: |String|
- Default: `'--enable-all'`
+ Default: `''`
- This variable can be changed to alter the command-line arguments to the
- golangci-lint invocation.
+ This variable can be set to pass additional options to the staticcheck
+ linter.
-g:ale_go_golangci_lint_package *g:ale_go_golangci_lint_package*
- *b:ale_go_golangci_lint_package*
+g:ale_go_staticcheck_lint_package *g:ale_go_staticcheck_lint_package*
+ *b:ale_go_staticcheck_lint_package*
Type: |Number|
Default: `0`
@@ -196,20 +231,4 @@ g:ale_go_golangci_lint_package *g:ale_go_golangci_lint_package*
===============================================================================
-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:
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 4307649d..0051fd6a 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -153,6 +153,7 @@ Notes:
* `golint`
* `gometalinter`!!
* `go mod`!!
+ * `gopls`
* `gosimple`!!
* `gotype`!!
* `go vet`!!
diff --git a/doc/ale.txt b/doc/ale.txt
index 34b5047f..7b1b32fd 100644
--- a/doc/ale.txt
+++ b/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|
+ golangci-lint.........................|ale-go-golangci-lint|
+ golangserver..........................|ale-go-golangserver|
golint................................|ale-go-golint|
- govet.................................|ale-go-govet|
gometalinter..........................|ale-go-gometalinter|
+ gopls.................................|ale-go-gopls|
+ govet.................................|ale-go-govet|
staticcheck...........................|ale-go-staticcheck|
- golangserver..........................|ale-go-golangserver|
- golangci-lint.........................|ale-go-golangci-lint|
- bingo.................................|ale-go-bingo|
graphql.................................|ale-graphql-options|
eslint................................|ale-graphql-eslint|
gqlint................................|ale-graphql-gqlint|
diff --git a/supported-tools.md b/supported-tools.md
index 36d72d3e..1d448407 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -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:
diff --git a/test/command_callback/test_gopls_command_callback.vader b/test/command_callback/test_gopls_command_callback.vader
new file mode 100644
index 00000000..0e079a73
--- /dev/null
+++ b/test/command_callback/test_gopls_command_callback.vader
@@ -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