diff --git a/lua/go/ts/nodes.lua b/lua/go/ts/nodes.lua index 38b45b6..873e624 100644 --- a/lua/go/ts/nodes.lua +++ b/lua/go/ts/nodes.lua @@ -126,11 +126,12 @@ local nodestime = {} M.get_all_nodes = function(query, lang, defaults, bufnr, pos_row, pos_col, ntype) ulog(query, lang, defaults, pos_row, pos_col) bufnr = bufnr or api.nvim_get_current_buf() + local key = tostring(bufnr) .. query local filetime = fn.getftime(fn.expand('%')) - if nodes[bufnr] ~= nil and nodestime[bufnr] ~= nil and filetime == nodestime[bufnr] then - return nodes[bufnr] + if nodes[key] ~= nil and nodestime[key] ~= nil and filetime == nodestime[key] then + return nodes[key] end - -- ulog(bufnr, nodestime[bufnr], filetime) + -- ulog(bufnr, nodestime[key], filetime) -- todo a huge number pos_row = pos_row or 30000 local success, parsed_query = pcall(function() @@ -222,8 +223,8 @@ M.get_all_nodes = function(query, lang, defaults, bufnr, pos_row, pos_col, ntype end end ulog('total nodes got: ' .. tostring(#results)) - nodes[bufnr] = results - nodestime[bufnr] = filetime + nodes[key] = results + nodestime[key] = filetime return results end diff --git a/lua/tests/go_comment_spec.lua b/lua/tests/go_comment_spec.lua index 1664423..6d731b9 100644 --- a/lua/tests/go_comment_spec.lua +++ b/lua/tests/go_comment_spec.lua @@ -1,33 +1,33 @@ local eq = assert.are.same -local busted = require("plenary/busted") -local cur_dir = vim.fn.expand("%:p:h") -describe("should get nodes ", function() +local busted = require('plenary/busted') +local cur_dir = vim.fn.expand('%:p:h') +describe('should get nodes ', function() _GO_NVIM_CFG.verbose = true - _GO_NVIM_CFG.comment_placeholder = "  " + _GO_NVIM_CFG.comment_placeholder = '  ' - local status = require("plenary.reload").reload_module("go.nvim") - status = require("plenary.reload").reload_module("nvim-treesitter/nvim-treesitter") + local status = require('plenary.reload').reload_module('go.nvim') + status = require('plenary.reload').reload_module('nvim-treesitter/nvim-treesitter') - local name = vim.fn.tempname() .. ".go" - print("tmp:" .. name) + local name = vim.fn.tempname() .. '.go' + print('tmp:' .. name) -- - local path = cur_dir .. "/lua/tests/fixtures/ts/playlist.go" -- %:p:h ? %:p + local path = cur_dir .. '/lua/tests/fixtures/ts/playlist.go' -- %:p:h ? %:p local lines = vim.fn.readfile(path) vim.fn.writefile(lines, name) local cmd = "silent exe 'e " .. name .. "'" vim.cmd(cmd) - local bufn = vim.fn.bufnr("") - it("should get struct playlist and generate comments", function() - vim.fn.setpos(".", { bufn, 20, 14, 0 }) - local query = require("go.comment").gen(20, 14) - eq("// createPlaylist function  ", query) + local bufn = vim.fn.bufnr('') + it('should get struct playlist and generate comments', function() + vim.fn.setpos('.', { bufn, 20, 14, 0 }) + local query = require('go.comment').gen(20, 14) + eq('// createPlaylist function  ', query) end) - it("should get struct playlist and generate comments", function() - vim.fn.setpos(".", { bufn, 14, 4, 0 }) - local query = require("go.comment").gen(14, 4) - eq("// playlist struct  ", query) + it('should get struct playlist and generate comments', function() + vim.fn.setpos('.', { bufn, 14, 4, 0 }) + local query = require('go.comment').gen(14, 4) + eq('// playlist struct  ', query) end) end)