diff options
| author | ThePrimeAgain <theprimeagain@theprimeagain.com> | 2026-01-14 18:32:30 -0700 |
|---|---|---|
| committer | ThePrimeAgain <theprimeagain@theprimeagain.com> | 2026-01-14 18:32:30 -0700 |
| commit | 6c88a9537ae829cd8a4b92312e115c311e6beb42 (patch) | |
| tree | d2b1796d453cbbd7374ed740fa50a1be411362b1 /lua/99/ops/over-range.lua | |
| parent | 701b4c34a1e3de34327d21cc6f51c79b49d26b51 (diff) | |
| download | a4-6c88a9537ae829cd8a4b92312e115c311e6beb42.tar.xz a4-6c88a9537ae829cd8a4b92312e115c311e6beb42.zip | |
fuzzy_find: for agents stuff
Diffstat (limited to 'lua/99/ops/over-range.lua')
| -rw-r--r-- | lua/99/ops/over-range.lua | 146 |
1 files changed, 72 insertions, 74 deletions
diff --git a/lua/99/ops/over-range.lua b/lua/99/ops/over-range.lua index 3dfdcbe..4cbe8f6 100644 --- a/lua/99/ops/over-range.lua +++ b/lua/99/ops/over-range.lua @@ -10,88 +10,86 @@ local make_clean_up = require("99.ops.clean-up") --- @param range _99.Range --- @param prompt string? local function over_range(context, range, prompt) - local logger = context.logger:set_area("visual") + local logger = context.logger:set_area("visual") - local request = Request.new(context) - local top_mark = Mark.mark_above_range(range) - local bottom_mark = Mark.mark_point(range.buffer, range.end_) - context.marks.top_mark = top_mark - context.marks.bottom_mark = bottom_mark + local request = Request.new(context) + local top_mark = Mark.mark_above_range(range) + local bottom_mark = Mark.mark_point(range.buffer, range.end_) + context.marks.top_mark = top_mark + context.marks.bottom_mark = bottom_mark - logger:debug( - "visual request start", - "start", - Point.from_mark(top_mark), - "end", - Point.from_mark(bottom_mark) - ) + logger:debug( + "visual request start", + "start", + Point.from_mark(top_mark), + "end", + Point.from_mark(bottom_mark) + ) - local display_ai_status = context._99.ai_stdout_rows > 1 - local top_status = RequestStatus.new( - 250, - context._99.ai_stdout_rows or 1, - "Implementing", - top_mark - ) - local bottom_status = RequestStatus.new(250, 1, "Implementing", bottom_mark) - local clean_up = make_clean_up(context, function() - top_status:stop() - bottom_status:stop() - context:clear_marks() - request:cancel() - end) + local display_ai_status = context._99.ai_stdout_rows > 1 + local top_status = RequestStatus.new( + 250, + context._99.ai_stdout_rows or 1, + "Implementing", + top_mark + ) + local bottom_status = RequestStatus.new(250, 1, "Implementing", bottom_mark) + local clean_up = make_clean_up(context, function() + top_status:stop() + bottom_status:stop() + context:clear_marks() + request:cancel() + end) - local full_prompt = context._99.prompts.prompts.visual_selection(range) - if prompt then - full_prompt = context._99.prompts.prompts.prompt(prompt, full_prompt) - end + local full_prompt = context._99.prompts.prompts.visual_selection(range) + if prompt then + full_prompt = context._99.prompts.prompts.prompt(prompt, full_prompt) + end - request:add_prompt_content(full_prompt) - top_status:start() - bottom_status:start() - request:start({ - on_complete = function(status, response) - vim.schedule(clean_up) - if status == "cancelled" then - logger:debug( - "request cancelled for visual selection, removing marks" - ) - elseif status == "failed" then - logger:error( - "request failed for visual_selection", - "error response", - response or "no response provided" - ) - elseif status == "success" then - local valid = top_mark:is_valid() and bottom_mark:is_valid() - if not valid then - logger:fatal( - -- luacheck: ignore 631 - "the original visual_selection has been destroyed. You cannot delete the original visual selection during a request" - ) - return - end + request:add_prompt_content(full_prompt) + top_status:start() + bottom_status:start() + request:start({ + on_complete = function(status, response) + vim.schedule(clean_up) + if status == "cancelled" then + logger:debug("request cancelled for visual selection, removing marks") + elseif status == "failed" then + logger:error( + "request failed for visual_selection", + "error response", + response or "no response provided" + ) + elseif status == "success" then + local valid = top_mark:is_valid() and bottom_mark:is_valid() + if not valid then + logger:fatal( + -- luacheck: ignore 631 + "the original visual_selection has been destroyed. You cannot delete the original visual selection during a request" + ) + return + end - local new_range = Range.from_marks(top_mark, bottom_mark) - local lines = vim.split(response, "\n") + local new_range = Range.from_marks(top_mark, bottom_mark) + local lines = vim.split(response, "\n") - --- HACK: i am adding a new line here because above range will add a mark to the line above. - --- that way this appears to be added to "the same line" as the visual selection was - --- originally take from - table.insert(lines, 1, "") + --- HACK: i am adding a new line here because above range will add a mark to the line above. + --- that way this appears to be added to "the same line" as the visual selection was + --- originally take from + table.insert(lines, 1, "") - new_range:replace_text(lines) - end - end, - on_stdout = function(line) - if display_ai_status then - top_status:push(line) - end - end, - on_stderr = function(line) - logger:debug("visual_selection#on_stderr received", "line", line) - end, - }) + new_range:replace_text(lines) + end + end, + on_stdout = function(line) + if display_ai_status then + top_status:push(line) + end + end, + on_stderr = function(line) + logger:debug("visual_selection#on_stderr received", "line", line) + end, + }) end return over_range |
