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 nodes = require("go.ts.nodes")
local log = require("go.utils").log local log = require("go.utils").log
local warn = require("go.utils").warn
M = { M = {
-- query_struct = "(type_spec name:(type_identifier) @definition.struct type: (struct_type))", -- 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 bufn = bufnr or vim.api.nvim_get_current_buf()
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col) local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
if ns == nil then if ns == nil then
print("struct not found") warn("struct not found")
else else
log('struct node', ns) log('struct node', ns)
return ns[#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 bufn = bufnr or vim.api.nvim_get_current_buf()
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col) local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
if ns == nil then if ns == nil then
print("interface not found") warn("interface not found")
else else
return ns[#ns] return ns[#ns]
end 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) local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
if ns == nil then if ns == nil then
print("interface method not found") warn("interface method not found")
else else
return ns[#ns] return ns[#ns]
end end
@ -136,7 +137,7 @@ M.get_func_method_node_at_pos = function(row, col, bufnr)
return nil return nil
end end
if ns == nil then if ns == nil then
print("function not found") warn("function not found")
else else
return ns[#ns] return ns[#ns]
end end
@ -156,7 +157,7 @@ M.get_package_node_at_pos = function(row, col, bufnr)
return nil return nil
end end
if ns == nil then if ns == nil then
print("package not found") warn("package not found")
else else
return ns[#ns] return ns[#ns]
end end

@ -5,6 +5,7 @@ local parsers = require("nvim-treesitter.parsers")
local locals = require("nvim-treesitter.locals") local locals = require("nvim-treesitter.locals")
local utils = require("go.ts.utils") local utils = require("go.ts.utils")
local ulog = require("go.utils").log local ulog = require("go.utils").log
local warn = require("go.utils").warn
local M = {} local M = {}
@ -59,7 +60,7 @@ M.get_nodes = function(query, lang, defaults, bufnr)
return vim.treesitter.parse_query(lang, query) return vim.treesitter.parse_query(lang, query)
end) end)
if not success then 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 return nil
end 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) type = string.sub(path, 1, idx - 1)
ulog("node ", vim.inspect(node), ulog("node ", vim.inspect(node),
"\n path: " .. path .. " op: " .. op .. " type: " .. type .. "\n txt: " .. dbg_txt "\n path: " .. path .. " op: " .. op .. " type: " .. type .. "\n txt: " .. dbg_txt .. "\n range: "
.. "\n range: " .. tostring(a1) .. ":" .. tostring(b1) .. " TO " .. tostring(c1) .. tostring(a1) .. ":" .. tostring(b1) .. " TO " .. tostring(c1) .. ":" .. tostring(d1))
.. ":" .. tostring(d1))
-- --
-- may not handle complex node -- may not handle complex node
if op == "name" then if op == "name" then
@ -199,7 +199,7 @@ M.nodes_at_cursor = function(query, default, bufnr, row, col)
end end
local nodes = M.get_all_nodes(query, ft, default, bufnr, row, col) local nodes = M.get_all_nodes(query, ft, default, bufnr, row, col)
if nodes == nil then 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 return nil
end end

@ -48,7 +48,7 @@ util.check_same = function(tbl1, tbl2)
end end
util.map = function(modes, key, result, options) 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 local buffer = options.buffer
options.buffer = nil options.buffer = nil
@ -283,4 +283,17 @@ function util.all_pkgs()
return '.' .. util.sep() .. '...' return '.' .. util.sep() .. '...'
end 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 return util

Loading…
Cancel
Save