Add warn messages

pull/44/head
ray-x 3 years ago
parent 2b284a47d9
commit f59422008a

@ -1,6 +1,7 @@
local nodes = require("go.ts.nodes")
local log = require("go.utils").log
local warn = require("go.utils").warn
M = {
-- query_struct = "(type_spec name:(type_identifier) @definition.struct type: (struct_type))",
@ -94,7 +95,7 @@ M.get_struct_node_at_pos = function(row, col, bufnr)
local bufn = bufnr or vim.api.nvim_get_current_buf()
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
if ns == nil then
print("struct not found")
warn("struct not found")
else
log('struct node', ns)
return ns[#ns]
@ -107,7 +108,7 @@ M.get_interface_node_at_pos = function(row, col, bufnr)
local bufn = bufnr or vim.api.nvim_get_current_buf()
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
if ns == nil then
print("interface not found")
warn("interface not found")
else
return ns[#ns]
end
@ -119,7 +120,7 @@ M.get_interface_method_node_at_pos = function(row, col, bufnr)
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
if ns == nil then
print("interface method not found")
warn("interface method not found")
else
return ns[#ns]
end
@ -136,7 +137,7 @@ M.get_func_method_node_at_pos = function(row, col, bufnr)
return nil
end
if ns == nil then
print("function not found")
warn("function not found")
else
return ns[#ns]
end
@ -156,7 +157,7 @@ M.get_package_node_at_pos = function(row, col, bufnr)
return nil
end
if ns == nil then
print("package not found")
warn("package not found")
else
return ns[#ns]
end

@ -5,6 +5,7 @@ local parsers = require("nvim-treesitter.parsers")
local locals = require("nvim-treesitter.locals")
local utils = require("go.ts.utils")
local ulog = require("go.utils").log
local warn = require("go.utils").warn
local M = {}
@ -59,7 +60,7 @@ M.get_nodes = function(query, lang, defaults, bufnr)
return vim.treesitter.parse_query(lang, query)
end)
if not success then
print("treesitter parse failed, make sure treesitter installed and setup correctly")
warn("treesitter parse failed, make sure treesitter installed and setup correctly")
return nil
end
@ -154,9 +155,8 @@ M.get_all_nodes = function(query, lang, defaults, bufnr, pos_row, pos_col)
type = string.sub(path, 1, idx - 1)
ulog("node ", vim.inspect(node),
"\n path: " .. path .. " op: " .. op .. " type: " .. type .. "\n txt: " .. dbg_txt
.. "\n range: " .. tostring(a1) .. ":" .. tostring(b1) .. " TO " .. tostring(c1)
.. ":" .. tostring(d1))
"\n path: " .. path .. " op: " .. op .. " type: " .. type .. "\n txt: " .. dbg_txt .. "\n range: "
.. tostring(a1) .. ":" .. tostring(b1) .. " TO " .. tostring(c1) .. ":" .. tostring(d1))
--
-- may not handle complex node
if op == "name" then
@ -199,7 +199,7 @@ M.nodes_at_cursor = function(query, default, bufnr, row, col)
end
local nodes = M.get_all_nodes(query, ft, default, bufnr, row, col)
if nodes == nil then
print("Unable to find any nodes. Is your query correct?")
print("Unable to find any nodes. place your cursor on a go symbol and try again")
return nil
end

@ -48,7 +48,7 @@ util.check_same = function(tbl1, tbl2)
end
util.map = function(modes, key, result, options)
options = M.merge({noremap = true, silent = false, expr = false, nowait = false}, options or {})
options = util.merge({noremap = true, silent = false, expr = false, nowait = false}, options or {})
local buffer = options.buffer
options.buffer = nil
@ -283,4 +283,17 @@ function util.all_pkgs()
return '.' .. util.sep() .. '...'
end
-- log and messages
function util.warn(msg)
vim.api.nvim_echo({{"WRN: " .. msg, "WarningMsg"}}, true, {})
end
function util.error(msg)
vim.api.nvim_echo({{"ERR: " .. msg, "ErrorMsg"}}, true, {})
end
function util.info(msg)
vim.api.nvim_echo({{"Info: " .. msg}}, true, {})
end
return util

Loading…
Cancel
Save