1
- local word = require (" word" )
1
+ local mod , map = require (" word.mod " ), require ( " word.util.maps " )
2
2
3
- local M = Mod .create (" data.todo" )
3
+ local M = mod .create (" data.todo" )
4
4
5
5
M .maps = function ()
6
- Map .nmap (" ,wt" , " <CMD>Telescope word todo<CR>" )
6
+ map .nmap (" ,wt" , " <CMD>Telescope word todo<CR>" )
7
7
end
8
8
9
+ --- @class word.data.todo.Data
9
10
M .data = {
10
- data = {
11
- namespace = vim .api .nvim_create_namespace (" word/todo" ),
11
+ namespace = vim .api .nvim_create_namespace (" word.data.todo" ),
12
12
13
- --- List of active buffers
14
- buffers = {},
15
- },
13
+ --- List of active buffers
14
+ buffers = {},
16
15
}
17
- --- @class base. todo
16
+ --- @class word.data. todo.Config
18
17
M .config .public = {
19
18
20
- -- Highlight group to display introspector in.
21
- --
22
- -- base to "Normal".
23
19
highlight_group = " Normal" ,
24
20
25
- --
26
- -- base to the following: `done`, `pending`, `undone`, `urgent`.
27
21
counted_statuses = {
28
22
" done" ,
29
23
" pending" ,
30
24
" undone" ,
31
25
" urgent" ,
32
26
},
33
27
34
- -- Which status should count towards the completed count (should be a subset of counted_statuses).
35
- --
36
- -- base to the following: `done`.
37
28
completed_statuses = {
38
29
" done" ,
39
30
},
40
31
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%)"
48
32
format = function (completed , total )
49
- -- stylua: ignore start
50
33
return string.format (
51
34
" [%d/%d] (%d%%)" ,
52
35
completed ,
53
36
total ,
54
37
(total ~= 0 and math.floor ((completed / total ) * 100 ) or 0 )
55
38
)
56
- -- stylua: ignore end
57
39
end ,
58
40
}
59
41
@@ -71,11 +53,11 @@ M.load = function()
71
53
callback = function (ev )
72
54
local buf = ev .buf
73
55
74
- if M .data .data . buffers [buf ] then
56
+ if M .data .buffers [buf ] then
75
57
return
76
58
end
77
59
78
- M .data .data . buffers [buf ] = true
60
+ M .data .buffers [buf ] = true
79
61
-- M.public.attach_introspector(buf) -- TODO
80
62
end ,
81
63
})
86
68
--- @param buffer number #The buffer ID to attach to.
87
69
function M .data .attach_introspector (buffer )
88
70
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"
91
73
then
92
74
error (
93
75
string.format (
@@ -122,15 +104,15 @@ function M.data.attach_introspector(buffer)
122
104
123
105
--- @type TSNode ?
124
106
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 )
126
108
127
109
if not node then
128
110
return
129
111
end
130
112
131
113
vim .api .nvim_buf_clear_namespace (
132
114
buffer ,
133
- M .data .data . namespace ,
115
+ M .data .namespace ,
134
116
first + 1 ,
135
117
first + 1
136
118
)
@@ -153,25 +135,25 @@ function M.data.attach_introspector(buffer)
153
135
introspect (node )
154
136
155
137
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
+ )
160
142
161
143
do
162
144
local todo_status = node_above :named_child (1 )
163
145
164
146
if
165
- todo_status and todo_status :type () == " detached_modifier_extension"
147
+ todo_status and todo_status :type () == " detached_modifier_extension"
166
148
then
167
149
introspect (node_above )
168
150
end
169
151
end
170
152
end ),
171
153
172
154
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
175
157
end ,
176
158
})
177
159
end
@@ -191,8 +173,8 @@ function M.data.calculate_items(node)
191
173
-- Go through all the children of the current todo item node and count the amount of "done" children
192
174
for child in node :iter_children () do
193
175
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"
196
178
then
197
179
for status in child :named_child (1 ):iter_children () do
198
180
if status :type ():match (" ^todo_item_" ) then
@@ -227,18 +209,13 @@ function M.data.perform_introspection(buffer, node)
227
209
228
210
local line , col = node :start ()
229
211
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 )
236
213
237
214
if total == 0 then
238
215
return
239
216
end
240
217
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 , {
242
219
virt_text = {
243
220
{
244
221
M .config .public .format (completed , total ),
@@ -249,4 +226,4 @@ function M.data.perform_introspection(buffer, node)
249
226
})
250
227
end
251
228
252
- return init
229
+ return M
0 commit comments