7 files changed,
39 insertions(+),
26 deletions(-)
Author:
Smirnov Oleksandr
ss2316544@gmail.com
Committed by:
GitHub
noreply@github.com
Committed at:
2025-03-23 19:06:13 +0200
Parent:
c0b2834
M
.github/workflows/linters.yml
@@ -53,4 +53,6 @@ - name: Generate docs
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 " ")
M
.github/workflows/tests.yml
@@ -14,7 +14,7 @@ matrix:
os: [ubuntu-latest] version: - stable - # - nightly # TODO: enable when stable + - nightly runs-on: ${{ matrix.os }} steps: - name: Install Task
M
Taskfile.yml
@@ -20,7 +20,7 @@ tests:
desc: run all tests cmds: - | - nvim --headless \ + nvim --clean --headless \ -u ./scripts/minimal_init.lua \ -c "lua MiniTest.run()"@@ -28,8 +28,7 @@ docgen:
desc: generate vimhelp cmds: - | - nvim --noplugin \ - --headless \ + nvim --clean --headless \ -u "./scripts/minimal_init.lua" \ -c "luafile ./scripts/docgen.lua" \ -c ":qa!"
M
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()*
M
lua/gopher/_utils/ts.lua
@@ -50,16 +50,13 @@ ---@param bufnr integer
---@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 @@ ---@param parent_type string[]
---@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, }
M
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 @@ end,
}, } 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, +})
M
spec/testutils.lua
@@ -69,6 +69,7 @@
---@class gopher.TestUtilsSetup ---@field tmp string ---@field fixtures gopher.TestUtilsFixtures +---@field bufnr number ---@param fixture string ---@param child MiniTest.child@@ -81,12 +82,14 @@
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