Lua API to easily provide Go implementation for current type
- neovim v0.9+
- treesitter with
Go
language support - Go impl installed (could be via mason.nvim)
-- init.lua
{ 'venomlab/goimpl.nvim', tag = "0.1.0" }
Public function impl
of goimpl
module checks if file is of type Go
and then asks for interface prompt.
If everything is fine, you'll have function stubs for the desired type
The simplest way would be to just set new keybinding somewhere in "after plugins" section:
-- after/plugin/goimpl.lua
local goimpl = require("goimpl")
vim.keymap.set("n", "<leader>im", function()
if goimpl.is_go() then -- call impl if current buffer is attached to Go file
goimpl.impl()
end
end)
Better would be to add it to your LSP config on buffer attach. Example with lsp-zero.nvim:
-- after/plugin/lsp.lua
lsp_zero.on_attach(function(client, bufnr)
local opts = { buffer = bufnr, remap = false }
local goimpl = require("goimpl")
if goimpl.is_go() then -- register keybinding only if it is Go file
vim.keymap.set("n", "<leader>im", function()
goimpl.impl()
end, opts)
end
-- your other keymaps