Skip to content

Commit 2a33f91

Browse files
committed
metalinter: filter autosave results manually
Filter results of running the metalinter manually in preparation for merging fatih#2367, so that merging fatih#2367 won't suddenly start reporting results for all files in a package when the metalinter is golangci-lint since golangci-lint does not have a way to filter its results to include only the results for a single file.
1 parent ed51984 commit 2a33f91

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

autoload/go/lint.vim

+23-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ function! go#lint#Gometa(bang, autosave, ...) abort
8484
else
8585
let l:winid = win_getid(winnr())
8686
" Parse and populate our location list
87-
call go#list#ParseFormat(l:listtype, errformat, split(out, "\n"), 'GoMetaLinter')
87+
88+
let l:messages = split(out, "\n")
89+
90+
if a:autosave
91+
call s:metalinterautosavecomplete(fnamemodify(expand('%:p'), ":."), 0, 1, l:messages)
92+
endif
93+
call go#list#ParseFormat(l:listtype, errformat, l:messages, 'GoMetaLinter')
8894

8995
let errors = go#list#Get(l:listtype)
9096
call go#list#Window(l:listtype, len(errors))
@@ -226,6 +232,7 @@ function! s:lint_job(args, bang, autosave)
226232

227233
if a:autosave
228234
let l:opts.for = "GoMetaLinterAutoSave"
235+
let l:opts.complete = funcref('s:metalinterautosavecomplete', [expand('%:p:t')])
229236
endif
230237

231238
" autowrite is not enabled for jobs
@@ -275,6 +282,21 @@ function! s:golangcilintcmd(bin_path)
275282
return cmd
276283
endfunction
277284

285+
function! s:metalinterautosavecomplete(filepath, job, exit_code, messages)
286+
if len(a:messages) == 0
287+
return
288+
endif
289+
290+
let l:file = expand('%:p:t')
291+
let l:idx = len(a:messages) - 1
292+
while l:idx >= 0
293+
if a:messages[l:idx] !~# '^' . a:filepath . ':'
294+
call remove(a:messages, l:idx)
295+
endif
296+
let l:idx -= 1
297+
endwhile
298+
endfunction
299+
278300
" restore Vi compatibility settings
279301
let &cpo = s:cpo_save
280302
unlet s:cpo_save

0 commit comments

Comments
 (0)