Skip to content

Commit 90b678a

Browse files
committed
updating todos, updating data todo, removing base todo mod
1 parent 950ff17 commit 90b678a

File tree

6 files changed

+40
-308
lines changed

6 files changed

+40
-308
lines changed

TODO.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- [ ] (easy) Remove all lingering instances of `[module].data.data` and merge into `[module].data`
2323
- [ ] (easy) Consider another separation of tables and functions of a module
2424
- [ ] (easy) Fix `ui.calendar` for `note` module
25+
- [ ] (easy) Fix mod popup window buffer close error
2526

2627
## Low priority
2728

lua/word/mod/data/init.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---brief TODO: refactor mod/schema of modules so submodules can
2+
--- load on `data` load also require the data module
3+
--- for generic function, maybe implement in separate
4+
--- util.lua file that is required for submodules
15
local M = require("word.mod").create("data", {
26
"log",
37
"mod",
@@ -8,6 +12,7 @@ local M = require("word.mod").create("data", {
812
"media",
913
"template",
1014
"metadata",
15+
"todo",
1116
"save",
1217
-- "code",
1318
})
@@ -23,7 +28,6 @@ M.setup = function()
2328
end
2429

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

lua/word/mod/data/metadata/init.lua

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
local M = Mod.create("data.metadata")
1+
local mod = require("word.mod")
2+
3+
local M = mod.create("data.metadata")
24

35
M.setup = function()
46
return {
@@ -10,12 +12,13 @@ M.setup = function()
1012
}
1113
end
1214

15+
---@class word.data.metadata.Config
1316
M.config.public = {
1417
fields = {},
1518
}
1619

1720
M.load = function()
18-
Mod.await("cmd", function(cmd)
21+
mod.await("cmd", function(cmd)
1922
cmd.add_commands_from_table({
2023
meta = {
2124
subcommands = {
@@ -38,10 +41,7 @@ M.load = function()
3841
end)
3942
end
4043

41-
M.config.public = {}
42-
43-
M.data.data = {}
44-
44+
---@class word.data.metadata.Data
4545
M.data = {
4646
buf_inject_frontmatter = function()
4747
local id = ""
@@ -68,6 +68,6 @@ M.events.subscribed = {
6868
},
6969
}
7070

71-
M.on_event = function(e) end
71+
M.on_event = function() end
7272

7373
return M

lua/word/mod/data/todo/init.lua

+26-49
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,41 @@
1-
local word = require("word")
1+
local mod, map = require("word.mod"), require("word.util.maps")
22

3-
local M = Mod.create("data.todo")
3+
local M = mod.create("data.todo")
44

55
M.maps = function()
6-
Map.nmap(",wt", "<CMD>Telescope word todo<CR>")
6+
map.nmap(",wt", "<CMD>Telescope word todo<CR>")
77
end
88

9+
---@class word.data.todo.Data
910
M.data = {
10-
data = {
11-
namespace = vim.api.nvim_create_namespace("word/todo"),
11+
namespace = vim.api.nvim_create_namespace("word.data.todo"),
1212

13-
--- List of active buffers
14-
buffers = {},
15-
},
13+
--- List of active buffers
14+
buffers = {},
1615
}
17-
---@class base.todo
16+
---@class word.data.todo.Config
1817
M.config.public = {
1918

20-
-- Highlight group to display introspector in.
21-
--
22-
-- base to "Normal".
2319
highlight_group = "Normal",
2420

25-
--
26-
-- base to the following: `done`, `pending`, `undone`, `urgent`.
2721
counted_statuses = {
2822
"done",
2923
"pending",
3024
"undone",
3125
"urgent",
3226
},
3327

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

41-
-- Callback to format introspector. Takes in two parameters:
42-
-- * `completed`: number of completed tasks
43-
-- * `total`: number of total counted tasks
44-
--
45-
-- Should return a string with the format you want to display the introspector in.
46-
--
47-
-- base to "[completed/total] (progress%)"
4832
format = function(completed, total)
49-
-- stylua: ignore start
5033
return string.format(
5134
"[%d/%d] (%d%%)",
5235
completed,
5336
total,
5437
(total ~= 0 and math.floor((completed / total) * 100) or 0)
5538
)
56-
-- stylua: ignore end
5739
end,
5840
}
5941

@@ -71,11 +53,11 @@ M.load = function()
7153
callback = function(ev)
7254
local buf = ev.buf
7355

74-
if M.data.data.buffers[buf] then
56+
if M.data.buffers[buf] then
7557
return
7658
end
7759

78-
M.data.data.buffers[buf] = true
60+
M.data.buffers[buf] = true
7961
-- M.public.attach_introspector(buf) -- TODO
8062
end,
8163
})
@@ -86,8 +68,8 @@ end
8668
---@param buffer number #The buffer ID to attach to.
8769
function M.data.attach_introspector(buffer)
8870
if
89-
not vim.api.nvim_buf_is_valid(buffer)
90-
or vim.bo[buffer].filetype ~= "markdown"
71+
not vim.api.nvim_buf_is_valid(buffer)
72+
or vim.bo[buffer].filetype ~= "markdown"
9173
then
9274
error(
9375
string.format(
@@ -122,15 +104,15 @@ function M.data.attach_introspector(buffer)
122104

123105
---@type TSNode?
124106
local node =
125-
M.required["integration.treesitter"].get_first_node_on_line(buf, first)
107+
M.required["integration.treesitter"].get_first_node_on_line(buf, first)
126108

127109
if not node then
128110
return
129111
end
130112

131113
vim.api.nvim_buf_clear_namespace(
132114
buffer,
133-
M.data.data.namespace,
115+
M.data.namespace,
134116
first + 1,
135117
first + 1
136118
)
@@ -153,25 +135,25 @@ function M.data.attach_introspector(buffer)
153135
introspect(node)
154136

155137
local node_above =
156-
M.required["integration.treesitter"].get_first_node_on_line(
157-
buf,
158-
first - 1
159-
)
138+
M.required["integration.treesitter"].get_first_node_on_line(
139+
buf,
140+
first - 1
141+
)
160142

161143
do
162144
local todo_status = node_above:named_child(1)
163145

164146
if
165-
todo_status and todo_status:type() == "detached_modifier_extension"
147+
todo_status and todo_status:type() == "detached_modifier_extension"
166148
then
167149
introspect(node_above)
168150
end
169151
end
170152
end),
171153

172154
on_detach = function()
173-
vim.api.nvim_buf_clear_namespace(buffer, M.data.data.namespace, 0, -1)
174-
M.data.data.buffers[buffer] = nil
155+
vim.api.nvim_buf_clear_namespace(buffer, M.data.namespace, 0, -1)
156+
M.data.buffers[buffer] = nil
175157
end,
176158
})
177159
end
@@ -191,8 +173,8 @@ function M.data.calculate_items(node)
191173
-- Go through all the children of the current todo item node and count the amount of "done" children
192174
for child in node:iter_children() do
193175
if
194-
child:named_child(1)
195-
and child:named_child(1):type() == "detached_modifier_extension"
176+
child:named_child(1)
177+
and child:named_child(1):type() == "detached_modifier_extension"
196178
then
197179
for status in child:named_child(1):iter_children() do
198180
if status:type():match("^todo_item_") then
@@ -227,18 +209,13 @@ function M.data.perform_introspection(buffer, node)
227209

228210
local line, col = node:start()
229211

230-
vim.api.nvim_buf_clear_namespace(
231-
buffer,
232-
M.data.data.namespace,
233-
line,
234-
line + 1
235-
)
212+
vim.api.nvim_buf_clear_namespace(buffer, M.data.namespace, line, line + 1)
236213

237214
if total == 0 then
238215
return
239216
end
240217

241-
vim.api.nvim_buf_set_extmark(buffer, M.data.data.namespace, line, col, {
218+
vim.api.nvim_buf_set_extmark(buffer, M.data.namespace, line, col, {
242219
virt_text = {
243220
{
244221
M.config.public.format(completed, total),
@@ -249,4 +226,4 @@ function M.data.perform_introspection(buffer, node)
249226
})
250227
end
251228

252-
return init
229+
return M

lua/word/mod/edit/todo/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# `edit.todo`

0 commit comments

Comments
 (0)