all repos

gopher.nvim @ 77754fe3624eaa9a59139452cf869b5fa91b6b28

Minimalistic plugin for Go development
7 files changed, 39 insertions(+), 26 deletions(-)
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
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