fixplurals

pull/121/head
ray-x 2 years ago
parent ab864c4c17
commit 54df0e9994

@ -172,7 +172,6 @@ The following go binaries are used in `go.nvim` (depends on your setup):
- iferr
- impl
- fillstruct
- fixplurals
- fillswitch
- dlv
- ginkgo

@ -117,7 +117,6 @@ function go.setup(cfg)
[[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoTest lua require('go.gotest').test(<f-args>)]]
)
vim.cmd(
[[command! -nargs=* -complete=custom,v:lua.package.loaded.go.package_complete GoCoverage lua require'go.coverage'.run(<f-args>)]]
)
@ -168,7 +167,7 @@ function go.setup(cfg)
vim.cmd([[command! GoIfErr lua require("go.iferr").run()]])
vim.cmd([[command! GoFillStruct lua require("go.reftool").fillstruct()]])
vim.cmd([[command! GoFillSwitch lua require("go.reftool").fillswitch()]])
vim.cmd([[command! GoFixPlurals lua require("go.reftool").fixplurals()]])
vim.cmd([[command! GoFixPlurals lua require("go.fixplurals").fixplurals()]])
vim.cmd([[command! -bang GoAlt lua require"go.alternate".switch("<bang>"=="!", '')]])
vim.cmd([[command! -bang GoAltV lua require"go.alternate".switch("<bang>"=="!", 'vsplit')]])
@ -197,9 +196,7 @@ function go.setup(cfg)
end
if _GO_NVIM_CFG.run_in_floaterm then
vim.cmd(
[[command! -nargs=* GoTermClose lua require("go.term").close()]]
)
vim.cmd([[command! -nargs=* GoTermClose lua require("go.term").close()]])
end
if _GO_NVIM_CFG.lsp_cfg then

@ -0,0 +1,40 @@
-- lua implementation of the fixplurals
local ts_utils = require("nvim-treesitter.ts_utils")
local info = require("go.utils").info
local get_node_text = vim.treesitter.query.get_node_text
function fixplurals()
local n = ts_utils.get_node_at_cursor()
local p = n:parent()
if p:type() ~= "parameter_declaration" then
return info("not in parameter declaration")
end
if p:named_child_count() ~= 2 then
return info("no plural parameter")
end
local type_node = p:named_child(1)
local type = get_node_text(type_node, 0)
local edits = {}
while ts_utils.get_next_node(p) ~= nil do
local next_node = ts_utils.get_next_node(p)
if next_node:type() == "parameter_declaration" then
local type_node2 = p:named_child(1)
local type_next = get_node_text(type_node2, 0)
if type == type_next then
local range1 = ts_utils.node_to_lsp_range(type_node2)
range1["start"]["character"] = range1["start"]["character"] - 1
local edit1 = { range = range1, newText = "" }
table.insert(edits, edit1)
end
p = next_node
else
break
end
end
if #edits == 0 then
return info("no plural parameter")
end
vim.lsp.util.apply_text_edits(edits, 0, "utf-8")
end
return { fixplurals = fixplurals }

@ -77,27 +77,6 @@ function reftool.fillstruct()
end
end
function reftool.fixplurals()
local fx = "fixplurals"
require("go.install").install(fx)
local curdir = fn.getcwd()
local filedir = fn.expand("%:p:h")
local setup = { fx, "." }
local cdpkg = string.format("cd %s", filedir)
local cdback = string.format("cd %s", curdir)
vim.cmd(cdpkg)
local d = vim.fn.systemlist(setup)
log(d)
vim.cmd(cdback)
-- vim.fn.jobstart(setup, {
-- on_stdout = function(jobid, data, event)
-- vim.cmd(cdback)
-- log(setup, data)
-- end,
-- })
end
reftool.fillswitch = function()
fill("fillswitch")
end

Loading…
Cancel
Save