diff --git a/lua/nvim-devdocs/operations.lua b/lua/nvim-devdocs/operations.lua index e3499c0..e50909f 100644 --- a/lua/nvim-devdocs/operations.lua +++ b/lua/nvim-devdocs/operations.lua @@ -177,15 +177,13 @@ M.get_all_entries = function() local entries_count = #index.entries for idx, doc_entry in ipairs(index.entries) do local next_path = nil - if idx < entries_count then - next_path = index.entries[idx+1].path - end + if idx < entries_count then next_path = index.entries[idx + 1].path end local entry = { - name = string.format("[%s] %s", alias, doc_entry.name), - alias = alias, + name = doc_entry.name, path = doc_entry.path, - next_path = next_path, link = doc_entry.link, + alias = alias, + next_path = next_path, } table.insert(entries, entry) end @@ -204,9 +202,7 @@ M.read_entry = function(entry, callback) file_path:_read_async(vim.schedule_wrap(function(content) local pattern = splited_path[2] local next_pattern = nil - if entry.next_path ~= nil then - next_pattern = vim.split(entry.next_path, ",")[2] - end + if entry.next_path ~= nil then next_pattern = vim.split(entry.next_path, ",")[2] end local lines = vim.split(content, "\n") local filtered_lines = M.filter_doc(lines, pattern, next_pattern) @@ -305,6 +301,7 @@ M.open = function(entry, bufnr, float) vim.wo[win].linebreak = config.options.wrap vim.wo[win].nu = false vim.wo[win].relativenumber = false + vim.wo[win].conceallevel = 3 end local ignore = vim.tbl_contains(config.options.cmd_ignore, entry.alias) diff --git a/lua/nvim-devdocs/pickers.lua b/lua/nvim-devdocs/pickers.lua index 177e557..e684ab0 100644 --- a/lua/nvim-devdocs/pickers.lua +++ b/lua/nvim-devdocs/pickers.lua @@ -7,6 +7,7 @@ local state = require("telescope.state") local actions = require("telescope.actions") local action_state = require("telescope.actions.state") local config = require("telescope.config").values +local entry_display = require("telescope.pickers.entry_display") local list = require("nvim-devdocs.list") local notify = require("nvim-devdocs.notify") @@ -141,6 +142,14 @@ end ---@param entries DocEntry[] ---@param float? boolean M.open_picker = function(entries, float) + local displayer = entry_display.create({ + separator = " ", + items = { + { remaining = true }, + { remaining = true }, + }, + }) + local picker = pickers.new(plugin_config.options.telescope, { prompt_title = "Select an entry", finder = finders.new_table({ @@ -148,8 +157,13 @@ M.open_picker = function(entries, float) entry_maker = function(entry) return { value = entry, - display = entry.name, - ordinal = entry.name, + display = function() + return displayer({ + { string.format("[%s]", entry.alias), "markdownH1" }, + { entry.name, "markdownH2" }, + }) + end, + ordinal = string.format("[%s] %s", entry.alias, entry.name), } end, }), @@ -160,6 +174,7 @@ M.open_picker = function(entries, float) actions.close(prompt_bufnr) local selection = action_state.get_selected_entry() + if selection then local name = selection.value.name local match = name:match("%[([^%]]+)%]") diff --git a/lua/nvim-devdocs/transpiler.lua b/lua/nvim-devdocs/transpiler.lua index e3e848b..531731c 100644 --- a/lua/nvim-devdocs/transpiler.lua +++ b/lua/nvim-devdocs/transpiler.lua @@ -323,13 +323,14 @@ function transpiler:eval(node) local id = attributes.id if id and self.section_map and vim.tbl_contains(self.section_map, id) then - table.insert(self.sections, {id = id, md_path = vim.trim(result)}) + table.insert(self.sections, { id = id, md_path = vim.trim(result) }) end return result end ---@param node TSNode +---@param parent_node TSNode ---@return string function transpiler:eval_child(node, parent_node) local result = self:eval(node) diff --git a/lua/nvim-devdocs/types.lua b/lua/nvim-devdocs/types.lua index 87d3a2b..ab60f8d 100644 --- a/lua/nvim-devdocs/types.lua +++ b/lua/nvim-devdocs/types.lua @@ -12,10 +12,11 @@ ---@field attribution string ---Represents an entry in the index.json file ----NOTE: alias is filled at runtime +---NOTE: alias and next_path are filled at runtime ---@see nvim_devdocs_path/index.json ---@class DocEntry ---@field name string ---@field path string ---@field link string ----@field alias string +---@field alias? string +---@field next_path? string