docs: update
This commit is contained in:
parent
3b01af99c1
commit
0c0584edbd
9 changed files with 83 additions and 95 deletions
|
|
@ -39,7 +39,7 @@ Requirements:
|
||||||
>
|
>
|
||||||
> If you need more info look `:h gopher.nvim`
|
> 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
|
```lua
|
||||||
require("gopher").setup {
|
require("gopher").setup {
|
||||||
|
|
|
||||||
|
|
@ -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.
|
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.
|
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
|
Table of Contents
|
||||||
Setup....................................................|gopher.nvim-setup|
|
Setup..................................................|gopher.nvim-setup()|
|
||||||
Install dependencies..............................|gopher.nvim-install-deps|
|
Install dependencies..............................|gopher.nvim-dependencies|
|
||||||
Configuration...........................................|gopher.nvim-config|
|
Config..................................................|gopher.nvim-config|
|
||||||
Commands..............................................|gopher.nvim-commands|
|
Commands..............................................|gopher.nvim-commands|
|
||||||
Modify struct tags.................................|gopher.nvim-struct-tags|
|
Modify struct tags.................................|gopher.nvim-struct-tags|
|
||||||
Auto implementation of interface methods..................|gopher.nvim-impl|
|
Auto implementation of interface methods..................|gopher.nvim-impl|
|
||||||
|
|
@ -19,20 +19,22 @@ Table of Contents
|
||||||
Generate comments.....................................|gopher.nvim-comments|
|
Generate comments.....................................|gopher.nvim-comments|
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*gopher.nvim-setup*
|
*gopher.nvim-setup()*
|
||||||
`gopher.setup`({user_config})
|
`gopher.setup`({user_config})
|
||||||
Setup function. This method simply merges default config with opts table.
|
Setup function. This method simply merges default config with opts table.
|
||||||
You can read more about configuration at |gopher.nvim-config|
|
You can read more about configuration at |gopher.nvim-config|
|
||||||
Calling this function is optional, if you ok with default settings.
|
Calling this function is optional, if you ok with default settings.
|
||||||
See |gopher.nvim.config-defaults|
|
See |gopher.nvim.config|
|
||||||
|
|
||||||
Usage ~
|
Usage ~
|
||||||
`require("gopher").setup {}` (replace `{}` with your `config` table)
|
>lua
|
||||||
|
require("gopher").setup {} -- use default config or replace {} with your own
|
||||||
|
<
|
||||||
Parameters ~
|
Parameters ~
|
||||||
{user_config} `(gopher.Config)`
|
{user_config} `(gopher.Config)` See |gopher.nvim-config|
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*gopher.nvim-install-deps*
|
*gopher.nvim-dependencies*
|
||||||
`gopher.install_deps`
|
`gopher.install_deps`
|
||||||
Gopher.nvim implements most of its features using third-party tools.
|
Gopher.nvim implements most of its features using third-party tools.
|
||||||
To install these tools, you can run `:GoInstallDeps` command
|
To install these tools, you can run `:GoInstallDeps` command
|
||||||
|
|
@ -44,17 +46,9 @@ to install them synchronously pass `{sync = true}` as an argument.
|
||||||
==============================================================================
|
==============================================================================
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*gopher.nvim-config*
|
*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`
|
`default_config`
|
||||||
>lua
|
>lua
|
||||||
local default_config = {
|
local default_config = {
|
||||||
--minidoc_replace_end
|
|
||||||
|
|
||||||
-- log level, you might consider using DEBUG or TRACE for debugging the plugin
|
-- log level, you might consider using DEBUG or TRACE for debugging the plugin
|
||||||
---@type number
|
---@type number
|
||||||
log_level = vim.log.levels.INFO,
|
log_level = vim.log.levels.INFO,
|
||||||
|
|
@ -112,15 +106,18 @@ you can set `vim.g.gopher_register_commands` to `false`, before loading the plug
|
||||||
==============================================================================
|
==============================================================================
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*gopher.nvim-struct-tags*
|
*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 ~
|
Usage ~
|
||||||
|
|
||||||
How to add/remove tags to struct fields:
|
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
|
2. Run `:GoTagAdd json` to add json tags to struct fields
|
||||||
3. Run `:GoTagRm json` to remove 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
|
NOTE: if you dont specify the tag it will use `json` as default
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
@ -139,30 +136,13 @@ Example:
|
||||||
Name string `yaml:name`
|
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*
|
*gopher.nvim-impl*
|
||||||
|
|
||||||
impl is utilizing the `impl` tool to generate method stubs for interfaces.
|
impl is utilizing the `impl` tool to generate method stubs for interfaces.
|
||||||
|
|
||||||
Usage ~
|
Usage ~
|
||||||
|
|
||||||
1. Automatically implement an interface for a struct:
|
1. Automatically implement an interface for a struct:
|
||||||
|
|
@ -214,17 +194,16 @@ Usage ~
|
||||||
You can also specify the template to use for generating the tests. See |gopher.nvim-config|
|
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
|
More details about templates can be found at: https://github.com/cweill/gotests
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
If you prefer named tests, you can enable them in |gopher.nvim-config|.
|
||||||
*gopher.nvim-gotests-named*
|
|
||||||
|
|
||||||
You can enable named tests in the config if you prefer using named tests.
|
|
||||||
See |gopher.nvim-config|.
|
|
||||||
|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*gopher.nvim-iferr*
|
*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 ~
|
Usage ~
|
||||||
Execute `:GoIfErr` near any `err` variable to insert the check
|
Execute `:GoIfErr` near any `err` variable to insert the check
|
||||||
|
|
||||||
|
|
@ -232,9 +211,11 @@ Execute `:GoIfErr` near any `err` variable to insert the check
|
||||||
==============================================================================
|
==============================================================================
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*gopher.nvim-comments*
|
*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.
|
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:
|
vim:tw=78:ts=8:noet:ft=help:norl:
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
---@toc_entry Generate comments
|
---@toc_entry Generate comments
|
||||||
---@tag gopher.nvim-comments
|
---@tag gopher.nvim-comments
|
||||||
---@usage Execute `:GoCmt` to generate a comment for the current function/method/struct/etc on this line.
|
---@text
|
||||||
---@text This module provides a way to generate comments for Go code.
|
--- 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 ts = require "gopher._utils.ts"
|
||||||
local log = require "gopher._utils.log"
|
local log = require "gopher._utils.log"
|
||||||
|
|
@ -9,14 +11,14 @@ local comment = {}
|
||||||
|
|
||||||
---@param name string
|
---@param name string
|
||||||
---@return string
|
---@return string
|
||||||
---@private
|
---@dochide
|
||||||
local function template(name)
|
local function template(name)
|
||||||
return "// " .. name .. " "
|
return "// " .. name .. " "
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
---@return string
|
---@return string
|
||||||
---@private
|
---@dochide
|
||||||
local function generate(bufnr)
|
local function generate(bufnr)
|
||||||
local s_ok, s_res = pcall(ts.get_struct_under_cursor, bufnr)
|
local s_ok, s_res = pcall(ts.get_struct_under_cursor, bufnr)
|
||||||
if s_ok then
|
if s_ok then
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,11 @@
|
||||||
---@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
|
---@type gopher.Config
|
||||||
---@private
|
---@dochide
|
||||||
local config = {}
|
local config = {}
|
||||||
|
|
||||||
---@tag gopher.nvim-config.ConfigGoTagTransform
|
---@tag gopher.nvim-config.ConfigGoTagTransform
|
||||||
---@text Possible values for |gopher.Config|.gotag.transform:
|
---@text Possible values for |gopher.Config|.gotag.transform:
|
||||||
---
|
---
|
||||||
---@private
|
---@dochide
|
||||||
---@alias gopher.ConfigGoTagTransform
|
---@alias gopher.ConfigGoTagTransform
|
||||||
---| "snakecase" "GopherUser" -> "gopher_user"
|
---| "snakecase" "GopherUser" -> "gopher_user"
|
||||||
---| "camelcase" "GopherUser" -> "gopherUser"
|
---| "camelcase" "GopherUser" -> "gopherUser"
|
||||||
|
|
@ -20,15 +14,11 @@ local config = {}
|
||||||
---| "titlecase" "GopherUser" -> "Gopher User"
|
---| "titlecase" "GopherUser" -> "Gopher User"
|
||||||
---| "keep" keeps the original field name
|
---| "keep" keeps the original field name
|
||||||
|
|
||||||
--minidoc_replace_start {
|
---@toc_entry Config
|
||||||
|
---@tag gopher.nvim-config
|
||||||
---@tag gopher.nvim-config-defaults
|
|
||||||
---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section)
|
---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section)
|
||||||
---
|
|
||||||
---@class gopher.Config
|
---@class gopher.Config
|
||||||
local default_config = {
|
local default_config = {
|
||||||
--minidoc_replace_end
|
|
||||||
|
|
||||||
-- log level, you might consider using DEBUG or TRACE for debugging the plugin
|
-- log level, you might consider using DEBUG or TRACE for debugging the plugin
|
||||||
---@type number
|
---@type number
|
||||||
log_level = vim.log.levels.INFO,
|
log_level = vim.log.levels.INFO,
|
||||||
|
|
@ -73,7 +63,7 @@ local default_config = {
|
||||||
--minidoc_afterlines_end
|
--minidoc_afterlines_end
|
||||||
|
|
||||||
---@type gopher.Config
|
---@type gopher.Config
|
||||||
---@private
|
---@dochide
|
||||||
local _config = default_config
|
local _config = default_config
|
||||||
|
|
||||||
-- I am kinda secret so don't tell anyone about me even dont use me
|
-- I am kinda secret so don't tell anyone about me even dont use me
|
||||||
|
|
@ -84,7 +74,7 @@ local _config = default_config
|
||||||
_config.___plugin_name = "gopher.nvim" ---@diagnostic disable-line: inject-field
|
_config.___plugin_name = "gopher.nvim" ---@diagnostic disable-line: inject-field
|
||||||
|
|
||||||
---@param user_config? gopher.Config
|
---@param user_config? gopher.Config
|
||||||
---@private
|
---@dochide
|
||||||
function config.setup(user_config)
|
function config.setup(user_config)
|
||||||
vim.validate { user_config = { user_config, "table", true } }
|
vim.validate { user_config = { user_config, "table", true } }
|
||||||
|
|
||||||
|
|
@ -118,5 +108,5 @@ setmetatable(config, {
|
||||||
})
|
})
|
||||||
|
|
||||||
---@return gopher.Config
|
---@return gopher.Config
|
||||||
---@private
|
---@dochide
|
||||||
return config
|
return config
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,7 @@
|
||||||
--- You can also specify the template to use for generating the tests. See |gopher.nvim-config|
|
--- 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
|
--- More details about templates can be found at: https://github.com/cweill/gotests
|
||||||
---
|
---
|
||||||
|
--- If you prefer named tests, you can enable them in |gopher.nvim-config|.
|
||||||
---@tag gopher.nvim-gotests-named
|
|
||||||
---@text
|
|
||||||
--- You can enable named tests in the config if you prefer using named tests.
|
|
||||||
--- See |gopher.nvim-config|.
|
|
||||||
|
|
||||||
local c = require "gopher.config"
|
local c = require "gopher.config"
|
||||||
local ts_utils = require "gopher._utils.ts"
|
local ts_utils = require "gopher._utils.ts"
|
||||||
|
|
@ -29,7 +25,7 @@ local log = require "gopher._utils.log"
|
||||||
local gotests = {}
|
local gotests = {}
|
||||||
|
|
||||||
---@param args table
|
---@param args table
|
||||||
---@private
|
---@dochide
|
||||||
local function add_test(args)
|
local function add_test(args)
|
||||||
if c.gotests.named then
|
if c.gotests.named then
|
||||||
table.insert(args, "-named")
|
table.insert(args, "-named")
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
|
-- Thanks https://github.com/koron/iferr for vim implementation
|
||||||
|
|
||||||
---@toc_entry Iferr
|
---@toc_entry Iferr
|
||||||
---@tag gopher.nvim-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
|
---@usage Execute `:GoIfErr` near any `err` variable to insert the check
|
||||||
|
|
||||||
local c = require "gopher.config"
|
local c = require "gopher.config"
|
||||||
|
|
@ -9,7 +14,6 @@ local r = require "gopher._utils.runner"
|
||||||
local log = require "gopher._utils.log"
|
local log = require "gopher._utils.log"
|
||||||
local iferr = {}
|
local iferr = {}
|
||||||
|
|
||||||
-- That's Lua implementation: https://github.com/koron/iferr
|
|
||||||
function iferr.iferr()
|
function iferr.iferr()
|
||||||
local curb = vim.fn.wordcount().cursor_bytes
|
local curb = vim.fn.wordcount().cursor_bytes
|
||||||
local pos = vim.fn.getcurpos()[2]
|
local pos = vim.fn.getcurpos()[2]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
---@toc_entry Auto implementation of interface methods
|
---@toc_entry Auto implementation of interface methods
|
||||||
---@tag gopher.nvim-impl
|
---@tag gopher.nvim-impl
|
||||||
---@text impl is utilizing the `impl` tool to generate method stubs for interfaces.
|
---@text
|
||||||
|
--- impl is utilizing the `impl` tool to generate method stubs for interfaces.
|
||||||
|
---
|
||||||
---@usage
|
---@usage
|
||||||
--- 1. Automatically implement an interface for a struct:
|
--- 1. Automatically implement an interface for a struct:
|
||||||
--- - Place your cursor on the struct where you want to implement the interface.
|
--- - Place your cursor on the struct where you want to implement the 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.
|
--- 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.
|
--- It's not an LSP tool, the main goal of this plugin is add go tooling support in Neovim.
|
||||||
|
---
|
||||||
--- Table of Contents
|
--- Table of Contents
|
||||||
---@tag gopher.nvim-table-of-contents
|
|
||||||
---@toc
|
---@toc
|
||||||
|
|
||||||
local log = require "gopher._utils.log"
|
local log = require "gopher._utils.log"
|
||||||
|
|
@ -16,14 +17,16 @@ local gocmd = require("gopher._utils.gocmd").run
|
||||||
local gopher = {}
|
local gopher = {}
|
||||||
|
|
||||||
---@toc_entry Setup
|
---@toc_entry Setup
|
||||||
---@tag gopher.nvim-setup
|
---@tag gopher.nvim-setup()
|
||||||
---@text Setup function. This method simply merges default config with opts table.
|
---@text Setup function. This method simply merges default config with opts table.
|
||||||
--- You can read more about configuration at |gopher.nvim-config|
|
--- You can read more about configuration at |gopher.nvim-config|
|
||||||
--- Calling this function is optional, if you ok with default settings.
|
--- 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)
|
---@usage >lua
|
||||||
---@param user_config gopher.Config
|
--- 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)
|
gopher.setup = function(user_config)
|
||||||
log.debug "setting up config"
|
log.debug "setting up config"
|
||||||
require("gopher.config").setup(user_config)
|
require("gopher.config").setup(user_config)
|
||||||
|
|
@ -31,7 +34,7 @@ gopher.setup = function(user_config)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@toc_entry Install dependencies
|
---@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.
|
---@text Gopher.nvim implements most of its features using third-party tools.
|
||||||
--- To install these tools, you can run `:GoInstallDeps` command
|
--- To install these tools, you can run `:GoInstallDeps` command
|
||||||
--- or call `require("gopher").install_deps()` if you want to use lua api.
|
--- or call `require("gopher").install_deps()` if you want to use lua api.
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
---@toc_entry Modify struct tags
|
---@toc_entry Modify struct tags
|
||||||
---@tag gopher.nvim-struct-tags
|
---@tag gopher.nvim-struct-tags
|
||||||
---@text struct-tags is utilizing the `gomodifytags` tool to add or remove tags to struct fields.
|
---@text
|
||||||
|
--- `struct_tags` is utilizing the `gomodifytags` tool to add or remove tags to struct fields.
|
||||||
|
---
|
||||||
---@usage
|
---@usage
|
||||||
--- How to add/remove tags to struct fields:
|
--- How to add/remove tags to struct fields:
|
||||||
-- 1. Place cursor on the struct
|
--- 1. Place cursor on the struct
|
||||||
--- 2. Run `:GoTagAdd json` to add json tags to struct fields
|
--- 2. Run `:GoTagAdd json` to add json tags to struct fields
|
||||||
--- 3. Run `:GoTagRm json` to remove 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
|
--- NOTE: if you dont specify the tag it will use `json` as default
|
||||||
---
|
---
|
||||||
--- Example:
|
--- Example:
|
||||||
|
|
@ -35,7 +39,7 @@ local struct_tags = {}
|
||||||
---@param fpath string
|
---@param fpath string
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
---@param user_args string[]
|
---@param user_args string[]
|
||||||
---@private
|
---@dochide
|
||||||
local function handle_tags(fpath, bufnr, user_args)
|
local function handle_tags(fpath, bufnr, user_args)
|
||||||
local st = ts.get_struct_under_cursor(bufnr)
|
local st = ts.get_struct_under_cursor(bufnr)
|
||||||
|
|
||||||
|
|
@ -87,7 +91,7 @@ end
|
||||||
|
|
||||||
---@param args string[]
|
---@param args string[]
|
||||||
---@return string
|
---@return string
|
||||||
---@private
|
---@dochide
|
||||||
local function handler_user_args(args)
|
local function handler_user_args(args)
|
||||||
if #args == 0 then
|
if #args == 0 then
|
||||||
return c.gotag.default_tag
|
return c.gotag.default_tag
|
||||||
|
|
@ -95,8 +99,10 @@ local function handler_user_args(args)
|
||||||
return table.concat(args, ",")
|
return table.concat(args, ",")
|
||||||
end
|
end
|
||||||
|
|
||||||
---Adds tags to a struct under the cursor
|
-- Adds tags to a struct under the cursor
|
||||||
|
-- See |gopher.nvim-struct-tags|
|
||||||
---@param ... string Tags to add to the struct fields. If not provided, it will use [config.gotag.default_tag]
|
---@param ... string Tags to add to the struct fields. If not provided, it will use [config.gotag.default_tag]
|
||||||
|
---@dochide
|
||||||
function struct_tags.add(...)
|
function struct_tags.add(...)
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
local fpath = vim.fn.expand "%"
|
local fpath = vim.fn.expand "%"
|
||||||
|
|
@ -106,7 +112,9 @@ function struct_tags.add(...)
|
||||||
handle_tags(fpath, bufnr, { "-add-tags", user_tags })
|
handle_tags(fpath, bufnr, { "-add-tags", user_tags })
|
||||||
end
|
end
|
||||||
|
|
||||||
---Removes tags from a struct under the cursor
|
-- Removes tags from a struct under the cursor
|
||||||
|
-- See `:h gopher.nvim-struct-tags`
|
||||||
|
---@dochide
|
||||||
---@param ... string Tags to add to the struct fields. If not provided, it will use [config.gotag.default_tag]
|
---@param ... string Tags to add to the struct fields. If not provided, it will use [config.gotag.default_tag]
|
||||||
function struct_tags.remove(...)
|
function struct_tags.remove(...)
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
|
|
@ -117,7 +125,9 @@ function struct_tags.remove(...)
|
||||||
handle_tags(fpath, bufnr, { "-remove-tags", user_tags })
|
handle_tags(fpath, bufnr, { "-remove-tags", user_tags })
|
||||||
end
|
end
|
||||||
|
|
||||||
---Removes all tags from a struct under the cursor
|
-- Removes all tags from a struct under the cursor
|
||||||
|
-- See `:h gopher.nvim-struct-tags`
|
||||||
|
---@dochide
|
||||||
function struct_tags.clear()
|
function struct_tags.clear()
|
||||||
local fpath = vim.fn.expand "%"
|
local fpath = vim.fn.expand "%"
|
||||||
local bufnr = vim.api.nvim_get_current_buf()
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue