diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7ce0603..103b18e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,12 +15,6 @@ jobs: version: - stable - nightly - - v0.10.0 - - v0.10.4 - - v0.11.0 - - v0.11.1 - - v0.11.2 - - v0.11.3 runs-on: ${{ matrix.os }} steps: - name: Install Task @@ -53,9 +47,14 @@ jobs: key: ${{ runner.os }}-tests-${{ hashFiles('${{ github.workspace }}/.tests') }} - name: Install Go bins - run: task install-deps + run: | + # TODO: install with :GoInstallDeps + go install github.com/fatih/gomodifytags@latest + go install github.com/josharian/impl@latest + go install github.com/cweill/gotests/...@latest + go install github.com/koron/iferr@latest - name: Run Tests run: | nvim --version - task test + task tests diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 554e358..ef377e2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,14 +1,17 @@ # Contributing to `gopher.nvim` + Thank you for taking the time to submit some code to gopher.nvim. It means a lot! ### Task running + In this codebase for running tasks is used [Taskfile](https://taskfile.dev). You can install it with: ```bash go install github.com/go-task/task/v3/cmd/task@latest ``` -### Formatting and linting +### Styling and formatting + Code is formatted by [stylua](https://github.com/JohnnyMorganz/StyLua) and linted using [selene](https://github.com/Kampfkarren/selene). You can install these with: @@ -19,31 +22,30 @@ sudo pacman -S selene stylua For formatting use this following commands, or setup your editor to integrate with selene/stylua: ```bash -task format -task lint +task stylua +task lint # lintering and format chewing ``` ### Documentation -Here we're using [mini.doc](https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-doc.md) -for generating vimhelp files based on [LuaCats](https://luals.github.io/wiki/annotations/) annotations in comments. -For demo gifs in [readme](./README.md) we're using [vhs](https://github.com/charmbracelet/vhs). -All files related to demos live in [/vhs](./vhs) dir. +Here we are using [mini.doc](https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-doc.md) +for generating help files based on EmmyLua-like annotations in comments You can generate docs with: ```bash -task docgen # generates vimhelp -task vhs:generate # generates demo gifs +task docgen ``` ### Commit messages + We use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/), please follow it. ### Testing + For testing this plugins uses [mini.test](https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-test.md). All tests live in [/spec](./spec) dir. You can run tests with: ```bash -task test +task tests ``` diff --git a/README.md b/README.md index d0c9515..b50642e 100644 --- a/README.md +++ b/README.md @@ -4,21 +4,19 @@ Minimalistic plugin for Go development in Neovim written in Lua. -It's **NOT** an LSP tool, the goal of this plugin is to add go tooling support in Neovim. +It's **NOT** an LSP tool, the main goal of this plugin is to add go tooling support in Neovim. -> All development of new and maybe undocumented, and unstable features is happening on [develop](https://github.com/olexsmir/gopher.nvim/tree/develop) branch. +> If you want to use new and maybe undocumented, and unstable features you might use [develop](https://github.com/olexsmir/gopher.nvim/tree/develop) branch. ## Install (using [lazy.nvim](https://github.com/folke/lazy.nvim)) Requirements: - **Neovim 0.10** or later -- Treesitter parser for `go`(`:TSInstall go` if you use [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter)) -- [Go](https://github.com/golang/go) installed +- Treesitter `go` parser(`:TSInstall go` if you use [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter)) +- [Go](https://github.com/golang/go) installed (tested on 1.23) ```lua --- NOTE: this plugin is already lazy-loaded, it adds only about 1ms of load --- time to your config { "olexsmir/gopher.nvim", ft = "go", @@ -27,14 +25,58 @@ Requirements: build = function() vim.cmd.GoInstallDeps() end, - ---@module "gopher" ---@type gopher.Config opts = {}, } ``` +## Configuration + +> [!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`)** + +```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 + timeout = 2000, + + commands = { + go = "go", + gomodifytags = "gomodifytags", + gotests = "gotests", + impl = "impl", + iferr = "iferr", + }, + gotests = { + -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template + template = "default", + -- path to a directory containing custom test code templates + template_dir = nil, + -- switch table tests from using slice to map (with test name for the key) + named = false, + }, + gotag = { + transform = "snakecase", + -- default tags to add to struct fields + default_tag = "json", + }, + iferr = { + -- choose a custom error message + message = nil, + }, +} +``` + ## Features + +
Install plugin's go deps @@ -57,8 +99,6 @@ Requirements: Add and remove tags for structs via gomodifytags - ![Add tags demo](./vhs/tags.gif) - By default `json` tag will be added/removed, if not set: ```vim @@ -136,8 +176,6 @@ Requirements: Interface implementation via impl - ![Auto interface implementation demo](./vhs/impl.gif) - Syntax of the command: ```vim :GoImpl [receiver] [interface] @@ -161,8 +199,6 @@ Requirements: Generate boilerplate for doc comments - ![Generate comments](./vhs/comment.gif) - First set a cursor on **public** package/function/interface/struct and execute: ```vim @@ -176,8 +212,6 @@ Requirements: Generate if err != nil { via iferr - ![Generate if err != nil {](./vhs/iferr.gif) - Set the cursor on the line with `err` and execute ```vim @@ -185,49 +219,11 @@ Requirements: ```
-## Configuration - -> [!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`)** - -```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 - timeout = 2000, - - commands = { - go = "go", - gomodifytags = "gomodifytags", - gotests = "gotests", - impl = "impl", - iferr = "iferr", - }, - gotests = { - -- gotests doesn't have template named "default" so this plugin uses "default" to set the default template - template = "default", - -- path to a directory containing custom test code templates - template_dir = nil, - -- switch table tests from using slice to map (with test name for the key) - named = false, - }, - gotag = { - transform = "snakecase", - -- default tags to add to struct fields - default_tag = "json", - }, - iferr = { - -- choose a custom error message - message = nil, - }, -} -``` - ## Contributing PRs are always welcome. See [CONTRIBUTING.md](./CONTRIBUTING.md) + +## Thanks + +- [go.nvim](https://github.com/ray-x/go.nvim) +- [iferr](https://github.com/koron/iferr) diff --git a/Taskfile.yml b/Taskfile.yml index 62ccd0c..19cbc8f 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,26 +1,28 @@ version: "3" - -includes: - vhs: - taskfile: ./vhs/Taskfile.yml - dir: ./vhs - tasks: lint: + desc: runs all linters cmds: - - selene . + - task: selene - stylua --check . - format: - cmd: stylua . + selene: + desc: runs lua linter(selene) + cmds: + - selene . - test: + stylua: + desc: runs lua formatter + cmds: + - stylua . + + tests: + desc: run all tests cmds: - | nvim --clean --headless \ -u ./scripts/minimal_init.lua \ - -c "lua MiniTest.run()" \ - -c ":qa!" + -c "lua MiniTest.run()" docgen: desc: generate vimhelp @@ -30,11 +32,3 @@ tasks: -u "./scripts/minimal_init.lua" \ -c "luafile ./scripts/docgen.lua" \ -c ":qa!" - - install-deps: - desc: installs go bin (used in CI) - cmds: - - | - nvim --clean --headless \ - -u "./scripts/minimal_init.lua" \ - +GoInstallDepsSync +qa diff --git a/lua/gopher/_utils/ts.lua b/lua/gopher/_utils/ts.lua index a0623ad..29d38fe 100644 --- a/lua/gopher/_utils/ts.lua +++ b/lua/gopher/_utils/ts.lua @@ -65,8 +65,8 @@ end ---@class gopher.TsResult ---@field name string ----@field start integer ----@field end_ integer +---@field start_line integer +---@field end_line integer ---@field is_varstruct boolean ---@param bufnr integer @@ -95,8 +95,8 @@ local function do_stuff(bufnr, parent_type, query) assert(res.name ~= nil, "No capture name found") local start_row, _, end_row, _ = parent_node:range() - res["start"] = start_row + 1 - res["end_"] = end_row + 1 + res["start_line"] = start_row + 1 + res["end_line"] = end_row + 1 return res end diff --git a/lua/gopher/config.lua b/lua/gopher/config.lua index 7754b8e..a0c4ed8 100644 --- a/lua/gopher/config.lua +++ b/lua/gopher/config.lua @@ -109,4 +109,4 @@ setmetatable(config, { ---@dochide ---@return gopher.Config -return config --[[ @as gopher.Config ]] +return config diff --git a/lua/gopher/struct_tags.lua b/lua/gopher/struct_tags.lua index 3264e7a..cf990bf 100644 --- a/lua/gopher/struct_tags.lua +++ b/lua/gopher/struct_tags.lua @@ -37,22 +37,11 @@ local u = require "gopher._utils" local log = require "gopher._utils.log" local struct_tags = {} ----@dochide ----@class gopher.StructTagInput ----@field tags string[] User provided tags ----@field range? gopher.StructTagRange (optional) - ----@dochide ----@class gopher.StructTagRange ----@field start number ----@field end_ number - ---@param fpath string ---@param bufnr integer ----@param range? gopher.StructTagRange ---@param user_args string[] ---@dochide -local function handle_tags(fpath, bufnr, range, user_args) +local function handle_tags(fpath, bufnr, user_args) local st = ts.get_struct_under_cursor(bufnr) -- stylua: ignore @@ -64,10 +53,9 @@ local function handle_tags(fpath, bufnr, range, user_args) "-w", } - -- `-struct` and `-line` cannot be combined, setting them separately - if range or st.is_varstruct then + if st.is_varstruct then table.insert(cmd, "-line") - table.insert(cmd, string.format("%d,%d", (range or st).start, (range or st).end_)) + table.insert(cmd, string.format("%d,%d", st.start_line, st.end_line)) else table.insert(cmd, "-struct") table.insert(cmd, st.name) @@ -105,7 +93,7 @@ end ---@param args string[] ---@return string ---@dochide -local function handler_user_tags(args) +local function handler_user_args(args) if #args == 0 then return c.gotag.default_tag end @@ -114,30 +102,28 @@ end -- Adds tags to a struct under the cursor -- See |gopher.nvim-struct-tags| ----@param opts gopher.StructTagInput +---@param ... string Tags to add to the struct fields. If not provided, it will use [config.gotag.default_tag] ---@dochide -function struct_tags.add(opts) - log.debug("adding tags", opts) - +function struct_tags.add(...) + local args = { ... } local fpath = vim.fn.expand "%" local bufnr = vim.api.nvim_get_current_buf() - local user_tags = handler_user_tags(opts.tags) - handle_tags(fpath, bufnr, opts.range, { "-add-tags", user_tags }) + local user_tags = handler_user_args(args) + handle_tags(fpath, bufnr, { "-add-tags", user_tags }) end -- Removes tags from a struct under the cursor -- See `:h gopher.nvim-struct-tags` ---@dochide ----@param opts gopher.StructTagInput -function struct_tags.remove(opts) - log.debug("removing tags", opts) - +---@param ... string Tags to add to the struct fields. If not provided, it will use [config.gotag.default_tag] +function struct_tags.remove(...) + local args = { ... } local fpath = vim.fn.expand "%" local bufnr = vim.api.nvim_get_current_buf() - local user_tags = handler_user_tags(opts.tags) - handle_tags(fpath, bufnr, opts.range, { "-remove-tags", user_tags }) + local user_tags = handler_user_args(args) + handle_tags(fpath, bufnr, { "-remove-tags", user_tags }) end -- Removes all tags from a struct under the cursor @@ -146,7 +132,7 @@ end function struct_tags.clear() local fpath = vim.fn.expand "%" local bufnr = vim.api.nvim_get_current_buf() - handle_tags(fpath, bufnr, nil, { "-clear-tags" }) + handle_tags(fpath, bufnr, { "-clear-tags" }) end return struct_tags diff --git a/nvim.toml b/nvim.toml index b0fce0c..50dc11f 100644 --- a/nvim.toml +++ b/nvim.toml @@ -3,3 +3,43 @@ any = true [MiniTest] any = true + +[describe] +any = true +[[describe.args]] +type = "string" +[[describe.args]] +type = "function" + +[it] +any = true +[[it.args]] +type = "string" +[[it.args]] +type = "function" + +[before_each] +any = true +[[before_each.args]] +type = "function" +[[after_each.args]] +type = "function" + +[assert] +any = true + +[assert.is_not] +any = true + +[[assert.equals.args]] +type = "any" +[[assert.equals.args]] +type = "any" +[[assert.equals.args]] +type = "any" +required = false + +[[assert.same.args]] +type = "any" +[[assert.same.args]] +type = "any" diff --git a/plugin/gopher.lua b/plugin/gopher.lua index 4ffda5b..1ccc74e 100644 --- a/plugin/gopher.lua +++ b/plugin/gopher.lua @@ -11,13 +11,10 @@ end ---@param name string ---@param fn fun(args: table) ---@param nargs? number|"*"|"?" ----@param range? boolean ---@private -local function cmd(name, fn, nargs, range) - vim.api.nvim_create_user_command(name, fn, { - nargs = nargs or 0, - range = range or false, - }) +local function cmd(name, fn, nargs) + nargs = nargs or 0 + vim.api.nvim_create_user_command(name, fn, { nargs = nargs }) end cmd("GopherLog", function() @@ -47,24 +44,12 @@ end) -- :GoTag cmd("GoTagAdd", function(opts) - require("gopher").tags.add { - tags = opts.fargs, - range = (opts.count ~= -1) and { - start = opts.line1, - end_ = opts.line2, - } or nil, - } -end, "*", true) + require("gopher").tags.add(unpack(opts.fargs)) +end, "*") cmd("GoTagRm", function(opts) - require("gopher").tags.rm { - tags = opts.fargs, - range = (opts.count ~= -1) and { - start = opts.line1, - end_ = opts.line2, - } or nil, - } -end, "*", true) + require("gopher").tags.rm(unpack(opts.fargs)) +end, "*") cmd("GoTagClear", function() require("gopher").tags.clear() diff --git a/scripts/minimal_init.lua b/scripts/minimal_init.lua index d7eed81..b0f51e6 100644 --- a/scripts/minimal_init.lua +++ b/scripts/minimal_init.lua @@ -23,7 +23,6 @@ end install_plug "nvim-lua/plenary.nvim" install_plug "nvim-treesitter/nvim-treesitter" install_plug "echasnovski/mini.doc" -- used for docs generation -install_plug "folke/tokyonight.nvim" -- theme for generating demos install_plug "echasnovski/mini.test" vim.env.XDG_CONFIG_HOME = root ".tests/config" @@ -33,8 +32,6 @@ vim.env.XDG_CACHE_HOME = root ".tests/cache" vim.opt.runtimepath:append(root()) vim.opt.packpath:append(root ".tests/site") -vim.o.swapfile = false -vim.o.writebackup = false vim.notify = vim.print -- install go treesitter parse @@ -56,13 +53,6 @@ if #vim.api.nvim_list_uis() == 0 then } end --- set colorscheme only when running ui -if #vim.api.nvim_list_uis() == 1 then - vim.cmd.colorscheme "tokyonight-night" - vim.o.cursorline = true - vim.o.number = true -end - -- needed for tests, i dont know the reason why, but on start -- vim is not able to use treesitter for go by default vim.api.nvim_create_autocmd("FileType", { diff --git a/spec/fixtures/tags/add_range_input.go b/spec/fixtures/tags/add_range_input.go deleted file mode 100644 index 7786518..0000000 --- a/spec/fixtures/tags/add_range_input.go +++ /dev/null @@ -1,14 +0,0 @@ -package main - -type Test struct { - ID int - Name string - Num int64 - Cost int - Thingy []string - Testing int - Another struct { - First int - Second string - } -} diff --git a/spec/fixtures/tags/add_range_output.go b/spec/fixtures/tags/add_range_output.go deleted file mode 100644 index 2d287ab..0000000 --- a/spec/fixtures/tags/add_range_output.go +++ /dev/null @@ -1,14 +0,0 @@ -package main - -type Test struct { - ID int - Name string `gopher:"name"` - Num int64 `gopher:"num"` - Cost int `gopher:"cost"` - Thingy []string - Testing int - Another struct { - First int - Second string - } -} diff --git a/spec/fixtures/tags/remove_range_input.go b/spec/fixtures/tags/remove_range_input.go deleted file mode 100644 index efa4c9d..0000000 --- a/spec/fixtures/tags/remove_range_input.go +++ /dev/null @@ -1,14 +0,0 @@ -package main - -type Test struct { - ID int `asdf:"id"` - Name string `asdf:"name"` - Num int64 `asdf:"num"` - Cost int `asdf:"cost"` - Thingy []string `asdf:"thingy"` - Testing int `asdf:"testing"` - Another struct { - First int `asdf:"first"` - Second string `asdf:"second"` - } `asdf:"another"` -} diff --git a/spec/fixtures/tags/remove_range_output.go b/spec/fixtures/tags/remove_range_output.go deleted file mode 100644 index 8c51c55..0000000 --- a/spec/fixtures/tags/remove_range_output.go +++ /dev/null @@ -1,14 +0,0 @@ -package main - -type Test struct { - ID int `asdf:"id"` - Name string `asdf:"name"` - Num int64 - Cost int - Thingy []string - Testing int `asdf:"testing"` - Another struct { - First int `asdf:"first"` - Second string `asdf:"second"` - } `asdf:"another"` -} diff --git a/spec/integration/comment_test.lua b/spec/integration/comment_test.lua index fdf39fe..38e7909 100644 --- a/spec/integration/comment_test.lua +++ b/spec/integration/comment_test.lua @@ -1,5 +1,5 @@ local t = require "spec.testutils" -local child, T, comment = t.setup "comment" +local child, T = t.setup "comment" local function do_the_test(fixture, pos) local rs = t.setup_test("comment/" .. fixture, child, pos) @@ -10,27 +10,27 @@ local function do_the_test(fixture, pos) t.cleanup(rs) end -comment["should add comment to package"] = function() +T["comment"]["should add comment to package"] = function() do_the_test("package", { 1, 1 }) end -comment["should add comment to struct"] = function() +T["comment"]["should add comment to struct"] = function() do_the_test("struct", { 4, 1 }) end -comment["should add comment to function"] = function() +T["comment"]["should add comment to function"] = function() do_the_test("func", { 3, 1 }) end -comment["should add comment to method"] = function() +T["comment"]["should add comment to method"] = function() do_the_test("method", { 5, 1 }) end -comment["should add comment to interface"] = function() +T["comment"]["should add comment to interface"] = function() do_the_test("interface", { 3, 6 }) end -comment["otherwise should add // above cursor"] = function() +T["comment"]["otherwise should add // above cursor"] = function() do_the_test("empty", { 1, 1 }) end diff --git a/spec/integration/gotests_test.lua b/spec/integration/gotests_test.lua index 2f2ceb3..fcba8a7 100644 --- a/spec/integration/gotests_test.lua +++ b/spec/integration/gotests_test.lua @@ -1,5 +1,5 @@ local t = require "spec.testutils" -local child, T, gotests = t.setup "gotests" +local child, T = t.setup "gotests" --- NOTE: :GoTestAdd is the only place that has actual logic --- All other parts are handled `gotests` itself. @@ -10,7 +10,7 @@ local function read_testfile(fpath) return t.readfile(fpath:gsub(".go", "_test.go")) end -gotests["should add test for function under cursor"] = function() +T["gotests"]["should add test for function under cursor"] = function() local rs = t.setup_test("tests/function", child, { 3, 5 }) child.cmd "GoTestAdd" @@ -18,7 +18,7 @@ gotests["should add test for function under cursor"] = function() t.cleanup(rs) end -gotests["should add test for method under cursor"] = function() +T["gotests"]["should add test for method under cursor"] = function() local rs = t.setup_test("tests/method", child, { 5, 19 }) child.cmd "GoTestAdd" diff --git a/spec/integration/iferr_test.lua b/spec/integration/iferr_test.lua index cc36404..fff53ba 100644 --- a/spec/integration/iferr_test.lua +++ b/spec/integration/iferr_test.lua @@ -1,7 +1,7 @@ local t = require "spec.testutils" -local child, T, iferr = t.setup "iferr" +local child, T = t.setup "iferr" -iferr["should add if != nil {"] = function() +T["iferr"]["should add if != nil {"] = function() local rs = t.setup_test("iferr/iferr", child, { 8, 2 }) child.cmd "GoIfErr" child.cmd "write" @@ -10,7 +10,7 @@ iferr["should add if != nil {"] = function() t.cleanup(rs) end -iferr["should add if err with custom message"] = function() +T["iferr"]["should add if err with custom message"] = function() child.lua [[ require("gopher").setup { iferr = { message = 'fmt.Errorf("failed to %w", err)' } diff --git a/spec/integration/impl_test.lua b/spec/integration/impl_test.lua index 8cfa11b..602d2b1 100644 --- a/spec/integration/impl_test.lua +++ b/spec/integration/impl_test.lua @@ -1,7 +1,7 @@ local t = require "spec.testutils" -local child, T, impl = t.setup "impl" +local child, T = t.setup "impl" -impl["should do impl with 'w io.Writer'"] = function() +T["impl"]["should do impl with 'w io.Writer'"] = function() local rs = t.setup_test("impl/writer", child, { 3, 0 }) child.cmd "GoImpl w io.Writer" child.cmd "write" @@ -12,7 +12,7 @@ impl["should do impl with 'w io.Writer'"] = function() t.cleanup(rs) end -impl["should work with full input, 'r Read io.Reader'"] = function() +T["impl"]["should work with full input, 'r Read io.Reader'"] = function() local rs = t.setup_test("impl/reader", child) child.cmd "GoImpl r Read io.Reader" child.cmd "write" @@ -22,7 +22,7 @@ impl["should work with full input, 'r Read io.Reader'"] = function() t.cleanup(rs) end -impl["should work with minimal input 'io.Closer'"] = function() +T["impl"]["should work with minimal input 'io.Closer'"] = function() local rs = t.setup_test("impl/closer", child, { 3, 6 }) child.cmd "GoImpl io.Closer" child.cmd "write" diff --git a/spec/integration/struct_tags_test.lua b/spec/integration/struct_tags_test.lua index ae7995b..1c97001 100644 --- a/spec/integration/struct_tags_test.lua +++ b/spec/integration/struct_tags_test.lua @@ -1,7 +1,7 @@ local t = require "spec.testutils" -local child, T, struct_tags = t.setup "struct_tags" +local child, T = t.setup "struct_tags" -struct_tags["should add tag"] = function() +T["struct_tags"]["should add tag"] = function() local rs = t.setup_test("tags/add", child, { 3, 6 }) child.cmd "GoTagAdd json" child.cmd "write" @@ -10,7 +10,7 @@ struct_tags["should add tag"] = function() t.cleanup(rs) end -struct_tags["should remove tag"] = function() +T["struct_tags"]["should remove tag"] = function() local rs = t.setup_test("tags/remove", child, { 4, 6 }) child.cmd "GoTagRm json" child.cmd "write" @@ -19,7 +19,7 @@ struct_tags["should remove tag"] = function() t.cleanup(rs) end -struct_tags["should be able to handle many structs"] = function() +T["struct_tags"]["should be able to handle many structs"] = function() local rs = t.setup_test("tags/many", child, { 10, 3 }) child.cmd "GoTagAdd testing" child.cmd "write" @@ -28,7 +28,7 @@ struct_tags["should be able to handle many structs"] = function() t.cleanup(rs) end -struct_tags["should clear struct"] = function() +T["struct_tags"]["should clear struct"] = function() local rs = t.setup_test("tags/clear", child, { 3, 1 }) child.cmd "GoTagClear" child.cmd "write" @@ -37,7 +37,7 @@ struct_tags["should clear struct"] = function() t.cleanup(rs) end -struct_tags["should add more than one tag"] = function() +T["struct_tags"]["should add more than one tag"] = function() local tmp = t.tmpfile() local fixtures = t.get_fixtures "tags/add_many" t.writefile(tmp, fixtures.input) @@ -60,7 +60,7 @@ struct_tags["should add more than one tag"] = function() t.cleanup { tmp = tmp } end -struct_tags["should add tags on var"] = function() +T["struct_tags"]["should add tags on var"] = function() local rs = t.setup_test("tags/var", child, { 5, 6 }) child.cmd "GoTagAdd yaml" child.cmd "write" @@ -69,7 +69,7 @@ struct_tags["should add tags on var"] = function() t.cleanup(rs) end -struct_tags["should add tags on short declr var"] = function() +T["struct_tags"]["should add tags on short declr var"] = function() local rs = t.setup_test("tags/svar", child, { 4, 3 }) child.cmd "GoTagAdd xml" child.cmd "write" @@ -78,22 +78,4 @@ struct_tags["should add tags on short declr var"] = function() t.cleanup(rs) end -struct_tags["should add tag with range"] = function() - local rs = t.setup_test("tags/add_range", child, { 5, 1 }) - child.cmd ".,+2GoTagAdd gopher" - child.cmd "write" - - t.eq(t.readfile(rs.tmp), rs.fixtures.output) - t.cleanup(rs) -end - -struct_tags["should remove tag with range"] = function() - local rs = t.setup_test("tags/remove_range", child, { 6, 1 }) - child.cmd ".,+2GoTagRm asdf" - child.cmd "write" - - t.eq(t.readfile(rs.tmp), rs.fixtures.output) - t.cleanup(rs) -end - return T diff --git a/spec/testutils.lua b/spec/testutils.lua index 0b24511..b359b4b 100644 --- a/spec/testutils.lua +++ b/spec/testutils.lua @@ -6,11 +6,9 @@ local testutils = {} testutils.mininit_path = vim.fs.joinpath(base_dir, "scripts", "minimal_init.lua") testutils.fixtures_dir = vim.fs.joinpath(base_dir, "spec/fixtures") ----@param mod string Module name for which to create a nested test set. ----@return MiniTest.child child nvim client. ----@return table T root test set created by `MiniTest.new_set()`. ----@return table mod_name nested set of tests in `T[mod]`. -function testutils.setup(mod) +---@param name string +---@return MiniTest.child, table +function testutils.setup(name) local child = MiniTest.new_child_neovim() local T = MiniTest.new_set { hooks = { @@ -21,8 +19,8 @@ function testutils.setup(mod) }, } - T[mod] = MiniTest.new_set {} - return child, T, T[mod] + T[name] = MiniTest.new_set {} + return child, T end ---@generic T @@ -78,8 +76,6 @@ end ---@param pos? number[] ---@return gopher.TestUtilsSetup function testutils.setup_test(fixture, child, pos) - vim.validate("pos", pos, "table", true) - local tmp = testutils.tmpfile() local fixtures = testutils.get_fixtures(fixture) @@ -88,8 +84,6 @@ function testutils.setup_test(fixture, child, pos) local bufnr = child.fn.bufnr(tmp) if pos then - assert(#pos == 2, "invalid cursor position") - child.fn.setpos(".", { bufnr, unpack(pos) }) end diff --git a/spec/unit/config_test.lua b/spec/unit/config_test.lua deleted file mode 100644 index ebb4be5..0000000 --- a/spec/unit/config_test.lua +++ /dev/null @@ -1,22 +0,0 @@ -local t = require "spec.testutils" -local _, T, config = t.setup "config" - -config["can be called without any arguments passed"] = function() - ---@diagnostic disable-next-line: missing-parameter - require("gopher").setup() -end - -config["can be called with empty table"] = function() - require("gopher").setup {} -end - -config["should change option"] = function() - local log_level = 1234567890 - require("gopher").setup { - log_level = log_level, - } - - t.eq(log_level, require("gopher.config").log_level) -end - -return T diff --git a/spec/unit/utils_test.lua b/spec/unit/utils_test.lua index d4898c2..4be8126 100644 --- a/spec/unit/utils_test.lua +++ b/spec/unit/utils_test.lua @@ -1,14 +1,14 @@ local t = require "spec.testutils" -local _, T, utils = t.setup "utils" +local _, T = t.setup "utils" -utils["should .remove_empty_lines()"] = function() +T["utils"]["should .remove_empty_lines()"] = function() local u = require "gopher._utils" local inp = { "hi", "", "a", "", "", "asdf" } t.eq(u.remove_empty_lines(inp), { "hi", "a", "asdf" }) end -utils["should .readfile_joined()"] = function() +T["utils"]["should .readfile_joined()"] = function() local data = "line1\nline2\nline3" local tmp = t.tmpfile() local u = require "gopher._utils" @@ -17,7 +17,7 @@ utils["should .readfile_joined()"] = function() t.eq(u.readfile_joined(tmp), data) end -utils["should .trimend()"] = function() +T["utils"]["should .trimend()"] = function() local u = require "gopher._utils" t.eq(u.trimend " hi ", " hi") end diff --git a/vhs/Taskfile.yml b/vhs/Taskfile.yml deleted file mode 100644 index 2dfb107..0000000 --- a/vhs/Taskfile.yml +++ /dev/null @@ -1,20 +0,0 @@ -version: "3" -tasks: - generate: - deps: - - comment - - iferr - - tags - - impl - - comment: - cmd: vhs comment.tape - - iferr: - cmd: vhs iferr.tape - - tags: - cmd: vhs tags.tape - - impl: - cmd: vhs impl.tape diff --git a/vhs/comment.gif b/vhs/comment.gif deleted file mode 100644 index 4b4a7b4..0000000 Binary files a/vhs/comment.gif and /dev/null differ diff --git a/vhs/comment.go b/vhs/comment.go deleted file mode 100644 index 3869484..0000000 --- a/vhs/comment.go +++ /dev/null @@ -1,7 +0,0 @@ -package demos - -func doSomethingImportant() {} - -type User struct{} - -type DataProvider interface{} diff --git a/vhs/comment.tape b/vhs/comment.tape deleted file mode 100644 index bc9724b..0000000 --- a/vhs/comment.tape +++ /dev/null @@ -1,34 +0,0 @@ -Output comment.gif -Require nvim - -Set FontFamily "JetBrains Mono" -Set Height 800 -Set Width 1500 -Set Padding 20 -Set Shell "bash" -Set Theme "tokyonight" -Set TypingSpeed 250ms - -Hide -Type@0ms "alias nvim='./nvim.sh'" Enter -Type@0ms "clear" Enter -Show - -Type "nvim comment.go" Sleep 150ms Enter - -# package -Type ":GoCmt" Enter Sleep 500ms Escape Sleep 700ms - -# func -Type "3j" -Type ":GoCmt" Enter Sleep 500ms Escape Sleep 700ms - -# struct -Type "3j" -Type ":GoCmt" Enter Sleep 500ms Escape Sleep 700ms - -# interface -Type "3j" -Type ":GoCmt" Enter Sleep 500ms Escape Sleep 700ms - -Sleep 5s diff --git a/vhs/go.mod b/vhs/go.mod deleted file mode 100644 index bd64a9b..0000000 --- a/vhs/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module demos - -go 1.25.0 diff --git a/vhs/iferr.gif b/vhs/iferr.gif deleted file mode 100644 index 217dd60..0000000 Binary files a/vhs/iferr.gif and /dev/null differ diff --git a/vhs/iferr.go b/vhs/iferr.go deleted file mode 100644 index a670571..0000000 --- a/vhs/iferr.go +++ /dev/null @@ -1,11 +0,0 @@ -package demos - -func ifErr() { - out, err := doSomething() - - _ = out -} - -func doSomething() (string, error) { - return "", nil -} diff --git a/vhs/iferr.tape b/vhs/iferr.tape deleted file mode 100644 index b54e3e7..0000000 --- a/vhs/iferr.tape +++ /dev/null @@ -1,23 +0,0 @@ -Output iferr.gif -Require nvim -Require iferr - -Set FontFamily "JetBrains Mono" -Set Height 800 -Set Width 1500 -Set Padding 20 -Set Shell "bash" -Set Theme "tokyonight" -Set TypingSpeed 250ms - -Hide -Type@0ms "alias nvim='./nvim.sh'" Enter -Type@0ms "clear" Enter -Show - -Type "nvim iferr.go" Sleep 150ms Enter - -Type "3j" -Type ":GoIfErr" Sleep 500ms Enter - -Sleep 5s diff --git a/vhs/impl.gif b/vhs/impl.gif deleted file mode 100644 index 26b6a6a..0000000 Binary files a/vhs/impl.gif and /dev/null differ diff --git a/vhs/impl.go b/vhs/impl.go deleted file mode 100644 index 6f6c0ba..0000000 --- a/vhs/impl.go +++ /dev/null @@ -1,3 +0,0 @@ -package demos - -type CloserExample struct{} diff --git a/vhs/impl.tape b/vhs/impl.tape deleted file mode 100644 index b8ef6b5..0000000 --- a/vhs/impl.tape +++ /dev/null @@ -1,23 +0,0 @@ -Output impl.gif -Require nvim -Require iferr - -Set FontFamily "JetBrains Mono" -Set Height 800 -Set Width 1500 -Set Padding 20 -Set Shell "bash" -Set Theme "tokyonight" -Set TypingSpeed 250ms - -Hide -Type@0ms "alias nvim='./nvim.sh'" Enter -Type@0ms "clear" Enter -Show - -Type "nvim impl.go" Sleep 150ms Enter - -Type "2j" -Type ":GoImpl io.Reader" Sleep 500ms Enter - -Sleep 5s diff --git a/vhs/nvim.sh b/vhs/nvim.sh deleted file mode 100755 index f907eb0..0000000 --- a/vhs/nvim.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -nvim --clean -u "../scripts/minimal_init.lua" $@ diff --git a/vhs/tags.gif b/vhs/tags.gif deleted file mode 100644 index 0b2b068..0000000 Binary files a/vhs/tags.gif and /dev/null differ diff --git a/vhs/tags.go b/vhs/tags.go deleted file mode 100644 index 91649d7..0000000 --- a/vhs/tags.go +++ /dev/null @@ -1,12 +0,0 @@ -package demos - -type AddTagsToMe struct { - Name string - ID int - Address string - Aliases []string - Nested struct { - Foo string - Bar float32 - } -} diff --git a/vhs/tags.tape b/vhs/tags.tape deleted file mode 100644 index 4888ec5..0000000 --- a/vhs/tags.tape +++ /dev/null @@ -1,36 +0,0 @@ -Output tags.gif -Require nvim -Require gomodifytags - -Set FontFamily "JetBrains Mono" -Set Height 800 -Set Width 1500 -Set Padding 20 -Set Shell "bash" -Set Theme "tokyonight" -Set TypingSpeed 250ms - -Hide -Type@0ms "alias nvim='./nvim.sh'" Enter -Type@0ms "clear" Enter -Show - -Type "nvim tags.go" Sleep 150ms Enter - -Type "3j" -Type ":GoTagAdd json yaml" Sleep 500ms Enter -Type@120ms ":w" Enter -Sleep 1s - -Type ":GoTagRm json" Sleep 500ms Enter -Type@120ms ":w" Enter -Sleep 1s - -Type ":GoTagClear" Sleep 500ms Enter -Type@120ms ":w" Enter -Sleep 1s - -Type "jV2j" -Type ":GoTagAdd xml" Sleep 500ms Enter - -Sleep 5s