Skip to content

Commit 59fab5e

Browse files
committed
summary: stylua
1 parent 90f8f52 commit 59fab5e

File tree

1 file changed

+45
-51
lines changed

1 file changed

+45
-51
lines changed

lua/neorg/modules/core/summary/module.lua

+45-51
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ module.load = function()
123123
for _, datapoint in ipairs(data) do
124124
table.insert(
125125
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.
128129
table.concat({
129130
prefix,
130131
"_ {:$",
@@ -165,71 +166,67 @@ module.events.subscribed = {
165166
},
166167
}
167168

168-
169169
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+
_ = [[
173173
(ranged_tag
174174
name: (tag_name) @_tag_name
175175
(#eq? @_tag_name "group")
176176
)
177177
]],
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
191192
end
192193
end
193-
end
194-
return nil
195-
end
194+
return nil
195+
end,
196196
}
197197

198198
module.on_event = function(event)
199199
if event.type == "core.neorgcmd.events.summary.summarize" then
200200
local ts = module.required["core.integrations.treesitter"]
201201
local buffer = event.buffer
202202

203-
204203
local start_line = event.cursor_position[1]
205204
local end_line = start_line
206205
local existing = module.private.find_existing_summary(buffer, ts.get_document_root(buffer))
207206
local heading_level = 0
208207
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
217215
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
230228
end
231229

232-
233230
local dirman = neorg.modules.get_module("core.dirman")
234231

235232
if not dirman then
@@ -240,11 +237,8 @@ module.on_event = function(event)
240237
local current_workspace = dirman.get_current_workspace()
241238
local ws_name = current_workspace[1]
242239
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)
248242

249243
if not generated or vim.tbl_isempty(generated) then
250244
neorg.utils.notify(
@@ -254,10 +248,10 @@ module.on_event = function(event)
254248
end
255249
-- use a tag to contain the result
256250
local content = {
257-
string.rep(" ", heading_level) .. "|group summary " .. ws_name,
251+
string.rep(" ", heading_level) .. "|group summary " .. ws_name,
258252
}
259253
for _, gen in ipairs(generated) do
260-
table.insert(content, gen)
254+
table.insert(content, gen)
261255
end
262256
table.insert(content, string.rep(" ", heading_level) .. "|end")
263257

0 commit comments

Comments
 (0)