From 6bdba9e1f3c7bd4ea8e7ab2c95c914cd927e4cd6 Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 22 Mar 2024 23:01:37 +1100 Subject: [PATCH] revert removing fillstruct as some gopls user saw issues --- lua/go/commands.lua | 2 +- lua/go/install.lua | 1 + lua/go/lsp.lua | 2 +- lua/go/reftool.lua | 19 ++++++++++++++++--- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lua/go/commands.lua b/lua/go/commands.lua index 04cedab..b93b4f7 100644 --- a/lua/go/commands.lua +++ b/lua/go/commands.lua @@ -375,7 +375,7 @@ return { require('go.iferr').run() end) create_cmd('GoFillStruct', function(_) - require('go.lsp').codeaction('apply_fix', 'refactor.rewrite') + require('go.reftool').fillstruct() end) create_cmd('GoFillSwitch', function(_) require('go.reftool').fillswitch() diff --git a/lua/go/install.lua b/lua/go/install.lua index 036419c..f35ff1a 100644 --- a/lua/go/install.lua +++ b/lua/go/install.lua @@ -16,6 +16,7 @@ local url = { callgraph = 'golang.org/x/tools/cmd/callgraph', guru = 'golang.org/x/tools/cmd/guru', impl = 'github.com/josharian/impl', + fillstruct = 'github.com/davidrjenni/reftools/cmd/fillstruct', fillswitch = 'github.com/davidrjenni/reftools/cmd/fillswitch', dlv = 'github.com/go-delve/delve/cmd/dlv', ginkgo = 'github.com/onsi/ginkgo/v2/ginkgo', diff --git a/lua/go/lsp.lua b/lua/go/lsp.lua index 5b227d5..de18b1f 100644 --- a/lua/go/lsp.lua +++ b/lua/go/lsp.lua @@ -257,7 +257,7 @@ write", "source", "source.organizeImports" } -- action / fix to take -- only gopls M.codeaction = function(gopls_cmd, only, hdlr) - hdlr = hdlr or function () end + hdlr = hdlr or function() end local params = vim.lsp.util.make_range_params() if not gopls_cmd:find('gopls') then gopls_cmd = 'gopls.' .. gopls_cmd diff --git a/lua/go/reftool.lua b/lua/go/reftool.lua index 1a69d8e..a77af20 100644 --- a/lua/go/reftool.lua +++ b/lua/go/reftool.lua @@ -30,9 +30,9 @@ end -- can only be fillstruct and fillswitch local function fill(cmd) - if cmd ~= 'fillswitch' then - log(cmd, 'not found') - error('cmd not supported by go.nvim', cmd) + if vim.tbl_contains({ 'fillstruct', 'fillswitch' }, cmd) == false then + error('reftool fill cmd not supported: ' .. cmd) + return end require('go.install').install(cmd) @@ -62,6 +62,19 @@ local function fill(cmd) }) end +local function gopls_fillstruct() + log('fill struct with gopls') + require('go.lsp').codeaction('apply_fix', 'refactor.rewrite') +end + +function reftool.fillstruct() + if _GO_NVIM_CFG.fillstruct == 'gopls' then + gopls_fillstruct() + else + fill('fillstruct') + end +end + reftool.fillswitch = function() fill('fillswitch') end