4 files changed,
30 insertions(+),
1 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed by:
GitHub
noreply@github.com
Committed at:
2026-02-28 17:54:08 +0200
Parent:
52cb8fa
M
lua/gopher/impl.lua
@@ -45,6 +45,7 @@ local args = { ... }
local iface, recv = "", "" local bufnr = vim.api.nvim_get_current_buf() + local append_after = nil if #args == 0 then u.notify("arguments not provided. usage: :GoImpl f *File io.Reader", vim.log.levels.ERROR) return@@ -52,10 +53,12 @@ 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 + append_after = st.end_ elseif #args == 2 then -- :GoImpl w io.Writer local st = ts_utils.get_struct_under_cursor(bufnr) iface = args[2] recv = args[1] .. " *" .. st.name + append_after = st.end_ elseif #args == 3 then -- :GoImpl r Struct io.Reader recv = args[1] .. " *" .. args[2] iface = args[3]@@ -70,7 +73,7 @@ if rs.code ~= 0 then
error("failed to implement interface: " .. rs.stderr) end - local pos = vim.fn.getcurpos()[2] + local pos = append_after or vim.fn.getcurpos()[2] local output = u.remove_empty_lines(vim.split(rs.stdout, "\n")) table.insert(output, 1, "")
A
spec/fixtures/impl/struct_input.go
@@ -0,0 +1,6 @@
+package main + +type StructTest struct { + someField int + otherField string +}
A
spec/fixtures/impl/struct_output.go
@@ -0,0 +1,10 @@
+package main + +type StructTest2 struct { + someField int + otherField string +} + +func (s *StructTest2) Write(p []byte) (n int, err error) { + panic("not implemented") // TODO: Implement +}
M
spec/integration/impl_test.lua
@@ -32,4 +32,14 @@ t.eq(t.readfile(rs.tmp), rhs)
t.cleanup(rs) end +impl["should append the implementation after struct declaration"] = function() + local rs = t.setup_test("impl/struct", child, { 3, 6 }) + child.cmd "GoImpl s io.Writer" + child.cmd "write" + + local rhs = rs.fixtures.output:gsub("Test2", "Test") + t.eq(t.readfile(rs.tmp), rhs) + t.cleanup(rs) +end + return T