mirror of https://github.com/ray-x/go.nvim
feature: go-enum. issue #260, gopls setting move to function local var
parent
b9c8ea1d7f
commit
1f52335ea3
@ -0,0 +1,36 @@
|
||||
local runner = require("go.runner")
|
||||
local utils = require("go.utils")
|
||||
local vfn = vim.fn
|
||||
local M = {}
|
||||
|
||||
function M.run(args)
|
||||
args = args or {}
|
||||
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
row, col = row - 1, col
|
||||
|
||||
local line = vim.api.nvim_buf_get_lines(0, row, row + 1, true)[1]
|
||||
line = line:gsub("^%s+", "") -- lstrip
|
||||
line = line:gsub("%s+", " ") -- combine spaces
|
||||
line = vim.split(line, " ")
|
||||
utils.log(line)
|
||||
local fn = vfn.expand('%:p:f')
|
||||
local cmd = { "go-enum", '-f', fn }
|
||||
local new_name = vfn.expand('%:p:r') .. "_enum.go"
|
||||
|
||||
vim.list_extend(cmd, args)
|
||||
local workfolder = vim.lsp.buf.list_workspace_folders()[1] or vfn.getcwd()
|
||||
local opts = {
|
||||
update_buffer = true,
|
||||
on_exit = function()
|
||||
vim.schedule(function()
|
||||
-- utils.restart()
|
||||
vim.cmd('e ' .. new_name)
|
||||
|
||||
end)
|
||||
end,
|
||||
}
|
||||
runner.run(cmd, opts)
|
||||
return cmd, opts
|
||||
end
|
||||
|
||||
return M
|
Loading…
Reference in New Issue