summaryrefslogtreecommitdiff
path: root/ale_linters/go/gopls.vim
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2019-04-10 19:23:06 +0100
committerw0rp <devw0rp@gmail.com>2019-04-10 19:23:16 +0100
commit2e8c8085a6b98261883a88edc849e4f1a9432fc8 (patch)
treea590e9975837261e06afaee06e7c5b77a539ae1a /ale_linters/go/gopls.vim
parent042b351b7ab20dd67854d0294c67efc47df3b924 (diff)
downloadale-2e8c8085a6b98261883a88edc849e4f1a9432fc8.zip
Close #2179 - Add support for gopls
Diffstat (limited to 'ale_linters/go/gopls.vim')
-rw-r--r--ale_linters/go/gopls.vim30
1 files changed, 30 insertions, 0 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'),
+\})