From e3d33952da4cfc8e0d7211814284cf21c6dad854 Mon Sep 17 00:00:00 2001 From: ray-x Date: Mon, 21 Oct 2024 11:21:50 +1100 Subject: [PATCH] add logs --- lua/go/gotest.lua | 20 ++++++++++++++------ lua/go/ts/go.lua | 4 ++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lua/go/gotest.lua b/lua/go/gotest.lua index bc34d1b7a..19050ba92 100644 --- a/lua/go/gotest.lua +++ b/lua/go/gotest.lua @@ -118,6 +118,7 @@ local function get_test_filebufnr() fn = vfn.fnamemodify(fn, ':p') -- expand to full path -- check if file exists if vfn.filereadable(fn) == 0 then + vim.notify('no test file found for ' .. fn, vim.log.levels.WARN) return 0, 'no test file' end local uri = vim.uri_from_fname(fn) @@ -506,7 +507,9 @@ M.test_func = function(...) if not ok or not p then -- require('nvim-treesitter.install').commands.TSInstallSync['run!']('go') vim.notify( - 'go treesitter parser not found, please Run `:TSInstallSync go`', + 'go treesitter parser not found for file ' + .. vim.fn.bufname() + .. ' please Run `:TSInstallSync go` ', vim.log.levels.WARN ) end @@ -666,11 +669,16 @@ end -- https://github.com/rentziass/dotfiles/blob/master/vim/.config/nvim/lua/rentziass/lsp/go_tests.lua M.run_file = function() local bufnr = vim.api.nvim_get_current_buf() - local tree = vim.treesitter.get_parser(bufnr, 'go'):parse()[1] + local ok, parser = vim.treesitter.get_parser(bufnr, 'go') + if not ok or not parser then + vim.notify('go treesitter parser not found for ' .. vim.fn.bufname(), vim.log.levels.WARN) + return log('no ts parser found') + end + local tree = parser:parse()[1] local query = parse('go', require('go.ts.textobjects').query_test_func) local test_names = {} - local get_node_text=vim.treesitter.get_node_text + local get_node_text = vim.treesitter.get_node_text for id, node in query:iter_captures(tree:root(), bufnr, 0, -1) do local name = query.captures[id] -- name of the capture in the query if name == 'test_name' then @@ -692,15 +700,15 @@ M.get_testfunc = function() -- Note: the buffer may not be loaded yet local ok, parser = vim.treesitter.get_parser(bufnr, 'go') if not ok or not parser then + vim.notify('go treesitter parser not found for ' .. vim.fn.bufname(), vim.log.levels.WARN) return log('no parser found') end - local tree = parser:parse() - tree = tree[1] + local tree = parser:parse()[1] local query = parse('go', require('go.ts.go').query_test_func) local test_names = {} - local get_node_text=vim.treesitter.get_node_text + local get_node_text = vim.treesitter.get_node_text for id, node in query:iter_captures(tree:root(), bufnr, 0, -1) do local name = query.captures[id] -- name of the capture in the query log(node) diff --git a/lua/go/ts/go.lua b/lua/go/ts/go.lua index 056746f2f..d589fe497 100644 --- a/lua/go/ts/go.lua +++ b/lua/go/ts/go.lua @@ -194,7 +194,7 @@ M.get_tbl_testcase_node_name = function(bufnr) local bufn = bufnr or vim.api.nvim_get_current_buf() local parser = vim.treesitter.get_parser(bufn, 'go') if not parser then - return warn('treesitter parser not found') + return warn('treesitter parser not found for' .. vim.fn.bufname(bufn)) end local tree = parser:parse() tree = tree[1] @@ -226,7 +226,7 @@ M.get_sub_testcase_name = function(bufnr) local bufn = bufnr or vim.api.nvim_get_current_buf() local parser = vim.treesitter.get_parser(bufn, 'go') if not parser then - return warn('treesitter parser not found') + return warn('treesitter parser not found for ' .. vim.fn.bufname(bufn)) end local sub_case_query = vim.treesitter.query.parse('go', M.query_sub_testcase_node)