@@ -29,7 +29,7 @@ build = function()
vim.cmd.GoInstallDeps() end, ---@type gopher.Config - opts = {}, -- required + opts = {}, } ```@@ -39,10 +39,11 @@ > [!IMPORTANT]
> > If you need more info look `:h gopher.nvim` -**Take a look at default options (might be a bit outdated, look `:h gopher.nvim-config-defaults`)** +**Take a look at default options (might be a bit outdated, look `:h gopher.nvim-config`)** ```lua require("gopher").setup { + -- log level, you might consider using DEBUG or TRACE for debugging the plugin log_level = vim.log.levels.INFO, -- timeout for running internal commands
@@ -1,16 +1,16 @@
-*gopher.nvim* +*gopher.nvim* Enhance your golang experience + +MIT License Copyright (c) 2025 Oleksandr Smirnov ============================================================================== gopher.nvim is a minimalistic plugin for Go development in Neovim written in Lua. It's not an LSP tool, the main goal of this plugin is add go tooling support in Neovim. ------------------------------------------------------------------------------- - *gopher.nvim-table-of-contents* Table of Contents - Setup....................................................|gopher.nvim-setup| - Install dependencies..............................|gopher.nvim-install-deps| - Configuration...........................................|gopher.nvim-config| + Setup..................................................|gopher.nvim-setup()| + Install dependencies..............................|gopher.nvim-dependencies| + Config..................................................|gopher.nvim-config| Commands..............................................|gopher.nvim-commands| Modify struct tags.................................|gopher.nvim-struct-tags| Auto implementation of interface methods..................|gopher.nvim-impl|@@ -19,20 +19,22 @@ Iferr....................................................|gopher.nvim-iferr|
Generate comments.....................................|gopher.nvim-comments| ------------------------------------------------------------------------------ - *gopher.nvim-setup* + *gopher.nvim-setup()* `gopher.setup`({user_config}) Setup function. This method simply merges default config with opts table. You can read more about configuration at |gopher.nvim-config| Calling this function is optional, if you ok with default settings. -See |gopher.nvim.config-defaults| +See |gopher.nvim.config| Usage ~ -`require("gopher").setup {}` (replace `{}` with your `config` table) +>lua + require("gopher").setup {} -- use default config or replace {} with your own +< Parameters ~ -{user_config} `(gopher.Config)` +{user_config} `(gopher.Config)` See |gopher.nvim-config| ------------------------------------------------------------------------------ - *gopher.nvim-install-deps* + *gopher.nvim-dependencies* `gopher.install_deps` Gopher.nvim implements most of its features using third-party tools. To install these tools, you can run `:GoInstallDeps` command@@ -44,17 +46,9 @@
============================================================================== ------------------------------------------------------------------------------ *gopher.nvim-config* -config it is the place where you can configure the plugin. -also this is optional is you're ok with default settings. -You can look at default options |gopher.nvim-config-defaults| - ------------------------------------------------------------------------------- - *gopher.nvim-config-defaults* `default_config` >lua local default_config = { - --minidoc_replace_end - -- log level, you might consider using DEBUG or TRACE for debugging the plugin ---@type number log_level = vim.log.levels.INFO,@@ -112,14 +106,17 @@
============================================================================== ------------------------------------------------------------------------------ *gopher.nvim-struct-tags* -struct-tags is utilizing the `gomodifytags` tool to add or remove tags to struct fields. + +`struct_tags` is utilizing the `gomodifytags` tool to add or remove tags to struct fields. + Usage ~ How to add/remove tags to struct fields: - ------------------------------------------------------------------------------- +1. Place cursor on the struct 2. Run `:GoTagAdd json` to add json tags to struct fields 3. Run `:GoTagRm json` to remove json tags to struct fields + +To clear all tags from struct run: `:GoTagClear` NOTE: if you dont specify the tag it will use `json` as default@@ -139,32 +136,14 @@ ID int `yaml:id`
Name string `yaml:name` } < ------------------------------------------------------------------------------- - *struct_tags.add()* - `struct_tags.add`({...}) -tags to a struct under the cursor -Parameters ~ -{...} `(string)` Tags to add to the struct fields. If not provided, it will use [config.gotag.default_tag] - ------------------------------------------------------------------------------- - *struct_tags.remove()* - `struct_tags.remove`({...}) -tags from a struct under the cursor -Parameters ~ -{...} `(string)` Tags to add to the struct fields. If not provided, it will use [config.gotag.default_tag] - ------------------------------------------------------------------------------- - *struct_tags.clear()* - `struct_tags.clear`() -all tags from a struct under the cursor - ============================================================================== ------------------------------------------------------------------------------ *gopher.nvim-impl* -impl is utilizing the `impl` tool to generate method stubs for interfaces. -Usage ~ +Integration of `impl` tool to generate method stubs for interfaces. + +Usage ~ 1. Automatically implement an interface for a struct: - Place your cursor on the struct where you want to implement the interface. - Run `:GoImpl io.Reader`@@ -214,17 +193,16 @@
You can also specify the template to use for generating the tests. See |gopher.nvim-config| More details about templates can be found at: https://github.com/cweill/gotests ------------------------------------------------------------------------------- - *gopher.nvim-gotests-named* - -You can enable named tests in the config if you prefer using named tests. -See |gopher.nvim-config|. +If you prefer named tests, you can enable them in |gopher.nvim-config|. ============================================================================== ------------------------------------------------------------------------------ *gopher.nvim-iferr* -If you're using `iferr` tool, this module provides a way to automatically insert `if err != nil` check. + +`iferr` provides a way to way to automatically insert `if err != nil` check. +If you want to change `-message` option of `iferr` tool, see |gopher.nvim-config| + Usage ~ Execute `:GoIfErr` near any `err` variable to insert the check@@ -232,9 +210,11 @@
============================================================================== ------------------------------------------------------------------------------ *gopher.nvim-comments* -Usage ~ -Execute `:GoCmt` to generate a comment for the current function/method/struct/etc on this line. + This module provides a way to generate comments for Go code. + +Usage ~ +Set cursor on line with function/method/struct/etc and run `:GoCmt` to generate a comment. vim:tw=78:ts=8:noet:ft=help:norl:
@@ -7,6 +7,7 @@ ---@param lvl? number
function utils.notify(msg, lvl) lvl = lvl or vim.log.levels.INFO vim.notify(msg, lvl, { + ---@diagnostic disable-next-line:undefined-field title = c.___plugin_name, }) log.debug(msg)@@ -28,6 +29,13 @@ table.insert(res, line)
end end return res +end + +---@param s string +---@return string +function utils.trimend(s) + local r, _ = string.gsub(s, "%s+$", "") + return r end return utils
@@ -18,6 +18,7 @@ ---@field fmt_error fun(...)
local config = { -- Name of the plugin. Prepended to log messages + ---@diagnostic disable-next-line:undefined-field name = c.___plugin_name, -- Should print the output to neovim while running
@@ -1,7 +1,9 @@
---@toc_entry Generate comments ---@tag gopher.nvim-comments ----@usage Execute `:GoCmt` to generate a comment for the current function/method/struct/etc on this line. ----@text This module provides a way to generate comments for Go code. +---@text +--- This module provides a way to generate comments for Go code. +--- +---@usage Set cursor on line with function/method/struct/etc and run `:GoCmt` to generate a comment. local ts = require "gopher._utils.ts" local log = require "gopher._utils.log"@@ -9,14 +11,14 @@ local comment = {}
---@param name string ---@return string ----@private +---@dochide local function template(name) return "// " .. name .. " " end ---@param bufnr integer ---@return string ----@private +---@dochide local function generate(bufnr) local s_ok, s_res = pcall(ts.get_struct_under_cursor, bufnr) if s_ok then
@@ -1,17 +1,9 @@
----@toc_entry Configuration ----@tag gopher.nvim-config ----@text config it is the place where you can configure the plugin. ---- also this is optional is you're ok with default settings. ---- You can look at default options |gopher.nvim-config-defaults| - ----@type gopher.Config ----@private local config = {} ---@tag gopher.nvim-config.ConfigGoTagTransform ---@text Possible values for |gopher.Config|.gotag.transform: --- ----@private +---@dochide ---@alias gopher.ConfigGoTagTransform ---| "snakecase" "GopherUser" -> "gopher_user" ---| "camelcase" "GopherUser" -> "gopherUser"@@ -20,15 +12,11 @@ ---| "pascalcase" "GopherUser" -> "GopherUser"
---| "titlecase" "GopherUser" -> "Gopher User" ---| "keep" keeps the original field name ---minidoc_replace_start { - ----@tag gopher.nvim-config-defaults +---@toc_entry Config +---@tag gopher.nvim-config ---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section) ---- ---@class gopher.Config local default_config = { - --minidoc_replace_end - -- log level, you might consider using DEBUG or TRACE for debugging the plugin ---@type number log_level = vim.log.levels.INFO,@@ -73,7 +61,7 @@ }
--minidoc_afterlines_end ---@type gopher.Config ----@private +---@dochide local _config = default_config -- I am kinda secret so don't tell anyone about me even dont use me@@ -84,7 +72,7 @@ ---@private
_config.___plugin_name = "gopher.nvim" ---@diagnostic disable-line: inject-field ---@param user_config? gopher.Config ----@private +---@dochide function config.setup(user_config) vim.validate { user_config = { user_config, "table", true } }@@ -117,6 +105,6 @@ return _config[key]
end, }) +---@dochide ---@return gopher.Config ----@private return config
@@ -15,11 +15,7 @@ ---
--- You can also specify the template to use for generating the tests. See |gopher.nvim-config| --- More details about templates can be found at: https://github.com/cweill/gotests --- - ----@tag gopher.nvim-gotests-named ----@text ---- You can enable named tests in the config if you prefer using named tests. ---- See |gopher.nvim-config|. +--- If you prefer named tests, you can enable them in |gopher.nvim-config|. local c = require "gopher.config" local ts_utils = require "gopher._utils.ts"@@ -29,7 +25,7 @@ local log = require "gopher._utils.log"
local gotests = {} ---@param args table ----@private +---@dochide local function add_test(args) if c.gotests.named then table.insert(args, "-named")
@@ -1,6 +1,11 @@
+-- Thanks https://github.com/koron/iferr for vim implementation + ---@toc_entry Iferr ---@tag gopher.nvim-iferr ----@text If you're using `iferr` tool, this module provides a way to automatically insert `if err != nil` check. +---@text +--- `iferr` provides a way to way to automatically insert `if err != nil` check. +--- If you want to change `-message` option of `iferr` tool, see |gopher.nvim-config| +--- ---@usage Execute `:GoIfErr` near any `err` variable to insert the check local c = require "gopher.config"@@ -9,7 +14,6 @@ local r = require "gopher._utils.runner"
local log = require "gopher._utils.log" local iferr = {} --- That's Lua implementation: https://github.com/koron/iferr function iferr.iferr() local curb = vim.fn.wordcount().cursor_bytes local pos = vim.fn.getcurpos()[2]
@@ -1,8 +1,9 @@
---@toc_entry Auto implementation of interface methods ---@tag gopher.nvim-impl ----@text impl is utilizing the `impl` tool to generate method stubs for interfaces. ----@usage ---- 1. Automatically implement an interface for a struct: +---@text +--- Integration of `impl` tool to generate method stubs for interfaces. +--- +---@usage 1. Automatically implement an interface for a struct: --- - Place your cursor on the struct where you want to implement the interface. --- - Run `:GoImpl io.Reader` --- - This will automatically determine the receiver and implement the `io.Reader` interface.
@@ -1,12 +1,13 @@
---- *gopher.nvim* +--- *gopher.nvim* Enhance your golang experience +--- +--- MIT License Copyright (c) 2025 Oleksandr Smirnov --- --- ============================================================================== --- --- gopher.nvim is a minimalistic plugin for Go development in Neovim written in Lua. --- It's not an LSP tool, the main goal of this plugin is add go tooling support in Neovim. - +--- --- Table of Contents ----@tag gopher.nvim-table-of-contents ---@toc local log = require "gopher._utils.log"@@ -16,14 +17,16 @@ local gocmd = require("gopher._utils.gocmd").run
local gopher = {} ---@toc_entry Setup ----@tag gopher.nvim-setup +---@tag gopher.nvim-setup() ---@text Setup function. This method simply merges default config with opts table. --- You can read more about configuration at |gopher.nvim-config| --- Calling this function is optional, if you ok with default settings. ---- See |gopher.nvim.config-defaults| +--- See |gopher.nvim.config| --- ----@usage `require("gopher").setup {}` (replace `{}` with your `config` table) ----@param user_config gopher.Config +---@usage >lua +--- require("gopher").setup {} -- use default config or replace {} with your own +--- < +---@param user_config gopher.Config See |gopher.nvim-config| gopher.setup = function(user_config) log.debug "setting up config" require("gopher.config").setup(user_config)@@ -31,7 +34,7 @@ log.debug(vim.inspect(user_config))
end ---@toc_entry Install dependencies ----@tag gopher.nvim-install-deps +---@tag gopher.nvim-dependencies ---@text Gopher.nvim implements most of its features using third-party tools. --- To install these tools, you can run `:GoInstallDeps` command --- or call `require("gopher").install_deps()` if you want to use lua api.
@@ -30,4 +30,8 @@
return lines end +hooks.sections["@dochide"] = function(s) + s.parent:clear_lines() +end + MiniDoc.generate(files, "doc/gopher.nvim.txt", { hooks = hooks })
@@ -1,15 +1,6 @@
local t = require "spec.testutils" -local child = MiniTest.new_child_neovim() -local T = MiniTest.new_set { - hooks = { - post_once = child.stop, - pre_case = function() - child.restart { "-u", t.mininit_path } - end, - }, -} +local _, T = t.setup "utils" -T["utils"] = MiniTest.new_set() T["utils"]["should .remove_empty_lines()"] = function() local u = require "gopher._utils" local inp = { "hi", "", "a", "", "", "asdf" }@@ -24,6 +15,11 @@ local u = require "gopher._utils"
t.writefile(tmp, data) t.eq(u.readfile_joined(tmp), data) +end + +T["utils"]["should .trimend()"] = function() + local u = require "gopher._utils" + t.eq(u.trimend " hi ", " hi") end return T