Skip to content

Commit

Permalink
fix(find_aof_tasks): fixed preview
Browse files Browse the repository at this point in the history
  • Loading branch information
max397574 committed Mar 30, 2022
1 parent 7bd9467 commit 4dc6699
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
16 changes: 8 additions & 8 deletions lua/neorg/telescope_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ local ns = vim.api.nvim_create_namespace("neorg-gtd-picker")

--- Neorg task states: `["<task-state>"] = { "- [<sth>] ",<highlight>}`
utils.states = {
["undone"] = { "-[ ] ", "NeorgTodoItem1Undone" },
["done"] = { "-[x] ", "NeorgTodoItem1Done" },
["pending"] = { "-[-] ", "NeorgTodoItem1Pending" },
["cancelled"] = { "-[_] ", "NeorgTodoItem1Cancelled" },
["uncertain"] = { "-[?] ", "NeorgTodoItem1Uncertain" },
["urgent"] = { "-[!] ", "NeorgTodoItem1Urgent" },
["recurring"] = { "-[+] ", "NeorgTodoItem1Recurring" },
["on_hold"] = { "-[=] ", "NeorgTodoItem1OnHold" },
["undone"] = { "- [ ] ", "NeorgTodoItem1Undone" },
["done"] = { "- [x] ", "NeorgTodoItem1Done" },
["pending"] = { "- [-] ", "NeorgTodoItem1Pending" },
["cancelled"] = { "- [_] ", "NeorgTodoItem1Cancelled" },
["uncertain"] = { "- [?] ", "NeorgTodoItem1Uncertain" },
["urgent"] = { "- [!] ", "NeorgTodoItem1Urgent" },
["recurring"] = { "- [+] ", "NeorgTodoItem1Recurring" },
["on_hold"] = { "- [=] ", "NeorgTodoItem1OnHold" },
}

--- Gets all gtd projects
Expand Down
30 changes: 27 additions & 3 deletions lua/telescope/_extensions/neorg/find_aof_tasks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ local function get_aof_projects()
return projects_by_aof
end

local function get_aof_tasks(aof)
local project_tasks = utils.get_project_tasks()
local aof_projects = get_aof_projects()
local raw_tasks = {}
local tasks = {}
local highlights = {}
for _, project in ipairs(aof_projects[aof]) do
local pr_tasks = project_tasks[project.uuid]
if pr_tasks and pr_tasks ~= {} then
for _, task in ipairs(pr_tasks) do
table.insert(raw_tasks, task)
end
end
end
for _, task in ipairs(raw_tasks) do
table.insert(tasks, states[task.state][1] .. task.content)
table.insert(highlights, states[task.state][2])
end
return tasks, highlights
end

local function pick_aof_tasks(aof)
local project_tasks = utils.get_project_tasks()
local aof_projects = get_aof_projects()
Expand Down Expand Up @@ -150,7 +171,7 @@ return function(opts)
local function make_display(ent)
local display = ent.value
if display == "_" then
display = "Projects without aof"
display = "Tasks without aof"
end
return displayer({
{
Expand Down Expand Up @@ -179,9 +200,12 @@ return function(opts)
}),
previewer = previewers.new_buffer_previewer({
define_preview = function(self, entry, status)
local projects_preview = get_project_list(entry.value)
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, true, projects_preview)
local tasks, highlights = get_aof_tasks(entry.value)
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, true, tasks)
vim.bo[self.state.bufnr].filetype = "norg"
for i, highlight in ipairs(highlights) do
vim.api.nvim_buf_add_highlight(self.state.bufnr, ns, highlight, i - 1, 0, 5)
end
end,
}),
sorter = conf.generic_sorter(opts),
Expand Down

0 comments on commit 4dc6699

Please sign in to comment.