From 936c7c38967eb7e166202864bd30786aa31912c9 Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Sat, 15 Feb 2020 10:16:00 -0800 Subject: [PATCH 1/2] lint: homogenize vet and errcheck handling * Use go#util#ExecInDir() when running go vet. * Make the progress message when starting go vet consistent with errcheck's similiar progress message. * Call go#cmd#autowrite() when starting go#lint#Errcheck to either write the buffers that have modifications when 'autowrite' or 'autowriteall' are set or display a message if neither of those options are set, because errcheck only analyzes files on disk. * chagne the error message that's displayed when the package name cannot be determined to avoid implying that the package must be in GOPATH when the user is operating in module aware mode. * Do not echo the start of errcheck progress if g:go_echo_command_info is cleared. * disable g:go_echo_command_info when running tests to avoid screen clutter when tests fail. --- autoload/go/lint.vim | 44 ++++++++++++++++++++++++++------------- autoload/go/lint_test.vim | 6 ++---- scripts/test | 1 + 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/autoload/go/lint.vim b/autoload/go/lint.vim index a730cd1dfd..35bf6e11b9 100644 --- a/autoload/go/lint.vim +++ b/autoload/go/lint.vim @@ -175,24 +175,29 @@ endfunction function! go#lint#Vet(bang, ...) abort call go#cmd#autowrite() - if go#config#EchoCommandInfo() - call go#util#EchoProgress('calling vet...') - endif - let l:cmd = ['go', 'vet'] let buildtags = go#config#BuildTags() if buildtags isnot '' - let cmd += ['-tags', buildtags] + let l:cmd += ['-tags', buildtags] endif - if a:0 != 0 - call extend(cmd, a:000) + if a:0 == 0 + let l:import_path = go#package#ImportPath() + if l:import_path == -1 + call go#util#EchoError('could not determine package') + return + endif + let l:cmd = add(l:cmd, l:import_path) + else + let l:cmd = extend(l:cmd, a:000) endif - let cmd += [go#package#ImportPath()] + if go#config#EchoCommandInfo() + call go#util#EchoProgress('[go vet] analyzing...') + endif - let [l:out, l:err] = go#util#Exec(l:cmd) + let [l:out, l:err] = go#util#ExecInDir(l:cmd) let l:listtype = go#list#Type("GoVet") if l:err != 0 @@ -221,21 +226,32 @@ endfunction " ErrCheck calls 'errcheck' for the given packages. Any warnings are populated in " the location list function! go#lint#Errcheck(bang, ...) abort + call go#cmd#autowrite() + + let l:cmd = [go#config#ErrcheckBin(), '-abspath'] + + let buildtags = go#config#BuildTags() + if buildtags isnot '' + let l:cmd += ['-tags', buildtags] + endif + if a:0 == 0 let l:import_path = go#package#ImportPath() if l:import_path == -1 - call go#util#EchoError('package is not inside GOPATH src') + call go#util#EchoError('could not determine package') return endif - let l:args = [l:import_path] + let l:cmd = add(l:cmd, l:import_path) else - let l:args = a:000 + let l:cmd = extend(l:cmd, a:000) endif - call go#util#EchoProgress('[errcheck] analysing ...') + if go#config#EchoCommandInfo() + call go#util#EchoProgress('[errcheck] analysing...') + endif redraw - let [l:out, l:err] = go#util#ExecInDir([go#config#ErrcheckBin(), '-abspath'] + l:args) + let [l:out, l:err] = go#util#ExecInDir(l:cmd) let l:listtype = go#list#Type("GoErrCheck") if l:err != 0 diff --git a/autoload/go/lint_test.vim b/autoload/go/lint_test.vim index 0a32a00c6e..830a98622d 100644 --- a/autoload/go/lint_test.vim +++ b/autoload/go/lint_test.vim @@ -158,9 +158,8 @@ func! Test_Vet() abort let l:tmp = gotest#load_fixture('lint/src/vet/vet.go') try - let expected = [ - \ {'lnum': 7, 'bufnr': bufnr('%'), 'col': 2, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', + \ {'lnum': 7, 'bufnr': bufnr('%')+2, 'col': 2, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', \ 'text': 'Printf format %d has arg str of wrong type string'} \ ] @@ -188,9 +187,8 @@ func! Test_Vet_compilererror() abort let l:tmp = gotest#load_fixture('lint/src/vet/compilererror/compilererror.go') try - let expected = [ - \ {'lnum': 6, 'bufnr': bufnr('%'), 'col': 22, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': "missing ',' before newline in argument list (and 1 more errors)"} + \ {'lnum': 6, 'bufnr': bufnr('%')+2, 'col': 22, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': "missing ',' before newline in argument list (and 1 more errors)"} \ ] let winnr = winnr() diff --git a/scripts/test b/scripts/test index e6bf96dc20..c06659b0b6 100755 --- a/scripts/test +++ b/scripts/test @@ -69,6 +69,7 @@ find "$vimgodir" -name '*_test.vim' | while read test_file; do "$vimgodir/scripts/run-vim" $coverage $vim -e \ +"silent e $test_file" \ +"let g:test_verbose=$verbose" \ + +"let g:go_echo_command_info=0" \ -S ./scripts/runtest.vim < /dev/null || ( # If Vim exits with non-0 it's almost certainly a bug in the test runner; # should very rarely happen in normal usage. From 7d21c2e1ae31d31f61a0f2adec9bddc70ec0c465 Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Sat, 15 Feb 2020 12:03:12 -0800 Subject: [PATCH 2/2] lint: set progress and statusline for consistently --- autoload/go/lint.vim | 95 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 16 deletions(-) diff --git a/autoload/go/lint.vim b/autoload/go/lint.vim index 35bf6e11b9..e14f40d09e 100644 --- a/autoload/go/lint.vim +++ b/autoload/go/lint.vim @@ -146,28 +146,51 @@ endfunction " Golint calls 'golint' on the current directory. Any warnings are populated in " the location list function! go#lint#Golint(bang, ...) abort + call go#cmd#autowrite() + + let l:type = 'golint' + let l:status = { + \ 'desc': 'current status', + \ 'type': l:type, + \ 'state': "started", + \ } + if go#config#EchoCommandInfo() + call go#util#EchoProgress(printf('[%s] analyzing...', l:type)) + endif + call go#statusline#Update(expand('%:p:h'), l:status) + if a:0 == 0 let [l:out, l:err] = go#util#Exec([go#config#GolintBin(), expand('%:p:h')]) else let [l:out, l:err] = go#util#Exec([go#config#GolintBin()] + a:000) endif - if empty(l:out) - call go#util#EchoSuccess('[lint] PASS') - return - endif + let l:status.state = 'success' + let l:state = 'PASS' + if !empty(l:out) + let l:status.state = 'failed' + let l:state = 'FAIL' - let l:winid = win_getid(winnr()) - let l:listtype = go#list#Type("GoLint") - call go#list#Parse(l:listtype, l:out, "GoLint") - let l:errors = go#list#Get(l:listtype) - call go#list#Window(l:listtype, len(l:errors)) + let l:winid = win_getid(winnr()) + let l:listtype = go#list#Type("GoLint") + call go#list#Parse(l:listtype, l:out, "GoLint") + let l:errors = go#list#Get(l:listtype) + call go#list#Window(l:listtype, len(l:errors)) - if a:bang - call win_gotoid(l:winid) + if a:bang + call win_gotoid(l:winid) + else + call go#list#JumpToFirst(l:listtype) + endif + if go#config#EchoCommandInfo() + call go#util#EchoError(printf('[%s] %s', l:type, l:state)) + endif else - call go#list#JumpToFirst(l:listtype) + if go#config#EchoCommandInfo() + call go#util#EchoSuccess(printf('[%s] %s', l:type, l:state)) + endif endif + call go#statusline#Update(expand('%:p:h'), l:status) endfunction " Vet calls 'go vet' on the current directory. Any warnings are populated in @@ -193,14 +216,27 @@ function! go#lint#Vet(bang, ...) abort let l:cmd = extend(l:cmd, a:000) endif + let l:type = 'go vet' if go#config#EchoCommandInfo() - call go#util#EchoProgress('[go vet] analyzing...') + call go#util#EchoProgress(printf('[%s] analyzing...', l:type)) endif + let l:status = { + \ 'desc': 'current status', + \ 'type': l:type, + \ 'state': "started", + \ } + call go#statusline#Update(expand('%:p:h'), l:status) let [l:out, l:err] = go#util#ExecInDir(l:cmd) + let l:status.state = 'success' + let l:state = 'PASS' + let l:listtype = go#list#Type("GoVet") if l:err != 0 + let l:status.state = 'failed' + let l:state = 'FAIL' + let l:winid = win_getid(winnr()) let l:errorformat = "%-Gexit status %\\d%\\+," . &errorformat call go#list#ParseFormat(l:listtype, l:errorformat, out, "GoVet") @@ -217,10 +253,17 @@ function! go#lint#Vet(bang, ...) abort else call win_gotoid(l:winid) endif + + if go#config#EchoCommandInfo() + call go#util#EchoError(printf('[%s] %s', l:type, l:state)) + endif else call go#list#Clean(l:listtype) - call go#util#EchoSuccess('[vet] PASS') + if go#config#EchoCommandInfo() + call go#util#EchoSuccess(printf('[%s] %s', l:type, l:state)) + endif endif + call go#statusline#Update(expand('%:p:h'), l:status) endfunction " ErrCheck calls 'errcheck' for the given packages. Any warnings are populated in @@ -246,15 +289,29 @@ function! go#lint#Errcheck(bang, ...) abort let l:cmd = extend(l:cmd, a:000) endif + let l:type = 'errcheck' if go#config#EchoCommandInfo() - call go#util#EchoProgress('[errcheck] analysing...') + call go#util#EchoProgress(printf('[%s] analyzing...', l:type)) endif + let l:status = { + \ 'desc': 'current status', + \ 'type': l:type, + \ 'state': "started", + \ } redraw + call go#statusline#Update(expand('%:p:h'), l:status) + let [l:out, l:err] = go#util#ExecInDir(l:cmd) + let l:status.state = 'success' + let l:state = 'PASS' + let l:listtype = go#list#Type("GoErrCheck") if l:err != 0 + let l:status.state = 'failed' + let l:state = 'FAIL' + let l:winid = win_getid(winnr()) if l:err == 1 @@ -278,10 +335,16 @@ function! go#lint#Errcheck(bang, ...) abort call win_gotoid(l:winid) endif endif + if go#config#EchoCommandInfo() + call go#util#EchoError(printf('[%s] %s', l:type, l:state)) + endif else call go#list#Clean(l:listtype) - call go#util#EchoSuccess('[errcheck] PASS') + if go#config#EchoCommandInfo() + call go#util#EchoSuccess(printf('[%s] %s', l:type, l:state)) + endif endif + call go#statusline#Update(expand('%:p:h'), l:status) endfunction function! go#lint#ToggleMetaLinterAutoSave() abort