From 9db5931af1293ae52500921d92c02145d86df02c Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Thu, 3 Apr 2025 16:52:38 +0300 Subject: [PATCH] fix(impl): not error if no args provided (#110) * fix(impl): handle case with no arguments provided * fix(config): validate missing field --- lua/gopher/config.lua | 1 + lua/gopher/impl.lua | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lua/gopher/config.lua b/lua/gopher/config.lua index b8e4a15..b8f291e 100644 --- a/lua/gopher/config.lua +++ b/lua/gopher/config.lua @@ -84,6 +84,7 @@ function config.setup(user_config) vim.validate { log_level = { _config.log_level, "number" }, timeout = { _config.timeout, "number" }, + installer_timeout = { _config.installer_timeout, "number" }, ["commands"] = { _config.commands, "table" }, ["commands.go"] = { _config.commands.go, "string" }, ["commands.gomodifytags"] = { _config.commands.gomodifytags, "string" }, diff --git a/lua/gopher/impl.lua b/lua/gopher/impl.lua index 702d58e..b8b115a 100644 --- a/lua/gopher/impl.lua +++ b/lua/gopher/impl.lua @@ -44,7 +44,10 @@ function impl.impl(...) local iface, recv = "", "" 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) iface = args[1] recv = string.lower(st.name) .. " *" .. st.name @@ -57,7 +60,11 @@ function impl.impl(...) iface = args[3] 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 error("failed to implement interface: " .. rs.stderr) end