add help file, and docs (#59)
* idk how good this idea is * this could be working but i still cant figure out how to run it * ignore tags that mini.doc gens, but why? * chore(taskfile): force exiting after tests because i got infinit ci * chore(ci): add more nvim versions to run on * chore: update taskfile * feat: add docs generator * docs: its only begining * refactor: update docgen script * docs: write some more * docs(config): update * docs: update readme * language * hope it would work * what about that? * maybe this would work? * update md * upd * WHY DOESNT IT WORKING * idk by but 0.9.3 just fails the ci, so i deleted it from suite * again update, why does markdown not work in embeded html * maybe it can help? * upd * again update * kinda fix * fix: formatting * again some updating * some readme updating * fix, this shouldnt be in repo * i finnaly undertood how to fix this fking skill issue * fix(struct_tags): typo * refactor(docs): change the order in generated file * docs: install deps * refactor(scripts): rename doc-gen script * docs(impl): write docs * docs(dap): add doc * stylua . * docs(struct_tags): add doc * docs(gotests): add docs * docs(iferr): add docs * docs(comment): add doc * update CONTRIBUTING.md * docs(README): talk about `develop` branch * docs: update README.md
This commit is contained in:
parent
28e1f5689f
commit
10cec9c6b0
16 changed files with 657 additions and 142 deletions
|
|
@ -1,3 +1,8 @@
|
|||
---@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.
|
||||
|
||||
local function generate(row, col)
|
||||
local ts_utils = require "gopher._utils.ts"
|
||||
local comment, ns = nil, nil
|
||||
|
|
|
|||
|
|
@ -1,6 +1,17 @@
|
|||
---@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
|
||||
---@alias gopher.ConfigGoTagTransform
|
||||
---| "snakecase" "GopherUser" -> "gopher_user"
|
||||
---| "camelcase" "GopherUser" -> "gopherUser"
|
||||
|
|
@ -9,8 +20,16 @@ local config = {}
|
|||
---| "titlecase" "GopherUser" -> "Gopher User"
|
||||
---| "keep" keeps the original field name
|
||||
|
||||
--minidoc_replace_start {
|
||||
|
||||
---@tag gopher.nvim-config-defaults
|
||||
---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section):gsub(">", ">lua")
|
||||
---
|
||||
---@class gopher.Config
|
||||
local default_config = {
|
||||
--minidoc_replace_end
|
||||
|
||||
-- user specified paths to binaries
|
||||
---@class gopher.ConfigCommand
|
||||
commands = {
|
||||
go = "go",
|
||||
|
|
@ -29,7 +48,6 @@ local default_config = {
|
|||
template_dir = nil,
|
||||
-- switch table tests from using slice to map (with test name for the key)
|
||||
-- works only with gotests installed from develop branch
|
||||
---@type boolean
|
||||
named = false,
|
||||
},
|
||||
---@class gopher.ConfigGoTag
|
||||
|
|
@ -38,8 +56,10 @@ local default_config = {
|
|||
transform = "snakecase",
|
||||
},
|
||||
}
|
||||
--minidoc_afterlines_end
|
||||
|
||||
---@type gopher.Config
|
||||
---@private
|
||||
local _config = default_config
|
||||
|
||||
---@param user_config? gopher.Config
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
---@toc_entry Setup `nvim-dap` for Go
|
||||
---@tag gopher.nvim-dap
|
||||
---@text This module sets up `nvim-dap` for Go.
|
||||
---@usage just call `require("gopher.dap").setup()`, and you're good to go.
|
||||
|
||||
local u = require "gopher._utils"
|
||||
local c = require "gopher.config"
|
||||
local dap = {}
|
||||
|
|
@ -106,7 +111,7 @@ dap.configuration = {
|
|||
},
|
||||
}
|
||||
|
||||
---setup `nvim-dap` for Go
|
||||
-- sets ups nvim-dap for Go in one function call.
|
||||
function dap.setup()
|
||||
local d = u.sreq "dap"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,44 @@
|
|||
---@toc_entry Generating unit tests boilerplate
|
||||
---@tag gopher.nvim-gotests
|
||||
---@text gotests is utilizing the `gotests` tool to generate unit tests boilerplate.
|
||||
---@usage
|
||||
--- - generate unit test for spesisfic function/method
|
||||
--- - to specift the function/method put your cursor on it
|
||||
--- - run `:GoTestAdd`
|
||||
---
|
||||
--- - generate unit tests for all functions/methods in current file
|
||||
--- - run `:GoTestsAll`
|
||||
---
|
||||
--- - generate unit tests only for exported(public) functions/methods
|
||||
--- - run `:GoTestsExp`
|
||||
---
|
||||
--- 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
|
||||
--- if you prefare using named tests, you can enable it in the config.
|
||||
--- but you would need to install `gotests@develop` because stable version doesn't support this feature.
|
||||
--- you can do it with:
|
||||
--- >lua
|
||||
--- -- simply run go get in your shell:
|
||||
--- go install github.com/cweill/gotests/...@develop
|
||||
---
|
||||
--- -- if you want to install it within neovim, you can use one of this:
|
||||
---
|
||||
--- vim.fn.jobstart("go install github.com/cweill/gotests/...@develop")
|
||||
---
|
||||
--- -- or if you want to use mason:
|
||||
--- require("mason-tool-installer").setup {
|
||||
--- ensure_installed = {
|
||||
--- { "gotests", version = "develop" },
|
||||
--- }
|
||||
--- }
|
||||
--- <
|
||||
---
|
||||
--- if you choose to install `gotests` within neovim, i recommend adding it to your `build` section in your |lazy.nvim|
|
||||
|
||||
local c = require "gopher.config"
|
||||
local ts_utils = require "gopher._utils.ts"
|
||||
local r = require "gopher._utils.runner"
|
||||
|
|
@ -5,6 +46,7 @@ local u = require "gopher._utils"
|
|||
local gotests = {}
|
||||
|
||||
---@param args table
|
||||
---@private
|
||||
local function add_test(args)
|
||||
if c.gotests.named then
|
||||
table.insert(args, "-named")
|
||||
|
|
@ -35,7 +77,7 @@ local function add_test(args)
|
|||
})
|
||||
end
|
||||
|
||||
---generate unit test for one function
|
||||
-- generate unit test for one function
|
||||
function gotests.func_test()
|
||||
local ns = ts_utils.get_func_method_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0)))
|
||||
if ns == nil or ns.name == nil then
|
||||
|
|
@ -46,12 +88,12 @@ function gotests.func_test()
|
|||
add_test { "-only", ns.name }
|
||||
end
|
||||
|
||||
---generate unit tests for all functions in current file
|
||||
-- generate unit tests for all functions in current file
|
||||
function gotests.all_tests()
|
||||
add_test { "-all" }
|
||||
end
|
||||
|
||||
---generate unit tests for all exported functions
|
||||
-- generate unit tests for all exported functions
|
||||
function gotests.all_exported_tests()
|
||||
add_test { "-exported" }
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
---@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.
|
||||
---@usage execute `:GoIfErr` near any err variable to insert the check
|
||||
|
||||
local c = require "gopher.config"
|
||||
local iferr = {}
|
||||
|
||||
-- That's Lua of vimscript implementation of: github.com/koron/iferr
|
||||
-- That's Lua implementation: github.com/koron/iferr
|
||||
function iferr.iferr()
|
||||
local boff = vim.fn.wordcount().cursor_bytes
|
||||
local pos = vim.fn.getcurpos()[2]
|
||||
|
|
|
|||
|
|
@ -1,3 +1,31 @@
|
|||
---@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. put your coursor on the struct on which you want implement the interface
|
||||
--- and run `:GoImpl io.Reader`
|
||||
--- which will automatically choose the reciver for the methods and
|
||||
--- implement the `io.Reader` interface
|
||||
--- 2. same as previous but with custom receiver, so put your coursor on the struct
|
||||
--- run `:GoImpl w io.Writer`
|
||||
--- where `w` is the receiver and `io.Writer` is the interface
|
||||
--- 3. specift receiver, struct, and interface
|
||||
--- there's no need to put your coursor on the struct if you specify all arguments
|
||||
--- `:GoImpl r RequestReader io.Reader`
|
||||
--- where `r` is the receiver, `RequestReader` is the struct and `io.Reader` is the interface
|
||||
---
|
||||
--- simple example:
|
||||
--- >go
|
||||
--- type BytesReader struct{}
|
||||
--- // ^ put your cursor here
|
||||
--- // run `:GoImpl b io.Reader`
|
||||
---
|
||||
--- // this is what you will get
|
||||
--- func (b *BytesReader) Read(p []byte) (n int, err error) {
|
||||
--- panic("not implemented") // TODO: Implement
|
||||
--- }
|
||||
--- <
|
||||
|
||||
local c = require("gopher.config").commands
|
||||
local r = require "gopher._utils.runner"
|
||||
local ts_utils = require "gopher._utils.ts"
|
||||
|
|
@ -5,6 +33,7 @@ local u = require "gopher._utils"
|
|||
local impl = {}
|
||||
|
||||
---@return string
|
||||
---@private
|
||||
local function get_struct()
|
||||
local ns = ts_utils.get_struct_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0)))
|
||||
if ns == nil then
|
||||
|
|
|
|||
|
|
@ -1,10 +1,35 @@
|
|||
--- *gopher.nvim*
|
||||
---
|
||||
--- ==============================================================================
|
||||
---
|
||||
--- 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 tags = require "gopher.struct_tags"
|
||||
local tests = require "gopher.gotests"
|
||||
local gocmd = require("gopher._utils.runner.gocmd").run
|
||||
local gopher = {}
|
||||
|
||||
---@toc_entry Setup
|
||||
---@tag gopher.nvim-setup
|
||||
---@text Setup function. This method simply merges default configs with opts table.
|
||||
--- You can read more about configuration at |gopher.nvim-config|
|
||||
--- Calling this function is optional, if you ok with default settings. Look |gopher.nvim.config-defaults|
|
||||
---
|
||||
---@usage `require("gopher").setup {}` (replace `{}` with your `config` table)
|
||||
gopher.setup = require("gopher.config").setup
|
||||
|
||||
---@toc_entry Install dependencies
|
||||
---@tag gopher.nvim-install-deps
|
||||
---@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 ues lua api.
|
||||
gopher.install_deps = require("gopher.installer").install_deps
|
||||
|
||||
gopher.impl = require("gopher.impl").impl
|
||||
gopher.iferr = require("gopher.iferr").iferr
|
||||
gopher.comment = require "gopher.comment"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,29 @@
|
|||
---@toc_entry Modifty struct tags
|
||||
---@tag gopher.nvim-struct-tags
|
||||
---@text struct-tags is utilizing the `gomodifytags` tool to add or remove tags to struct fields.
|
||||
---@usage - put your coursor on the struct
|
||||
--- - run `:GoTagAdd json` to add json tags to struct fields
|
||||
--- - run `:GoTagRm json` to remove json tags to struct fields
|
||||
---
|
||||
--- note: if you dont spesify the tag it will use `json` as default
|
||||
---
|
||||
--- simple example:
|
||||
--- >go
|
||||
--- // before
|
||||
--- type User struct {
|
||||
--- // ^ put your cursor here
|
||||
--- // run `:GoTagAdd yaml`
|
||||
--- ID int
|
||||
--- Name string
|
||||
--- }
|
||||
---
|
||||
--- // after
|
||||
--- type User struct {
|
||||
--- ID int `yaml:id`
|
||||
--- Name string `yaml:name`
|
||||
--- }
|
||||
--- <
|
||||
|
||||
local ts_utils = require "gopher._utils.ts"
|
||||
local r = require "gopher._utils.runner"
|
||||
local c = require "gopher.config"
|
||||
|
|
@ -56,7 +82,7 @@ local function modify(...)
|
|||
or tagged["start"] == nil
|
||||
or tagged["start"] == 0
|
||||
then
|
||||
error("failed to set tags " .. vim.inspec(tagged))
|
||||
error("failed to set tags " .. vim.inspect(tagged))
|
||||
end
|
||||
|
||||
vim.api.nvim_buf_set_lines(
|
||||
|
|
@ -69,8 +95,7 @@ local function modify(...)
|
|||
vim.cmd "write"
|
||||
end
|
||||
|
||||
---add tags to struct under cursor
|
||||
---@param ... unknown
|
||||
-- add tags to struct under cursor
|
||||
function struct_tags.add(...)
|
||||
local arg = { ... }
|
||||
if #arg == nil or arg == "" then
|
||||
|
|
@ -85,8 +110,7 @@ function struct_tags.add(...)
|
|||
modify(unpack(cmd_args))
|
||||
end
|
||||
|
||||
---remove tags to struct under cursor
|
||||
---@param ... unknown
|
||||
-- remove tags to struct under cursor
|
||||
function struct_tags.remove(...)
|
||||
local arg = { ... }
|
||||
if #arg == nil or arg == "" then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue