Skip to content

Commit 9cfe15a

Browse files
authored
Merge pull request #3050 from bhcleek/lsp/ignore-warnings
config: add an option to ignore diagnostics warnings
2 parents 8f3c032 + 9d11a67 commit 9cfe15a

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

autoload/go/config.vim

+4
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,10 @@ function! go#config#DiagnosticsEnabled() abort
576576
return get(g:, 'go_diagnostics_enabled', 0)
577577
endfunction
578578

579+
function! go#config#DiagnosticsIgnoreWarnings() abort
580+
return get(g:, 'go_diagnostics_ignore_warnings', 0)
581+
endfunction
582+
579583
function! go#config#GoplsOptions() abort
580584
return get(g:, 'go_gopls_options', ['-remote=auto'])
581585
endfunction

autoload/go/lint.vim

+12-7
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,16 @@ function! go#lint#Diagnostics(bang, ...) abort
144144

145145
let l:listtype = go#list#Type("GoDiagnostics")
146146

147-
if len(l:messages) == 0
147+
" Parse and populate the quickfix list
148+
let l:winid = win_getid(winnr())
149+
call go#list#ParseFormat(l:listtype, l:errformat, l:messages, 'GoDiagnostics', 0)
150+
151+
let l:errors = go#list#Get(l:listtype)
152+
153+
if len(l:errors) == 0
148154
call go#list#Clean(l:listtype)
149155
call go#util#EchoSuccess('[diagnostics] PASS')
150156
else
151-
" Parse and populate the quickfix list
152-
let l:winid = win_getid(winnr())
153-
call go#list#ParseFormat(l:listtype, l:errformat, l:messages, 'GoDiagnostics', 0)
154-
155-
let errors = go#list#Get(l:listtype)
156157
call go#list#Window(l:listtype, len(errors))
157158

158159
if a:bang
@@ -467,7 +468,11 @@ function! s:errorformat(metalinter) abort
467468
elseif a:metalinter == 'staticcheck'
468469
return '%f:%l:%c:\ %m'
469470
elseif a:metalinter == 'gopls'
470-
return '%f:%l:%c:%t:\ %m,%f:%l:%c::\ %m,%f:%l::%t:\ %m'
471+
let l:efm = ''
472+
if go#config#DiagnosticsIgnoreWarnings()
473+
let l:efm = '%-G%f:%l:%c:W:\ %m,%-G%f:%l::W:\ %m,'
474+
endif
475+
return l:efm . '%f:%l:%c:%t:\ %m,%f:%l:%c::\ %m,%f:%l::%t:\ %m'
471476
endif
472477
endfunction
473478

autoload/go/lsp.vim

+3-1
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,9 @@ function! s:highlightMatches(errorMatches, warningMatches) abort
13931393
call go#util#ClearHighlights('goDiagnosticWarning')
13941394
if go#config#HighlightDiagnosticWarnings()
13951395
let b:go_diagnostic_matches.warnings = copy(a:warningMatches)
1396-
call go#util#HighlightPositions('goDiagnosticWarning', a:warningMatches)
1396+
if !go#config#DiagnosticsIgnoreWarnings()
1397+
call go#util#HighlightPositions('goDiagnosticWarning', a:warningMatches)
1398+
endif
13971399
endif
13981400
endif
13991401

doc/vim-go.txt

+8
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,14 @@ By default it is disabled.
19391939
>
19401940
let g:go_diagnostics_enabled = 0
19411941
<
1942+
*'g:go_diagnostics_ignore_warnings'*
1943+
1944+
Specifies whether warnings from `gopls` diagnostics are ignored.
1945+
1946+
By default it is disabled.
1947+
>
1948+
let g:go_diagnostics_ignore_warnings = 0
1949+
<
19421950

19431951
*'g:go_template_autocreate'*
19441952

0 commit comments

Comments
 (0)