From b30b3533e46ad7f31180852ab60b563da1a9bb94 Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Sat, 17 Aug 2024 12:33:40 -0700 Subject: [PATCH] handle multiple code action commands Handle multiple code action commands that are being returned when trying to use refactor.rewrite for fillstruct when the struct being filled results in gopls providing that commannd and a command to split the line into multiple lines. --- autoload/go/lsp.vim | 15 +++++++++------ scripts/lint | 6 +++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/autoload/go/lsp.vim b/autoload/go/lsp.vim index c76375801d..72f02565ac 100644 --- a/autoload/go/lsp.vim +++ b/autoload/go/lsp.vim @@ -1639,7 +1639,7 @@ function! go#lsp#Imports() abort let l:lsp = s:lspfactory.get() let l:state = s:newHandlerState('') - let l:handler = go#promise#New(function('s:handleCodeAction', ['source.organizeImports', ''], l:state), 10000, '') + let l:handler = go#promise#New(function('s:handleCodeAction', ['source.organizeImports', '', ''], l:state), 10000, '') let l:state.handleResult = l:handler.wrapper let l:state.error = l:handler.wrapper let l:state.handleError = function('s:handleCodeActionError', [l:fname], l:state) @@ -1663,7 +1663,7 @@ function! go#lsp#FillStruct() abort let l:lsp = s:lspfactory.get() let l:state = s:newHandlerState('') - let l:handler = go#promise#New(function('s:handleCodeAction', ['refactor.rewrite', 'apply_fix'], l:state), 10000, '') + let l:handler = go#promise#New(function('s:handleCodeAction', ['refactor.rewrite', 'apply_fix', 'fillstruct'], l:state), 10000, '') let l:state.handleResult = l:handler.wrapper let l:state.error = l:handler.wrapper let l:state.handleError = function('s:handleCodeActionError', [l:fname], l:state) @@ -1689,7 +1689,7 @@ function! go#lsp#Extract(line1, line2) abort let l:lsp = s:lspfactory.get() let l:state = s:newHandlerState('') - let l:handler = go#promise#New(function('s:handleCodeAction', ['refactor.extract', 'apply_fix'], l:state), 10000, '') + let l:handler = go#promise#New(function('s:handleCodeAction', ['refactor.extract', 'apply_fix', ''], l:state), 10000, '') let l:state.handleResult = l:handler.wrapper let l:state.error = l:handler.wrapper let l:state.handleError = function('s:handleCodeActionError', [l:fname], l:state) @@ -1818,7 +1818,7 @@ function! s:handleFormat(msg) abort dict call s:applyTextEdits(bufnr(''), a:msg) endfunction -function! s:handleCodeAction(kind, cmd, msg) abort dict +function! s:handleCodeAction(kind, cmd, fix, msg) abort dict if type(a:msg) is type('') call self.handleError(a:msg) return @@ -1829,14 +1829,17 @@ function! s:handleCodeAction(kind, cmd, msg) abort dict endif for l:item in a:msg - if get(l:item, 'kind', '') is a:kind + " TODO(bc): always pass in exactly the right kind and remove the fix + " paramter entirely after + " https://github.com/golang/go/issues/68791 is merged and released. + if get(l:item, 'kind', '') is a:kind || l:item.kind is printf('%s.%s', kind, fix) if has_key(l:item, 'disabled') && get(l:item.disabled, 'reason', '') isnot '' call go#util#EchoWarning(printf('code action is disabled: %s', l:item.disabled.reason)) continue endif if has_key(l:item, 'command') - if has_key(l:item.command, 'command') && (l:item.command.command is a:cmd || l:item.command.command is printf('gopls.%s', a:cmd)) + if has_key(l:item['command'], 'command') && (l:item.command.command is a:cmd || (l:item.command.command is printf('gopls.%s', a:cmd) && (a:fix is '' || (has_key(l:item.command.arguments, 'Fix') && a:fix == l:item.command.arguments.Fix)))) call s:executeCommand(l:item.command.command, l:item.command.arguments) continue endif diff --git a/scripts/lint b/scripts/lint index 924bb96e8d..73d6efe6bb 100755 --- a/scripts/lint +++ b/scripts/lint @@ -54,9 +54,9 @@ lint=$(sh "$vimdir/share/vim/vimgo/pack/vim-go/start/vim-vimlint/bin/vimlint.sh" -c func_abort=1 \ -e EVL110=1 -e EVL103=1 -e EVL104=1 -e EVL102=1 \ "$vimgodir" \ - 2>&1) -result="$?" -if [ "$result" -eq "2" ]; then + 2>&1 ||:) +if [ -n "$lint" ]; then + echo "FAILED" echo "$lint" echo failed=6