Skip to content

Commit

Permalink
add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-x committed Oct 21, 2024
1 parent 5b070bf commit e3d3395
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions lua/go/gotest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lua/go/ts/go.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e3d3395

Please sign in to comment.