diff --git a/lua/hawtkeys/show_all.lua b/lua/hawtkeys/show_all.lua index bee6bed..321e9c8 100644 --- a/lua/hawtkeys/show_all.lua +++ b/lua/hawtkeys/show_all.lua @@ -3,21 +3,7 @@ local tsSearch = require("hawtkeys.ts") ---@return table function M.show_all() - local allKeys = tsSearch.get_all_keymaps() - local resultTable = {} - for _, data in ipairs(allKeys) do - table.insert( - resultTable, - tostring(data.lhs) - .. " " - .. tostring(data.rhs) - .. " (" - .. tostring(data.mode) - .. ") - " - .. tostring(data.from_file) - ) - end - return resultTable + return tsSearch.get_all_keymaps() end return M diff --git a/lua/hawtkeys/ts.lua b/lua/hawtkeys/ts.lua index ee83510..c8d9686 100644 --- a/lua/hawtkeys/ts.lua +++ b/lua/hawtkeys/ts.lua @@ -61,7 +61,7 @@ local function find_maps_in_file(file_path) end if not buf_local then - table.insert(tsKemaps, { + local map = { mode = vim.treesitter .get_node_text(node.node:child(1), file_content) :gsub("^%s*(['\"])(.*)%1%s*$", "%2") @@ -75,7 +75,26 @@ local function find_maps_in_file(file_path) :gsub("^%s*(['\"])(.*)%1%s*$", "%2") :gsub("[\n\r]", ""), from_file = file_path, - }) + } + + if map.mode:match("^%s*{.*},?.*$") then + local mode = {} + for i, child in + vim.iter(node.node:child(1):iter_children()) + :enumerate() + do + if i % 2 == 0 then + local ty = vim.treesitter + .get_node_text(child, file_content) + :gsub("['\"]", "") + :gsub("[\n\r]", "") + vim.print("type: " .. vim.inspect(ty)) + table.insert(mode, ty) + end + end + map.mode = table.concat(mode, ", ") + end + table.insert(tsKemaps, map) end end end diff --git a/lua/hawtkeys/ui.lua b/lua/hawtkeys/ui.lua index c92d677..a293b89 100644 --- a/lua/hawtkeys/ui.lua +++ b/lua/hawtkeys/ui.lua @@ -3,6 +3,8 @@ local Hawtkeys = require("hawtkeys.score") local ShowAll = require("hawtkeys.show_all") local showDuplicates = require("hawtkeys.duplicates") +local ns = vim.api.nvim_create_namespace("hawtkeys") + local ResultWin local ResultBuf local SearchWin @@ -192,7 +194,26 @@ M.show_all = function() height = height, footer = "Current Keybindings", }) - vim.api.nvim_buf_set_lines(ResultBuf, 0, -1, false, ShowAll.show_all()) + local all = ShowAll.show_all() + for i, data in ipairs(all) do + local l1 = tostring(data.lhs) + .. " (" + .. (data.mode or "n") + .. ") - " + .. tostring(data.from_file):gsub(vim.env.HOME, "~") + local l2 = tostring(data.rhs or "") + vim.api.nvim_buf_set_lines( + ResultBuf, + i == 1 and 0 or -1, + -1, + false, + { l1 } + ) + -- mapping rhs as extmark so the cursor skips over it + vim.api.nvim_buf_set_extmark(ResultBuf, ns, i - 1, 0, { + virt_lines = { { { l2, "Comment" } } }, + }) + end end M.show_dupes = function()