From d1eed0f61821c7516a0f59113a59e1f8ac2247f0 Mon Sep 17 00:00:00 2001 From: Iraq Jaber Date: Sat, 11 May 2024 10:23:41 +0100 Subject: [PATCH 1/3] made change to close qf windown when same command is run again and all issues fixed --- lua/go/asyncmake.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/go/asyncmake.lua b/lua/go/asyncmake.lua index c2108a209..55cac1135 100644 --- a/lua/go/asyncmake.lua +++ b/lua/go/asyncmake.lua @@ -369,6 +369,8 @@ M.runjob = function(cmd, runner, args, efm) } end vim.fn.setqflist({}, ' ', opts) + elseif vim.fn.getqflist({ title = 0 }).title == cmdstr then + vim.api.nvim_command([[:cclose]]) end if tonumber(data) ~= 0 then From de03495d9da0448aefaa6c03cf3a5fd55ba5a20e Mon Sep 17 00:00:00 2001 From: Iraq Jaber Date: Sun, 12 May 2024 09:22:08 +0100 Subject: [PATCH 2/3] fixup! made change to close qf windown when same command is run again and all issues fixed --- lua/go/asyncmake.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/go/asyncmake.lua b/lua/go/asyncmake.lua index 55cac1135..e95d9b8e3 100644 --- a/lua/go/asyncmake.lua +++ b/lua/go/asyncmake.lua @@ -370,6 +370,7 @@ M.runjob = function(cmd, runner, args, efm) end vim.fn.setqflist({}, ' ', opts) elseif vim.fn.getqflist({ title = 0 }).title == cmdstr then + vim.fn.setqflist({}, ' ', {lines = {}}) vim.api.nvim_command([[:cclose]]) end From 3af44a7d8abc02779ffed2a6db312ad81278c609 Mon Sep 17 00:00:00 2001 From: Iraq Jaber Date: Tue, 19 Nov 2024 15:23:50 +0800 Subject: [PATCH 3/3] adding range to tag commands --- lua/go/commands.lua | 16 +++++++----- lua/go/tags.lua | 59 +++++++++++++++++++++++++++------------------ 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/lua/go/commands.lua b/lua/go/commands.lua index e3e8075e4..6a05c1538 100644 --- a/lua/go/commands.lua +++ b/lua/go/commands.lua @@ -308,16 +308,20 @@ return { nargs = '*', }) create_cmd('GoAddTag', function(opts) - require('go.tags').add(unpack(opts.fargs)) + require('go.tags').add(opts) end, { complete = function(a, l) return package.loaded.go.add_tags_complete(a, l) end, nargs = '*', + range = true, }) create_cmd('GoRmTag', function(opts) - require('go.tags').rm(unpack(opts.fargs)) - end, { nargs = '*' }) + require('go.tags').rm(opts) + end, { + nargs = '*', + range = true, + }) create_cmd('GoImpl', function(opts) require('go.impl').run(unpack(opts.fargs)) end, { @@ -365,9 +369,9 @@ return { require('go.install').update_all() end) - create_cmd('GoClearTag', function(_) - require('go.tags').clear() - end) + create_cmd('GoClearTag', function(opts) + require('go.tags').clear(opts) + end, { range = true }) create_cmd('GoCmt', function(_) require('go.comment').gen() end) diff --git a/lua/go/tags.lua b/lua/go/tags.lua index 27b7bc01f..0d9fc9eee 100644 --- a/lua/go/tags.lua +++ b/lua/go/tags.lua @@ -14,27 +14,40 @@ local gomodify = 'gomodifytags' local transform = _GO_NVIM_CFG.tag_transform local options = _GO_NVIM_CFG.tag_options -tags.modify = function(...) +tags.modify = function(cmd, opts) require('go.install').install(gomodify) local fname = vim.fn.expand('%') -- %:p:h ? %:p - local ns = require('go.ts.go').get_struct_node_at_pos() - if utils.empty(ns) then - return - end - - -- vim.notify("parnode" .. vim.inspect(ns), vim.log.levels.DEBUG) - local struct_name = ns.name local setup = { gomodify, '-format', 'json', '-file', fname, '-w' } - if struct_name == nil then - local _, csrow, _, _ = unpack(vim.fn.getpos('.')) + if opts and opts.line1 ~= opts.line2 then + local lines + for i = opts.line1, opts.line2 do + if not lines then + lines = i + else + lines = lines .. "," .. i + end + end table.insert(setup, '-line') - table.insert(setup, csrow) + table.insert(setup, lines) else - table.insert(setup, '-struct') - table.insert(setup, struct_name) + local ns = require('go.ts.go').get_struct_node_at_pos() + if utils.empty(ns) then + return + end + -- vim.notify("parnode" .. vim.inspect(ns), vim.log.levels.DEBUG) + local struct_name = ns.name + + if struct_name == nil then + local _, csrow, _, _ = unpack(vim.fn.getpos('.')) + table.insert(setup, '-line') + table.insert(setup, csrow) + else + table.insert(setup, '-struct') + table.insert(setup, struct_name) + end end - local arg = { ... } + local arg = { unpack(cmd) } local transflg = false local optsflg = false local optidx @@ -96,14 +109,14 @@ tags.modify = function(...) end -- e.g {"json,xml", "-transform", "camelcase"} -tags.add = function(...) +tags.add = function(opts) local cmd = { '-add-tags' } - local arg = { ... } + local arg = { unpack(opts.fargs) } if #arg == 0 then arg = { 'json' } end - local tg = select(1, ...) + local tg = select(1, args) if tg == '-transform' then table.insert(cmd, 'json') end @@ -113,24 +126,24 @@ tags.add = function(...) end log(cmd) - tags.modify(unpack(cmd)) + tags.modify(cmd, opts) end -tags.rm = function(...) +tags.rm = function(opts) local cmd = { '-remove-tags' } - local arg = { ... } + local arg = { unpack(opts.fargs) } if #arg == 0 then arg = { 'json' } end for _, v in ipairs(arg) do table.insert(cmd, v) end - tags.modify(unpack(cmd)) + tags.modify(cmd, opts) end -tags.clear = function() +tags.clear = function(opts) local cmd = { '-clear-tags' } - tags.modify(unpack(cmd)) + tags.modify(cmd, opts) end return tags