Skip to content

Commit

Permalink
updating todos, updating data todo, removing base todo mod
Browse files Browse the repository at this point in the history
  • Loading branch information
clpi committed Dec 4, 2024
1 parent 950ff17 commit 90b678a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 308 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- [ ] (easy) Remove all lingering instances of `[module].data.data` and merge into `[module].data`
- [ ] (easy) Consider another separation of tables and functions of a module
- [ ] (easy) Fix `ui.calendar` for `note` module
- [ ] (easy) Fix mod popup window buffer close error

## Low priority

Expand Down
6 changes: 5 additions & 1 deletion lua/word/mod/data/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---brief TODO: refactor mod/schema of modules so submodules can
--- load on `data` load also require the data module
--- for generic function, maybe implement in separate
--- util.lua file that is required for submodules
local M = require("word.mod").create("data", {
"log",
"mod",
Expand All @@ -8,6 +12,7 @@ local M = require("word.mod").create("data", {
"media",
"template",
"metadata",
"todo",
"save",
-- "code",
})
Expand All @@ -23,7 +28,6 @@ M.setup = function()
end

M.config.public = {
-- Full path to store data (saved in mpack data format)
path = vim.fn.stdpath("data") .. "/word.mpack",
}

Expand Down
14 changes: 7 additions & 7 deletions lua/word/mod/data/metadata/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
local M = Mod.create("data.metadata")
local mod = require("word.mod")

local M = mod.create("data.metadata")

M.setup = function()
return {
Expand All @@ -10,12 +12,13 @@ M.setup = function()
}
end

---@class word.data.metadata.Config
M.config.public = {
fields = {},
}

M.load = function()
Mod.await("cmd", function(cmd)
mod.await("cmd", function(cmd)
cmd.add_commands_from_table({
meta = {
subcommands = {
Expand All @@ -38,10 +41,7 @@ M.load = function()
end)
end

M.config.public = {}

M.data.data = {}

---@class word.data.metadata.Data
M.data = {
buf_inject_frontmatter = function()
local id = ""
Expand All @@ -68,6 +68,6 @@ M.events.subscribed = {
},
}

M.on_event = function(e) end
M.on_event = function() end

return M
75 changes: 26 additions & 49 deletions lua/word/mod/data/todo/init.lua
Original file line number Diff line number Diff line change
@@ -1,59 +1,41 @@
local word = require("word")
local mod, map = require("word.mod"), require("word.util.maps")

local M = Mod.create("data.todo")
local M = mod.create("data.todo")

M.maps = function()
Map.nmap(",wt", "<CMD>Telescope word todo<CR>")
map.nmap(",wt", "<CMD>Telescope word todo<CR>")
end

---@class word.data.todo.Data
M.data = {
data = {
namespace = vim.api.nvim_create_namespace("word/todo"),
namespace = vim.api.nvim_create_namespace("word.data.todo"),

--- List of active buffers
buffers = {},
},
--- List of active buffers
buffers = {},
}
---@class base.todo
---@class word.data.todo.Config
M.config.public = {

-- Highlight group to display introspector in.
--
-- base to "Normal".
highlight_group = "Normal",

--
-- base to the following: `done`, `pending`, `undone`, `urgent`.
counted_statuses = {
"done",
"pending",
"undone",
"urgent",
},

-- Which status should count towards the completed count (should be a subset of counted_statuses).
--
-- base to the following: `done`.
completed_statuses = {
"done",
},

-- Callback to format introspector. Takes in two parameters:
-- * `completed`: number of completed tasks
-- * `total`: number of total counted tasks
--
-- Should return a string with the format you want to display the introspector in.
--
-- base to "[completed/total] (progress%)"
format = function(completed, total)
-- stylua: ignore start
return string.format(
"[%d/%d] (%d%%)",
completed,
total,
(total ~= 0 and math.floor((completed / total) * 100) or 0)
)
-- stylua: ignore end
end,
}

Expand All @@ -71,11 +53,11 @@ M.load = function()
callback = function(ev)
local buf = ev.buf

if M.data.data.buffers[buf] then
if M.data.buffers[buf] then
return
end

M.data.data.buffers[buf] = true
M.data.buffers[buf] = true
-- M.public.attach_introspector(buf) -- TODO
end,
})
Expand All @@ -86,8 +68,8 @@ end
---@param buffer number #The buffer ID to attach to.
function M.data.attach_introspector(buffer)
if
not vim.api.nvim_buf_is_valid(buffer)
or vim.bo[buffer].filetype ~= "markdown"
not vim.api.nvim_buf_is_valid(buffer)
or vim.bo[buffer].filetype ~= "markdown"
then
error(
string.format(
Expand Down Expand Up @@ -122,15 +104,15 @@ function M.data.attach_introspector(buffer)

---@type TSNode?
local node =
M.required["integration.treesitter"].get_first_node_on_line(buf, first)
M.required["integration.treesitter"].get_first_node_on_line(buf, first)

if not node then
return
end

vim.api.nvim_buf_clear_namespace(
buffer,
M.data.data.namespace,
M.data.namespace,
first + 1,
first + 1
)
Expand All @@ -153,25 +135,25 @@ function M.data.attach_introspector(buffer)
introspect(node)

local node_above =
M.required["integration.treesitter"].get_first_node_on_line(
buf,
first - 1
)
M.required["integration.treesitter"].get_first_node_on_line(
buf,
first - 1
)

do
local todo_status = node_above:named_child(1)

if
todo_status and todo_status:type() == "detached_modifier_extension"
todo_status and todo_status:type() == "detached_modifier_extension"
then
introspect(node_above)
end
end
end),

on_detach = function()
vim.api.nvim_buf_clear_namespace(buffer, M.data.data.namespace, 0, -1)
M.data.data.buffers[buffer] = nil
vim.api.nvim_buf_clear_namespace(buffer, M.data.namespace, 0, -1)
M.data.buffers[buffer] = nil
end,
})
end
Expand All @@ -191,8 +173,8 @@ function M.data.calculate_items(node)
-- Go through all the children of the current todo item node and count the amount of "done" children
for child in node:iter_children() do
if
child:named_child(1)
and child:named_child(1):type() == "detached_modifier_extension"
child:named_child(1)
and child:named_child(1):type() == "detached_modifier_extension"
then
for status in child:named_child(1):iter_children() do
if status:type():match("^todo_item_") then
Expand Down Expand Up @@ -227,18 +209,13 @@ function M.data.perform_introspection(buffer, node)

local line, col = node:start()

vim.api.nvim_buf_clear_namespace(
buffer,
M.data.data.namespace,
line,
line + 1
)
vim.api.nvim_buf_clear_namespace(buffer, M.data.namespace, line, line + 1)

if total == 0 then
return
end

vim.api.nvim_buf_set_extmark(buffer, M.data.data.namespace, line, col, {
vim.api.nvim_buf_set_extmark(buffer, M.data.namespace, line, col, {
virt_text = {
{
M.config.public.format(completed, total),
Expand All @@ -249,4 +226,4 @@ function M.data.perform_introspection(buffer, node)
})
end

return init
return M
1 change: 1 addition & 0 deletions lua/word/mod/edit/todo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# `edit.todo`
Loading

0 comments on commit 90b678a

Please sign in to comment.