Skip to content

AEKDA/minimock.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

minimock.nvim

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.

Requirements

  1. Neovim >= 0.9.0

  2. minimock CLI tool installed and available in your $PATH.

  3. Treesitter with the Go parser installed.

    :TSInstall go

Installation

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
}

Usage

  1. Open a Go file.

  2. Place your cursor anywhere inside an interface definition:

    type MyService interface {
        // cursor can be here
        DoSomething(ctx context.Context) error
    }
  3. Press your hotkey (e.g., <leader>cp).

  4. A floating window will appear with the suggested output path.

    • Default behavior: It creates a mocks/ subfolder inside the current package directory.
  5. Press Enter to confirm or edit the path if necessary.

⚙️ How it works

When triggered, the plugin:

  1. Parses the AST to find the interface name (MyService).

  2. Locates go.mod to determine the module name (gitlab.com/my/repo).

  3. Calculates the relative path of the current file (internal/services/sender).

  4. 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

📜 License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages