[mirror] Make your go dev experience better github.com/olexsmir/gopher.nvim
neovim golang

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

authored by olexsmir.xyz and committed by GitHub 77754fe3 c0b28346

Changed files
+39 -26
.github
doc
lua
gopher
_utils
scripts
spec
+3 -1
.github/workflows/linters.yml
··· 53 53 run: task docgen 54 54 55 55 - name: Diff 56 - run: exit $(git status --porcelain doc | wc -l | tr -d " ") 56 + run: | 57 + git diff doc 58 + exit $(git status --porcelain doc | wc -l | tr -d " ")
+1 -1
.github/workflows/tests.yml
··· 14 14 os: [ubuntu-latest] 15 15 version: 16 16 - stable 17 - # - nightly # TODO: enable when stable 17 + - nightly 18 18 runs-on: ${{ matrix.os }} 19 19 steps: 20 20 - name: Install Task
+2 -3
Taskfile.yml
··· 20 20 desc: run all tests 21 21 cmds: 22 22 - | 23 - nvim --headless \ 23 + nvim --clean --headless \ 24 24 -u ./scripts/minimal_init.lua \ 25 25 -c "lua MiniTest.run()" 26 26 ··· 28 28 desc: generate vimhelp 29 29 cmds: 30 30 - | 31 - nvim --noplugin \ 32 - --headless \ 31 + nvim --clean --headless \ 33 32 -u "./scripts/minimal_init.lua" \ 34 33 -c "luafile ./scripts/docgen.lua" \ 35 34 -c ":qa!"
+9 -9
doc/gopher.nvim.txt
··· 8 8 It's not an LSP tool, the main goal of this plugin is add go tooling support in Neovim. 9 9 10 10 Table of Contents 11 - Setup..................................................|gopher.nvim-setup()| 12 - Install dependencies..............................|gopher.nvim-dependencies| 13 - Config..................................................|gopher.nvim-config| 14 - Commands..............................................|gopher.nvim-commands| 15 - Modify struct tags.................................|gopher.nvim-struct-tags| 16 - Auto implementation of interface methods..................|gopher.nvim-impl| 17 - Generating unit tests boilerplate......................|gopher.nvim-gotests| 18 - Iferr....................................................|gopher.nvim-iferr| 19 - Generate comments.....................................|gopher.nvim-comments| 11 + Setup ................................................ |gopher.nvim-setup()| 12 + Install dependencies ............................ |gopher.nvim-dependencies| 13 + Config ................................................ |gopher.nvim-config| 14 + Commands ............................................ |gopher.nvim-commands| 15 + Modify struct tags ............................... |gopher.nvim-struct-tags| 16 + Auto implementation of interface methods ................ |gopher.nvim-impl| 17 + Generating unit tests boilerplate .................... |gopher.nvim-gotests| 18 + Iferr .................................................. |gopher.nvim-iferr| 19 + Generate comments ................................... |gopher.nvim-comments| 20 20 21 21 ------------------------------------------------------------------------------ 22 22 *gopher.nvim-setup()*
+10 -9
lua/gopher/_utils/ts.lua
··· 50 50 ---@return {name:string, is_varstruct:boolean} 51 51 local function get_captures(query, node, bufnr) 52 52 local res = {} 53 - for _, match, _ in query:iter_matches(node, bufnr) do 54 - for capture_id, captured_node in pairs(match) do 55 - local capture_name = query.captures[capture_id] 56 - if capture_name == "_name" then 57 - res["name"] = vim.treesitter.get_node_text(captured_node, bufnr) 58 - end 53 + for id, _node in query:iter_captures(node, bufnr) do 54 + if query.captures[id] == "_name" then 55 + res["name"] = vim.treesitter.get_node_text(_node, bufnr) 56 + end 59 57 60 - if capture_name == "_var" then 61 - res["is_varstruct"] = true 62 - end 58 + if query.captures[id] == "_var" then 59 + res["is_varstruct"] = true 63 60 end 64 61 end 65 62 ··· 77 74 ---@param query string 78 75 ---@return gopher.TsResult 79 76 local function do_stuff(bufnr, parent_type, query) 77 + if not vim.treesitter.get_parser(bufnr, "go") then 78 + error "No treesitter parser found for go" 79 + end 80 + 80 81 local node = vim.treesitter.get_node { 81 82 bufnr = bufnr, 82 83 }
+10 -2
scripts/minimal_init.lua
··· 30 30 vim.env.XDG_STATE_HOME = root ".tests/state" 31 31 vim.env.XDG_CACHE_HOME = root ".tests/cache" 32 32 33 - vim.cmd [[set runtimepath=$VIMRUNTIME]] 34 33 vim.opt.runtimepath:append(root()) 35 - vim.opt.packpath = { root ".tests/site" } 34 + vim.opt.packpath:append(root ".tests/site") 36 35 vim.notify = vim.print 37 36 38 37 -- install go treesitter parse ··· 53 52 }, 54 53 } 55 54 end 55 + 56 + -- needed for tests, i dont know the reason why, but on start 57 + -- vim is not able to use treesitter for go by default 58 + vim.api.nvim_create_autocmd("FileType", { 59 + pattern = "go", 60 + callback = function(args) 61 + vim.treesitter.start(args.buf, "go") 62 + end, 63 + })
+4 -1
spec/testutils.lua
··· 69 69 ---@class gopher.TestUtilsSetup 70 70 ---@field tmp string 71 71 ---@field fixtures gopher.TestUtilsFixtures 72 + ---@field bufnr number 72 73 73 74 ---@param fixture string 74 75 ---@param child MiniTest.child ··· 81 82 testutils.writefile(tmp, fixtures.input) 82 83 child.cmd("silent edit " .. tmp) 83 84 85 + local bufnr = child.fn.bufnr(tmp) 84 86 if pos then 85 - child.fn.setpos(".", { child.fn.bufnr(tmp), unpack(pos) }) 87 + child.fn.setpos(".", { bufnr, unpack(pos) }) 86 88 end 87 89 88 90 return { 89 91 tmp = tmp, 92 + bufnr = bufnr, 90 93 fixtures = fixtures, 91 94 } 92 95 end