Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: consolidate diagnostics options #3052

Merged
merged 1 commit into from Oct 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions autoload/go/config.vim
Expand Up @@ -572,12 +572,19 @@ function! go#config#GoplsEnabled() abort
return get(g:, 'go_gopls_enabled', 1)
endfunction

" TODO(bc): remove support for g:go_diagnostics_enabled;
" g:go_diagnostics_level is the replacement.
function! go#config#DiagnosticsEnabled() abort
return get(g:, 'go_diagnostics_enabled', 0)
endfunction

function! go#config#DiagnosticsIgnoreWarnings() abort
return get(g:, 'go_diagnostics_ignore_warnings', 0)
function! go#config#DiagnosticsLevel() abort
let l:default = 2
if has_key(g:, 'go_diagnostics_enabled') && !g:go_diagnostics_enabled
let l:default = 0
endif

return get(g:, 'go_diagnostics_level', l:default)
endfunction

function! go#config#GoplsOptions() abort
Expand Down
9 changes: 7 additions & 2 deletions autoload/go/lint.vim
Expand Up @@ -468,8 +468,13 @@ function! s:errorformat(metalinter) abort
elseif a:metalinter == 'staticcheck'
return '%f:%l:%c:\ %m'
elseif a:metalinter == 'gopls'
let l:efm = ''
if go#config#DiagnosticsIgnoreWarnings()
let l:level = go#config#DiagnosticsLevel()

if l:level == 0
return '%-G%f:%l:%c:%t:\ %m,%-G%f:%l:%c::\ %m,%-G%f:%l::%t:\ %m'
endif

if l:level < 2
let l:efm = '%-G%f:%l:%c:W:\ %m,%-G%f:%l::W:\ %m,'
endif
return l:efm . '%f:%l:%c:%t:\ %m,%f:%l:%c::\ %m,%f:%l::%t:\ %m'
Expand Down
15 changes: 7 additions & 8 deletions autoload/go/lsp.vim
Expand Up @@ -233,6 +233,8 @@ function! s:newlsp() abort

" TODO(bc): process the queue asynchronously
function! l:lsp.updateDiagnostics() dict abort
let l:level = go#config#DiagnosticsLevel()

for l:data in self.diagnosticsQueue
call remove(self.diagnosticsQueue, 0)

Expand All @@ -246,22 +248,17 @@ function! s:newlsp() abort
" Vim says that a buffer name can't be an absolute path.
let l:bufname = fnamemodify(l:fname, ':.')

if len(l:data.diagnostics) > 0 && (go#config#DiagnosticsEnabled() || bufnr(l:bufname) == bufnr(''))
if len(l:data.diagnostics) > 0
" make sure the buffer is listed and loaded before calling getbufline() on it
if !bufexists(l:bufname)
"let l:starttime = reltime()
call bufadd(l:bufname)
endif

if !bufloaded(l:bufname)
"let l:starttime = reltime()
call bufload(l:bufname)
endif

for l:diag in l:data.diagnostics
" TODO(bc): cache the raw diagnostics when they're not for the
" current buffer so that they can be processed when it is the
" current buffer and highlight the areas of concern.
let [l:error, l:matchpos] = s:errorFromDiagnostic(l:diag, l:bufname, l:fname)
let l:diagnostics = add(l:diagnostics, l:error)

Expand Down Expand Up @@ -1383,7 +1380,9 @@ function! s:highlightMatches(errorMatches, warningMatches) abort
call go#util#ClearHighlights('goDiagnosticError')
if go#config#HighlightDiagnosticErrors()
let b:go_diagnostic_matches.errors = copy(a:errorMatches)
call go#util#HighlightPositions('goDiagnosticError', a:errorMatches)
if go#config#DiagnosticsLevel() >= 2
call go#util#HighlightPositions('goDiagnosticError', a:errorMatches)
endif
endif
endif

Expand All @@ -1393,7 +1392,7 @@ function! s:highlightMatches(errorMatches, warningMatches) abort
call go#util#ClearHighlights('goDiagnosticWarning')
if go#config#HighlightDiagnosticWarnings()
let b:go_diagnostic_matches.warnings = copy(a:warningMatches)
if !go#config#DiagnosticsIgnoreWarnings()
if go#config#DiagnosticsLevel() >= 2
call go#util#HighlightPositions('goDiagnosticWarning', a:warningMatches)
endif
endif
Expand Down
19 changes: 9 additions & 10 deletions doc/vim-go.txt
Expand Up @@ -1931,21 +1931,20 @@ default it is `v:null`.
<
*'g:go_diagnostics_enabled'*

Specifies whether `gopls` diagnostics are enabled. Only the diagnostics for
the current buffer will be processed when it is not set; all others will be
ignored.

By default it is disabled.
Deprecated. See `'g:go_diagnostics_level'`. Specifies whether `gopls`
diagnostics are enabled. Only the diagnostics for the current buffer will be
processed when it is not set; all others will be ignored. By default it is
disabled.
>
let g:go_diagnostics_enabled = 0
<
*'g:go_diagnostics_ignore_warnings'*
*'g:go_diagnostics_level'*

Specifies whether warnings from `gopls` diagnostics are ignored.

By default it is disabled.
Specifies the `gopls` diagnostics level. Valid values are 0, 1, and 2. 0
ignores `gopls` diagnostics, 1 is for errors only, and 2 is for errors and
warnings. By default it is 2.
>
let g:go_diagnostics_ignore_warnings = 0
let g:go_diagnostics_level = 2
<

*'g:go_template_autocreate'*
Expand Down