Skip to content

Commit

Permalink
Use a different approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander van Harmelen authored and Sander van Harmelen committed Nov 29, 2015
1 parent 09da010 commit a308f10
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
49 changes: 32 additions & 17 deletions autoload/go/lint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ if !exists("g:go_metalinter_command")
let g:go_metalinter_command = ""
endif

if !exists("g:go_metalinter_currentfile")
let g:go_metalinter_currentfile = 0
if !exists("g:go_metalinter_autosave_enabled")
let g:go_metalinter_autosave_enabled = ['vet', 'golint']
endif

if !exists("g:go_metalinter_enabled")
Expand All @@ -23,10 +23,28 @@ if !exists("g:go_errcheck_bin")
endif

function! go#lint#GometaAutoSave() abort
let curfile = g:go_metalinter_currentfile
let g:go_metalinter_currentfile = 1
call go#lint#Gometa()
let g:go_metalinter_currentfile = curfile
let bin_path = go#path#CheckBinPath("gometalinter")
if empty(bin_path)
return
endif

let meta_command = "gometalinter --disable-all"

" include only messages for the active buffer
let meta_command .= " --include='^" . expand('%:p') . ".*$'"

" linters
for linter in g:go_metalinter_autosave_enabled
let meta_command .= " --enable=".linter
endfor

" deadline
let meta_command .= " --deadline=" . g:go_metalinter_deadline

" path
let meta_command .= " " . expand('%:p:h')

call s:gometa(meta_command)
endfunction

function! go#lint#Gometa(...) abort
Expand All @@ -43,33 +61,30 @@ function! go#lint#Gometa(...) abort
return
endif

if g:go_metalinter_currentfile
let meta_command .= " --include='^" . expand('%:p') . ".*$'"
endif

if empty(g:go_metalinter_enabled)
echohl Error | echomsg "vim-go: please enable linters with the setting g:go_metalinter_enabled" | echohl None
return
endif

" linters
for linter in g:go_metalinter_enabled
let meta_command .= " --enable=".linter
endfor

" deadline
let meta_command .= " --deadline=" . g:go_metalinter_deadline

" path
let meta_command .= " " . goargs
else
" the user wants something else, let us use it.
let meta_command = g:go_metalinter_command
endif

call s:gometa(meta_command)
endfunction

function! s:gometa(meta_command) abort
" comment out the following two lines for debugging
" echo meta_command
" echo a:meta_command
" return

let out = go#tool#ExecuteInDir(meta_command)
let out = go#tool#ExecuteInDir(a:meta_command)

if v:shell_error == 0
redraw | echo
Expand Down
13 changes: 7 additions & 6 deletions doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,13 @@ Use this option to auto |:GoMetaLinter| on save. Only linter messages for
the active buffer will be shown. By default it's disabled >
let g:go_metalinter_autosave = 0
<
*'g:go_metalinter_autosave_enabled'*

Specifies the enabled linters for auto |GoMetaLinter| on save. By
default it's using `vet` and `golint`
>
let g:go_metalinter_autosave_enabled = ['vet', 'golint']
<
*'g:go_metalinter_enabled'*

Expand All @@ -885,12 +892,6 @@ an advanced settings and is for users who want to have a complete control
over of how `gometalinter` should be executed. By default it's empty.
>
let g:go_metalinter_command = ""
<
*'g:go_metalinter_currentfile'*

Use this option to only show linter messages for the active buffer.
>
let g:go_metalinter_currentfile = 0
<
*'g:go_metalinter_deadline'*

Expand Down

0 comments on commit a308f10

Please sign in to comment.