summaryrefslogtreecommitdiff
path: root/lua/99/prompt-settings.lua
diff options
context:
space:
mode:
authorIlyaZar <zarubin@wiso.uni-koeln.de>2026-04-28 19:57:15 +0200
committerIlyaZar <zarubin@wiso.uni-koeln.de>2026-04-28 19:57:15 +0200
commitf8874363db3600c7da3cf445113055f8408e9617 (patch)
treec259b9b4a4b6a04b85ae05d423d5cb0a797ef851 /lua/99/prompt-settings.lua
parent3bc191fbfb1f67a395953a71ef1bef41c5fec979 (diff)
downloada4-f8874363db3600c7da3cf445113055f8408e9617.tar.xz
a4-f8874363db3600c7da3cf445113055f8408e9617.zip
fix: clamp visual context bounds
Diffstat (limited to 'lua/99/prompt-settings.lua')
-rw-r--r--lua/99/prompt-settings.lua8
1 files changed, 4 insertions, 4 deletions
diff --git a/lua/99/prompt-settings.lua b/lua/99/prompt-settings.lua
index 258de34..a688a0e 100644
--- a/lua/99/prompt-settings.lua
+++ b/lua/99/prompt-settings.lua
@@ -4,10 +4,10 @@
local function get_surrounding_context(range, n)
local start_row, _ = range.start:to_vim()
local end_row, _ = range.end_:to_vim()
- -- nvim_buf_get_lines safely clamps out-of-bounds indexes
- local from = start_row - n
- local to = end_row + 1 + n -- +1 because end_row is end-inclusive
- local lines = vim.api.nvim_buf_get_lines(range.buffer, from, to, false) -- nvim_buf_get_lines is end-exclusive
+ local line_count = vim.api.nvim_buf_line_count(range.buffer)
+ local from = math.max(start_row - n, 0)
+ local to = math.min(end_row + 1 + n, line_count)
+ local lines = vim.api.nvim_buf_get_lines(range.buffer, from, to, false)
return table.concat(lines, "\n")
end