fix(impl): not error if no args provided (#110)

* fix(impl): handle case with no arguments provided

* fix(config): validate missing field
This commit is contained in:
Smirnov Oleksandr 2025-04-03 16:52:38 +03:00 committed by GitHub
parent 9d28cdebf1
commit 9db5931af1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View file

@ -84,6 +84,7 @@ function config.setup(user_config)
vim.validate { vim.validate {
log_level = { _config.log_level, "number" }, log_level = { _config.log_level, "number" },
timeout = { _config.timeout, "number" }, timeout = { _config.timeout, "number" },
installer_timeout = { _config.installer_timeout, "number" },
["commands"] = { _config.commands, "table" }, ["commands"] = { _config.commands, "table" },
["commands.go"] = { _config.commands.go, "string" }, ["commands.go"] = { _config.commands.go, "string" },
["commands.gomodifytags"] = { _config.commands.gomodifytags, "string" }, ["commands.gomodifytags"] = { _config.commands.gomodifytags, "string" },

View file

@ -44,7 +44,10 @@ function impl.impl(...)
local iface, recv = "", "" local iface, recv = "", ""
local bufnr = vim.api.nvim_get_current_buf() local bufnr = vim.api.nvim_get_current_buf()
if #args == 1 then -- :GoImpl io.Reader if #args == 0 then
u.notify("arguments not provided. usage: :GoImpl f *File io.Reader", vim.log.levels.ERROR)
return
elseif #args == 1 then -- :GoImpl io.Reader
local st = ts_utils.get_struct_under_cursor(bufnr) local st = ts_utils.get_struct_under_cursor(bufnr)
iface = args[1] iface = args[1]
recv = string.lower(st.name) .. " *" .. st.name recv = string.lower(st.name) .. " *" .. st.name
@ -57,7 +60,11 @@ function impl.impl(...)
iface = args[3] iface = args[3]
end end
local rs = r.sync { c.impl, "-dir", vim.fn.fnameescape(vim.fn.expand "%:p:h"), recv, iface } assert(iface ~= "", "interface not provided")
assert(recv ~= "", "receiver not provided")
local dir = vim.fn.fnameescape(vim.fn.expand "%:p:h")
local rs = r.sync { c.impl, "-dir", dir, recv, iface }
if rs.code ~= 0 then if rs.code ~= 0 then
error("failed to implement interface: " .. rs.stderr) error("failed to implement interface: " .. rs.stderr)
end end