From 8c49237e64b1e9e279b4d43aea26e6d07e4722ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Philippe=20Gu=C3=A9rard?= Date: Tue, 25 Jun 2019 23:08:08 +0200 Subject: [PATCH 1/2] Add a new Go linter: gopls --- doc/syntastic-checkers.txt | 27 +++++++++++++++--- syntax_checkers/go/gopls.vim | 53 ++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 syntax_checkers/go/gopls.vim diff --git a/doc/syntastic-checkers.txt b/doc/syntastic-checkers.txt index 64d51e414..842004945 100644 --- a/doc/syntastic-checkers.txt +++ b/doc/syntastic-checkers.txt @@ -2516,8 +2516,9 @@ The following checkers are available for Go (filetype "go"): 3. GolangCI-Lint............|syntastic-go-golangci_lint| 4. Golint...................|syntastic-go-golint| 5. Go Meta Linter...........|syntastic-go-gometalinter| - 6. gotype...................|syntastic-go-gotype| - 7. vet......................|syntastic-go-govet| + 6. gopls....................|syntastic-go-gopls| + 7. gotype...................|syntastic-go-gotype| + 8. vet......................|syntastic-go-govet| ------------------------------------------------------------------------------ 1. go *syntastic-go-go* @@ -2613,7 +2614,25 @@ This checker is initialised using the "makeprgBuild()" function and thus it accepts the standard options described at |syntastic-config-makeprg|. ------------------------------------------------------------------------------ -6. gotype *syntastic-go-gotype* +6. gopls *syntastic-go-gopls* + +Name: gopls +Maintainer: Jean-Philippe Guérard + +gopls (pronounced: "go please") is an implementation of the Language Server +Protocol (LSP) server for Go. It can be used as a standalone linter. +See the Go wiki for details: + + https://github.com/golang/go/wiki/gopls + +Note~ + +Initial releases of gopls did not allow use as a standalone linter. This +checker will only work with releases of gopls that allow the use of +the "version" and "check" commands. + +------------------------------------------------------------------------------ +7. gotype *syntastic-go-gotype* Name: gotype Maintainer: luz @@ -2623,7 +2642,7 @@ See the tool's documentation for details: https://godoc.org/golang.org/x/tools/cmd/gotype ------------------------------------------------------------------------------ -7. vet *syntastic-go-govet* +8. vet *syntastic-go-govet* Name: govet Maintainer: Kamil Kisiel diff --git a/syntax_checkers/go/gopls.vim b/syntax_checkers/go/gopls.vim new file mode 100644 index 000000000..b1db1c4eb --- /dev/null +++ b/syntax_checkers/go/gopls.vim @@ -0,0 +1,53 @@ +"============================================================================ +"File: gopls.vim +"Description: Check go syntax using 'gopls check' +"Maintainer: Jean-Philippe Guérard +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +"============================================================================ + +if exists('g:loaded_syntastic_go_gopls_checker') + finish +endif +let g:loaded_syntastic_go_gopls_checker = 1 + +let s:save_cpo = &cpo +set cpo&vim + +function! SyntaxCheckers_go_gopls_IsAvailable() dict + if !executable(self.getExec()) + return 0 + endif + " Older version of gopls only understand 'gopls serve', but not 'gopls + " version' or 'gopls check' + call syntastic#util#system(self.getExecEscaped() . ' version') + return v:shell_error == 0 +endfunction + +function! SyntaxCheckers_go_gopls_GetLocList() dict + let makeprg = self.makeprgBuild({ 'args_before': 'check' }) + + let errorformat = + \ '%f:%l:%c: %m,' . + \ '%f:%l:%c-%\\d%\\+: %m,' . + \ '%-G%.%#' + + return SyntasticMake({ + \ 'makeprg': makeprg, + \ 'errorformat': errorformat, + \ 'defaults': {'type': 'e'}, + \ 'subtype': 'Style' }) +endfunction + +call g:SyntasticRegistry.CreateAndRegisterChecker({ + \ 'filetype': 'go', + \ 'name': 'gopls', + \ 'exec': 'gopls' }) + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim: set sw=4 sts=4 et fdm=marker: From f0c0b582a573b01805fbbaba27f6ab460160673f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Philippe=20Gu=C3=A9rard?= Date: Thu, 27 Jun 2019 09:40:47 +0200 Subject: [PATCH 2/2] Remove useless backslash in errorformat --- syntax_checkers/go/gopls.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax_checkers/go/gopls.vim b/syntax_checkers/go/gopls.vim index b1db1c4eb..49f9c0fef 100644 --- a/syntax_checkers/go/gopls.vim +++ b/syntax_checkers/go/gopls.vim @@ -32,7 +32,7 @@ function! SyntaxCheckers_go_gopls_GetLocList() dict let errorformat = \ '%f:%l:%c: %m,' . - \ '%f:%l:%c-%\\d%\\+: %m,' . + \ '%f:%l:%c-%\d%\+: %m,' . \ '%-G%.%#' return SyntasticMake({