@@ -123,8 +123,9 @@ module.load = function()
123
123
for _ , datapoint in ipairs (data ) do
124
124
table.insert (
125
125
result ,
126
- -- TODO each item _SHOULD BE_ a list item,
127
- -- but for now, the parser barfs on list items (or headings) inside a ranged tag
126
+ -- TODO each line _SHOULD BE_ a list item,
127
+ -- but due to an apparent bug, treesitter currently barfs on list items (or headings) inside a ranged tag.
128
+ -- :InspectTree shows an "ERROR" instead of the ranged_tag node.
128
129
table.concat ({
129
130
prefix ,
130
131
" _ {:$" ,
@@ -165,71 +166,67 @@ module.events.subscribed = {
165
166
},
166
167
}
167
168
168
-
169
169
module .private = {
170
- find_existing_summary = function (buffer , root )
171
- local query_str = neorg .lib .match (" all" )({
172
- _ = [[
170
+ find_existing_summary = function (buffer , root )
171
+ local query_str = neorg .lib .match (" all" )({
172
+ _ = [[
173
173
(ranged_tag
174
174
name: (tag_name) @_tag_name
175
175
(#eq? @_tag_name "group")
176
176
)
177
177
]] ,
178
- })
179
-
180
- local query = neorg .utils .ts_parse_query (" norg" , query_str )
181
- for _ , node in query :iter_captures (root , buffer , 0 , - 1 ) do
182
- -- node is the tag_name. we need its parent node
183
- local ranged_tag = node :parent ()
184
- for child in ranged_tag :iter_children () do
185
- if child :type () == " tag_parameters" then
186
- local _ , param = child :iter_children ()
187
- local text = module .required [" core.integrations.treesitter" ].get_node_text (param )
188
- if text == " summary" then
189
- return ranged_tag
190
- end
178
+ })
179
+
180
+ local query = neorg .utils .ts_parse_query (" norg" , query_str )
181
+ for _ , node in query :iter_captures (root , buffer , 0 , - 1 ) do
182
+ -- node is the tag_name. we need its parent node
183
+ local ranged_tag = node :parent ()
184
+ for child in ranged_tag :iter_children () do
185
+ if child :type () == " tag_parameters" then
186
+ local _ , param = child :iter_children ()
187
+ local text = module .required [" core.integrations.treesitter" ].get_node_text (param )
188
+ if text == " summary" then
189
+ return ranged_tag
190
+ end
191
+ end
191
192
end
192
193
end
193
- end
194
- return nil
195
- end
194
+ return nil
195
+ end ,
196
196
}
197
197
198
198
module .on_event = function (event )
199
199
if event .type == " core.neorgcmd.events.summary.summarize" then
200
200
local ts = module .required [" core.integrations.treesitter" ]
201
201
local buffer = event .buffer
202
202
203
-
204
203
local start_line = event .cursor_position [1 ]
205
204
local end_line = start_line
206
205
local existing = module .private .find_existing_summary (buffer , ts .get_document_root (buffer ))
207
206
local heading_level = 0
208
207
if existing ~= nil then
209
- -- neorg.utils.notify("matched: " .. existing.type())
210
- start_line , _ = existing :start ()
211
- end_line , _ = existing :end_ ()
212
- end_line = end_line + 1
213
- local level = tonumber (string.sub (existing :type (), - 1 ))
214
- if level ~= nil then
215
- heading_level = level
216
- end
208
+ start_line , _ = existing :start ()
209
+ end_line , _ = existing :end_ ()
210
+ end_line = end_line + 1
211
+ local level = tonumber (string.sub (existing :type (), - 1 ))
212
+ if level ~= nil then
213
+ heading_level = level
214
+ end
217
215
else
218
- local node_at_cursor = ts .get_first_node_on_line (buffer , event .cursor_position [1 ] - 1 )
219
- if not node_at_cursor or not node_at_cursor :type ():match (" ^heading%d$" ) then
220
- neorg .utils .notify (
221
- " No heading under cursor! Please move your cursor under the heading you'd like to generate the summary under."
222
- )
223
- return
224
- end
225
- -- heading level of 'node_at_cursor' (summary headings should be one level deeper)
226
- local level = tonumber (string.sub (node_at_cursor :type (), - 1 ))
227
- if level ~= nil then
228
- heading_level = level
229
- end
216
+ local node_at_cursor = ts .get_first_node_on_line (buffer , event .cursor_position [1 ] - 1 )
217
+ if not node_at_cursor or not node_at_cursor :type ():match (" ^heading%d$" ) then
218
+ neorg .utils .notify (
219
+ " No heading under cursor! Please move your cursor under the heading you'd like to generate the summary under."
220
+ )
221
+ return
222
+ end
223
+ -- heading level of 'node_at_cursor' (summary headings should be one level deeper)
224
+ local level = tonumber (string.sub (node_at_cursor :type (), - 1 ))
225
+ if level ~= nil then
226
+ heading_level = level
227
+ end
230
228
end
231
229
232
-
233
230
local dirman = neorg .modules .get_module (" core.dirman" )
234
231
235
232
if not dirman then
@@ -240,11 +237,8 @@ module.on_event = function(event)
240
237
local current_workspace = dirman .get_current_workspace ()
241
238
local ws_name = current_workspace [1 ]
242
239
local ws_root = current_workspace [2 ]
243
- local generated = module .config .public .strategy (
244
- dirman .get_norg_files (ws_name ) or {},
245
- ws_root ,
246
- heading_level + 2
247
- )
240
+ local generated =
241
+ module .config .public .strategy (dirman .get_norg_files (ws_name ) or {}, ws_root , heading_level + 2 )
248
242
249
243
if not generated or vim .tbl_isempty (generated ) then
250
244
neorg .utils .notify (
@@ -254,10 +248,10 @@ module.on_event = function(event)
254
248
end
255
249
-- use a tag to contain the result
256
250
local content = {
257
- string.rep (" " , heading_level ) .. " |group summary " .. ws_name ,
251
+ string.rep (" " , heading_level ) .. " |group summary " .. ws_name ,
258
252
}
259
253
for _ , gen in ipairs (generated ) do
260
- table.insert (content , gen )
254
+ table.insert (content , gen )
261
255
end
262
256
table.insert (content , string.rep (" " , heading_level ) .. " |end" )
263
257
0 commit comments