[mirror] Make your go dev experience better github.com/olexsmir/gopher.nvim
neovim golang
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(impl): append the `impl` output after the struct (#137)

authored by

Oleksandr Smirnov and committed by
GitHub
27ba078f dec6ff44

+30 -1
+4 -1
lua/gopher/impl.lua
··· 45 45 local iface, recv = "", "" 46 46 local bufnr = vim.api.nvim_get_current_buf() 47 47 48 + local append_after = nil 48 49 if #args == 0 then 49 50 u.notify("arguments not provided. usage: :GoImpl f *File io.Reader", vim.log.levels.ERROR) 50 51 return ··· 52 53 local st = ts_utils.get_struct_under_cursor(bufnr) 53 54 iface = args[1] 54 55 recv = string.lower(st.name) .. " *" .. st.name 56 + append_after = st.end_ 55 57 elseif #args == 2 then -- :GoImpl w io.Writer 56 58 local st = ts_utils.get_struct_under_cursor(bufnr) 57 59 iface = args[2] 58 60 recv = args[1] .. " *" .. st.name 61 + append_after = st.end_ 59 62 elseif #args == 3 then -- :GoImpl r Struct io.Reader 60 63 recv = args[1] .. " *" .. args[2] 61 64 iface = args[3] ··· 70 73 error("failed to implement interface: " .. rs.stderr) 71 74 end 72 75 73 - local pos = vim.fn.getcurpos()[2] 76 + local pos = append_after or vim.fn.getcurpos()[2] 74 77 local output = u.remove_empty_lines(vim.split(rs.stdout, "\n")) 75 78 76 79 table.insert(output, 1, "")
+6
spec/fixtures/impl/struct_input.go
··· 1 + package main 2 + 3 + type StructTest struct { 4 + someField int 5 + otherField string 6 + }
+10
spec/fixtures/impl/struct_output.go
··· 1 + package main 2 + 3 + type StructTest2 struct { 4 + someField int 5 + otherField string 6 + } 7 + 8 + func (s *StructTest2) Write(p []byte) (n int, err error) { 9 + panic("not implemented") // TODO: Implement 10 + }
+10
spec/integration/impl_test.lua
··· 32 32 t.cleanup(rs) 33 33 end 34 34 35 + impl["should append the implementation after struct declaration"] = function() 36 + local rs = t.setup_test("impl/struct", child, { 3, 6 }) 37 + child.cmd "GoImpl s io.Writer" 38 + child.cmd "write" 39 + 40 + local rhs = rs.fixtures.output:gsub("Test2", "Test") 41 + t.eq(t.readfile(rs.tmp), rhs) 42 + t.cleanup(rs) 43 + end 44 + 35 45 return T