Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
fix: small fixes + styling
Browse files Browse the repository at this point in the history
  • Loading branch information
luckasRanarison committed Nov 29, 2023
1 parent 6685d79 commit d38fc71
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
15 changes: 6 additions & 9 deletions lua/nvim-devdocs/operations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
19 changes: 17 additions & 2 deletions lua/nvim-devdocs/pickers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -141,15 +142,28 @@ 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({
results = entries,
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,
}),
Expand All @@ -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("%[([^%]]+)%]")
Expand Down
3 changes: 2 additions & 1 deletion lua/nvim-devdocs/transpiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions lua/nvim-devdocs/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d38fc71

Please sign in to comment.