refactor(impl): change api

This commit is contained in:
Smirnov Oleksandr 2023-07-19 20:43:28 +03:00
parent 3e78f86d42
commit 263692f865
2 changed files with 12 additions and 8 deletions

View file

@ -1,9 +1,11 @@
local c = require("gopher.config").commands
local Job = require "plenary.job"
local ts_utils = require "gopher._utils.ts"
local u = require "gopher._utils" local u = require "gopher._utils"
local impl = {}
---@return string ---@return string
local function get_struct() local function get_struct()
local ts_utils = require "gopher._utils.ts"
local ns = ts_utils.get_struct_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0))) local ns = ts_utils.get_struct_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0)))
if ns == nil then if ns == nil then
u.notify("put cursor on a struct or specify a receiver", "info") u.notify("put cursor on a struct or specify a receiver", "info")
@ -18,10 +20,7 @@ local function get_struct()
return ns.name return ns.name
end end
return function(...) function impl.impl(...)
local c = require("gopher.config").config.commands
local Job = require "plenary.job"
local args = { ... } local args = { ... }
local iface, recv_name = "", "" local iface, recv_name = "", ""
local recv = get_struct() local recv = get_struct()
@ -61,7 +60,10 @@ return function(...)
args = cmd_args, args = cmd_args,
on_exit = function(data, retval) on_exit = function(data, retval)
if retval ~= 0 then if retval ~= 0 then
u.notify("command 'impl " .. unpack(cmd_args) .. "' exited with code " .. retval, "error") u.notify(
"command '" .. c.impl .. " " .. unpack(cmd_args) .. "' exited with code " .. retval,
"error"
)
return return
end end
@ -73,3 +75,5 @@ return function(...)
table.insert(res_data, 1, "") table.insert(res_data, 1, "")
vim.fn.append(pos, res_data) vim.fn.append(pos, res_data)
end end
return impl

View file

@ -5,7 +5,7 @@ local gopher = {}
gopher.setup = require("gopher.config").setup gopher.setup = require("gopher.config").setup
gopher.install_deps = require "gopher.installer" gopher.install_deps = require "gopher.installer"
gopher.impl = require "gopher.impl" gopher.impl = require("gopher.impl").impl
gopher.iferr = require("gopher.iferr").iferr gopher.iferr = require("gopher.iferr").iferr
gopher.comment = require "gopher.comment" gopher.comment = require "gopher.comment"