maxandron/goplements.nvim

github github
programming-languages-supportgolang
stars 55
issues 0
subscribers 1
forks 1
CREATED

2024-07-27

UPDATED

3 months ago


Goplements.nvim

Goplements visualizes Go struct and interface implementations.

image

✨ Features

  • Displays the implementors of an interface next to the definition.
  • Displays the interfaces implemented by a struct next to the definition.

⚡️ Requirements

  • Neovim >= 0.9.4
  • LSP with the gopls server
    • for the textDocument/implementations request
  • (optional) nvim-treesitter with the go parser installed.
    • for an unnoticeably faster experience

📦 Installation

Install the plugin with your package manager.

Lazy.nvim

{
  "maxandron/goplements.nvim",
  ft = "go",
  opts = {
    -- your configuration comes here
    -- or leave it empty to use the default settings
    -- refer to the configuration section below
  },
}

⚙️ Configuration

Default Options

local defaults = {
  -- The prefixes prepended to the type names
  prefix = {
    interface = "implemented by: ",
    struct = "implements: ",
  },
  -- Whether to display the package name along with the type name (i.e., builtins.error vs error)
  display_package = false,
  -- The namespace to use for the extmarks (no real reason to change this except for testing)
  namespace_name = "goplements",
  -- The highlight group to use (if you want to change the default colors)
  -- The default links to DiagnosticHint
  highlight = "Goplements",
}

🚀 Usage and API

The plugin is automatically enabled for Go files using an autocmd.

Three commands are provided for disabling, enabling, and toggling the plugin:

  • :GoplementEnable
  • :GoplementDisable
  • :GoplementToggle

The same commands are also available as Lua functions:

  • require("goplements").enable()
  • require("goplements").disable()
  • require("goplements").toggle()