Skip to content

Commit c29714e

Browse files
committed
feat: annotate omitted lines in content and context output
1 parent 9f8d18b commit c29714e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lua/simplegpt/tpl.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,13 @@ function M.RegQAUI:get_special()
244244
-- Get all lines
245245
local lines = vim.api.nvim_buf_get_lines(buf, math.max(cursor_pos[1] - content_max_len - 1, 0),
246246
math.min(cursor_pos[1] + content_max_len, line_count), false)
247+
-- prepend/append annotation if lines are omitted (like <.... X lines omitted .....>)
248+
if cursor_pos[1] - content_max_len - 1 > 0 then
249+
table.insert(lines, 1, string.format("<.... %d lines omitted .....>", cursor_pos[1] - content_max_len - 1))
250+
end
251+
if cursor_pos[1] + content_max_len < line_count then
252+
table.insert(lines, string.format("<.... %d lines omitted .....>", line_count - (cursor_pos[1] + content_max_len)))
253+
end
247254
res["content"] = table.concat(lines, "\n")
248255
res["full_content"] = table.concat(vim.api.nvim_buf_get_lines(buf, 0, -1, false), "\n")
249256

@@ -277,6 +284,13 @@ function M.RegQAUI:get_special()
277284
-- Get the context lines
278285
local context_lines = vim.api.nvim_buf_get_lines(buf, start_line, end_line, false)
279286
-- Now 'context_lines' is a table containing all context lines
287+
-- prepend/append annotation if lines are omitted (like <.... X lines omitted .....>)
288+
if start_line > 0 then
289+
table.insert(context_lines, 1, string.format("<.... %d lines omitted .....>", start_line))
290+
end
291+
if end_line < line_count then
292+
table.insert(context_lines, string.format("<.... %d lines omitted .....>", line_count - end_line))
293+
end
280294
res["context"] = table.concat(context_lines, "\n")
281295

282296
-- 5) Get content in all buffers that have corresponding files on disk; use get_buf_cont

0 commit comments

Comments
 (0)