From 77754fe3624eaa9a59139452cf869b5fa91b6b28 Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Sun, 23 Mar 2025 19:06:13 +0200 Subject: [PATCH] fix: nightly(0.11) (#104) * chore: fix minimal_init, load default plugins correctly * refactor(ts): make it work on nightly * chore: get nightly back in ci * fix(tests): some how i now i need to run vim.treesitter.start() to make it work * feat(ts): check if parser is found * chore: use --clean instead --noplugin * refactor(tests): use auto commands instead of putting it in each test * chore: show the diff of the doc --- .github/workflows/linters.yml | 4 +++- .github/workflows/tests.yml | 2 +- Taskfile.yml | 5 ++--- doc/gopher.nvim.txt | 18 +++++++++--------- lua/gopher/_utils/ts.lua | 19 ++++++++++--------- scripts/minimal_init.lua | 12 ++++++++++-- spec/testutils.lua | 5 ++++- 7 files changed, 39 insertions(+), 26 deletions(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 175465e..0122b93 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -53,4 +53,6 @@ jobs: run: task docgen - name: Diff - run: exit $(git status --porcelain doc | wc -l | tr -d " ") + run: | + git diff doc + exit $(git status --porcelain doc | wc -l | tr -d " ") diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2eaf9fa..103b18e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,7 +14,7 @@ jobs: os: [ubuntu-latest] version: - stable - # - nightly # TODO: enable when stable + - nightly runs-on: ${{ matrix.os }} steps: - name: Install Task diff --git a/Taskfile.yml b/Taskfile.yml index 3900751..19cbc8f 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -20,7 +20,7 @@ tasks: desc: run all tests cmds: - | - nvim --headless \ + nvim --clean --headless \ -u ./scripts/minimal_init.lua \ -c "lua MiniTest.run()" @@ -28,8 +28,7 @@ tasks: desc: generate vimhelp cmds: - | - nvim --noplugin \ - --headless \ + nvim --clean --headless \ -u "./scripts/minimal_init.lua" \ -c "luafile ./scripts/docgen.lua" \ -c ":qa!" diff --git a/doc/gopher.nvim.txt b/doc/gopher.nvim.txt index 3d653ca..47aa005 100644 --- a/doc/gopher.nvim.txt +++ b/doc/gopher.nvim.txt @@ -8,15 +8,15 @@ 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 - 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| - Generating unit tests boilerplate......................|gopher.nvim-gotests| - Iferr....................................................|gopher.nvim-iferr| - Generate comments.....................................|gopher.nvim-comments| + 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| + Generating unit tests boilerplate .................... |gopher.nvim-gotests| + Iferr .................................................. |gopher.nvim-iferr| + Generate comments ................................... |gopher.nvim-comments| ------------------------------------------------------------------------------ *gopher.nvim-setup()* diff --git a/lua/gopher/_utils/ts.lua b/lua/gopher/_utils/ts.lua index b5e6d32..29d38fe 100644 --- a/lua/gopher/_utils/ts.lua +++ b/lua/gopher/_utils/ts.lua @@ -50,16 +50,13 @@ end ---@return {name:string, is_varstruct:boolean} local function get_captures(query, node, bufnr) local res = {} - for _, match, _ in query:iter_matches(node, bufnr) do - for capture_id, captured_node in pairs(match) do - local capture_name = query.captures[capture_id] - if capture_name == "_name" then - res["name"] = vim.treesitter.get_node_text(captured_node, bufnr) - end + for id, _node in query:iter_captures(node, bufnr) do + if query.captures[id] == "_name" then + res["name"] = vim.treesitter.get_node_text(_node, bufnr) + end - if capture_name == "_var" then - res["is_varstruct"] = true - end + if query.captures[id] == "_var" then + res["is_varstruct"] = true end end @@ -77,6 +74,10 @@ end ---@param query string ---@return gopher.TsResult local function do_stuff(bufnr, parent_type, query) + if not vim.treesitter.get_parser(bufnr, "go") then + error "No treesitter parser found for go" + end + local node = vim.treesitter.get_node { bufnr = bufnr, } diff --git a/scripts/minimal_init.lua b/scripts/minimal_init.lua index 503bf49..b0f51e6 100644 --- a/scripts/minimal_init.lua +++ b/scripts/minimal_init.lua @@ -30,9 +30,8 @@ vim.env.XDG_DATA_HOME = root ".tests/data" vim.env.XDG_STATE_HOME = root ".tests/state" vim.env.XDG_CACHE_HOME = root ".tests/cache" -vim.cmd [[set runtimepath=$VIMRUNTIME]] vim.opt.runtimepath:append(root()) -vim.opt.packpath = { root ".tests/site" } +vim.opt.packpath:append(root ".tests/site") vim.notify = vim.print -- install go treesitter parse @@ -53,3 +52,12 @@ if #vim.api.nvim_list_uis() == 0 then }, } 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", { + pattern = "go", + callback = function(args) + vim.treesitter.start(args.buf, "go") + end, +}) diff --git a/spec/testutils.lua b/spec/testutils.lua index 1a31e10..b359b4b 100644 --- a/spec/testutils.lua +++ b/spec/testutils.lua @@ -69,6 +69,7 @@ end ---@class gopher.TestUtilsSetup ---@field tmp string ---@field fixtures gopher.TestUtilsFixtures +---@field bufnr number ---@param fixture string ---@param child MiniTest.child @@ -81,12 +82,14 @@ function testutils.setup_test(fixture, child, pos) testutils.writefile(tmp, fixtures.input) child.cmd("silent edit " .. tmp) + local bufnr = child.fn.bufnr(tmp) if pos then - child.fn.setpos(".", { child.fn.bufnr(tmp), unpack(pos) }) + child.fn.setpos(".", { bufnr, unpack(pos) }) end return { tmp = tmp, + bufnr = bufnr, fixtures = fixtures, } end