A Neovim plugin to generate Go mocks using minimock directly from your editor.
It eliminates the need to manually type long CLI commands by automatically detecting the interface, package, and module context using Treesitter.
-
Neovim >= 0.9.0
-
minimock CLI tool installed and available in your
$PATH. -
Treesitter with the Go parser installed.
:TSInstall go
Using lazy.nvim
return {
"AEKDA/minimock.nvim",
dependencies = {
"MunifTanjim/nui.nvim",
"nvim-treesitter/nvim-treesitter",
},
keys = {
{
"<leader>cp",
function()
require("minimock").generate_mock()
end,
desc = "Generate Minimock",
mode = "n",
},
},
-- Optional: if you want to use the setup function
config = function()
require("minimock").setup()
end
}-
Open a Go file.
-
Place your cursor anywhere inside an interface definition:
type MyService interface { // cursor can be here DoSomething(ctx context.Context) error }
-
Press your hotkey (e.g.,
<leader>cp). -
A floating window will appear with the suggested output path.
- Default behavior: It creates a
mocks/subfolder inside the current package directory.
- Default behavior: It creates a
-
Press Enter to confirm or edit the path if necessary.
When triggered, the plugin:
-
Parses the AST to find the interface name (
MyService). -
Locates
go.modto determine the module name (gitlab.com/my/repo). -
Calculates the relative path of the current file (
internal/services/sender). -
Constructs the command:
minimock -i gitlab.com/my/repo/internal/services/sender.MyService \ -o internal/services/sender/mocks/my_service_mock.go \ -n MyServiceMock \ -p mocks
MIT