diff options
| author | Wayne-Cole <77279425+Wacky404@users.noreply.github.com> | 2026-06-07 17:45:22 -0500 |
|---|---|---|
| committer | Wayne-Cole <77279425+Wacky404@users.noreply.github.com> | 2026-06-07 17:45:22 -0500 |
| commit | 53c60a9213f4e899bc411373ea2f0c20cf716826 (patch) | |
| tree | 63001d83197db89f61890467740db940645fb2ca /lua/99/ops | |
| parent | 4d229141546290746c82ac90f5afc2786865b5f3 (diff) | |
| download | a4-53c60a9213f4e899bc411373ea2f0c20cf716826.tar.xz a4-53c60a9213f4e899bc411373ea2f0c20cf716826.zip | |
feat: huge refactor, still broken requests
Diffstat (limited to 'lua/99/ops')
| -rw-r--r-- | lua/99/ops/clean-up.lua | 74 | ||||
| -rw-r--r-- | lua/99/ops/init.lua | 10 | ||||
| -rw-r--r-- | lua/99/ops/make-prompt.lua | 44 | ||||
| -rw-r--r-- | lua/99/ops/over-range.lua | 155 |
4 files changed, 148 insertions, 135 deletions
diff --git a/lua/99/ops/clean-up.lua b/lua/99/ops/clean-up.lua index 9eea6da..ce7cc74 100644 --- a/lua/99/ops/clean-up.lua +++ b/lua/99/ops/clean-up.lua @@ -11,49 +11,49 @@ local M = {} --- @param obs_or_fn _99.Providers.PartialObserver | _99.Providers.on_complete --- @return _99.Providers.Observer M.make_observer = function(context, obs_or_fn) - --- @type _99.Providers.PartialObserver - local obs = type(obs_or_fn) == "table" and obs_or_fn - or { - on_complete = obs_or_fn, - } - return { - on_start = function() - if obs.on_start then - obs.on_start() - end - end, - on_complete = function(status, res) - pcall(obs.on_complete, status, res) - vim.schedule(function() - context:stop() - context._99:sync() - end) - end, - on_stderr = function(line) - if obs.on_stderr then - obs.on_stderr(line) - end - end, - on_stdout = function(line) - if obs.on_stdout then - obs.on_stdout(line) - end - end, - } --[[@as _99.Providers.Observer ]] + --- @type _99.Providers.PartialObserver + local obs = type(obs_or_fn) == "table" and obs_or_fn + or { + on_complete = obs_or_fn, + } + return { + on_start = function() + if obs.on_start then + obs.on_start() + end + end, + on_complete = function(status, res) + pcall(obs.on_complete, status, res) + vim.schedule(function() + context:stop() + context._99:sync() + end) + end, + on_stderr = function(line) + if obs.on_stderr then + obs.on_stderr(line) + end + end, + on_stdout = function(line) + if obs.on_stdout then + obs.on_stdout(line) + end + end, + } --[[@as _99.Providers.Observer ]] end ---@param clean_up_fn fun(): nil ---@return fun(): nil M.make_clean_up = function(clean_up_fn) - local called = false - local function clean_up() - if called then - return + local called = false + local function clean_up() + if called then + return + end + called = true + clean_up_fn() end - called = true - clean_up_fn() - end - return clean_up + return clean_up end return M diff --git a/lua/99/ops/init.lua b/lua/99/ops/init.lua index 5cb7a74..ef85bf6 100644 --- a/lua/99/ops/init.lua +++ b/lua/99/ops/init.lua @@ -3,7 +3,7 @@ --- includes search, visual, and others --- --- @docs included ---- @field additional_prompt? string +--- @field additional_prompt? string | boolean --- by providing `additional_prompt` you will not be required to provide a prompt. --- this allows you to define actions based on remaps --- @@ -32,8 +32,8 @@ --- @docs included return { - search = require("99.ops.search"), - tutorial = require("99.ops.tutorial"), - over_range = require("99.ops.over-range"), - vibe = require("99.ops.vibe"), + search = require("99.ops.search"), + tutorial = require("99.ops.tutorial"), + over_range = require("99.ops.over-range"), + vibe = require("99.ops.vibe"), } diff --git a/lua/99/ops/make-prompt.lua b/lua/99/ops/make-prompt.lua index 091eade..f60904b 100644 --- a/lua/99/ops/make-prompt.lua +++ b/lua/99/ops/make-prompt.lua @@ -6,27 +6,33 @@ local Agents = require("99.extensions.agents") --- @param opts _99.ops.Opts --- @return string, _99.Reference[] return function(context, prompt, opts) - local user_prompt = opts.additional_prompt - assert( - user_prompt and type(user_prompt) == "string" and #user_prompt > 0, - "you must add a prompt to you request" - ) + local user_prompt - local full_prompt = prompt - full_prompt = context._99.prompts.prompts.prompt(user_prompt, full_prompt) + if opts.additional_prompt then + if type(opts.additional_prompt) == "string" then + user_prompt = type(opts.additional_prompt) == "string" + and opts.additional_prompt + or nil + end + else + user_prompt = nil + end + + local full_prompt = prompt + full_prompt = context._99.prompts.prompts.prompt(user_prompt, full_prompt) - local refs = Completions.parse(user_prompt) - local additional_rules = opts.additional_rules - if additional_rules then - for _, r in ipairs(additional_rules) do - local content = Agents.get_rule_content(r) - if content then - table.insert(refs, { - content = content, - }) - end + local refs = Completions.parse(user_prompt) + local additional_rules = opts.additional_rules + if additional_rules then + for _, r in ipairs(additional_rules) do + local content = Agents.get_rule_content(r) + if content then + table.insert(refs, { + content = content, + }) + end + end end - end - return full_prompt, refs + return full_prompt, refs end diff --git a/lua/99/ops/over-range.lua b/lua/99/ops/over-range.lua index e8512b8..0562a7d 100644 --- a/lua/99/ops/over-range.lua +++ b/lua/99/ops/over-range.lua @@ -1,3 +1,6 @@ +-- TODO: YOU HAVE TO FIX THIS FILE BROOOOO.... +-- actually important file!!!! + local RequestStatus = require("99.ops.request_status") local Mark = require("99.ops.marks") local geo = require("99.geo") @@ -13,90 +16,94 @@ local Point = geo.Point --- @param context _99.Prompt --- @param opts? _99.ops.Opts local function over_range(context, opts) - opts = opts or {} - local logger = context.logger:set_area("visual") + opts = opts or {} + local logger = context.logger:set_area("visual") - local data = context:visual_data() - local range = data.range - 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 data = context:visual_data() + local range = data.range + 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(function() - top_status:stop() - bottom_status:stop() - 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(function() + top_status:stop() + bottom_status:stop() + end) - local system_cmd = context._99.prompts.prompts.visual_selection(range) - local prompt, refs = make_prompt(context, system_cmd, opts) + local system_cmd = context._99.prompts.prompts.visual_selection(range) + local prompt, refs = make_prompt(context, system_cmd, opts) - context:add_prompt_content(prompt) - context:add_references(refs) - context:add_clean_up(clean_up) + context:add_prompt_content(prompt) + context:add_references(refs) + context:add_clean_up(clean_up) - top_status:start() - bottom_status:start() - context:start_request(make_observer(context, { - on_complete = function(status, response) - 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 + top_status:start() + bottom_status:start() + context:start_request(make_observer(context, { + on_complete = function(status, response) + 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 - if vim.trim(response) == "" then - print("response was empty, visual replacement aborted") - logger:debug("response was empty, visual replacement aborted") - return - end + if vim.trim(response) == "" then + print("response was empty, visual replacement aborted") + logger:debug( + "response was empty, visual replacement aborted" + ) + 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) - context._99:sync() - end - end, - on_stdout = function(line) - if display_ai_status then - top_status:push(line) - end - end, - })) + new_range:replace_text(lines) + context._99:sync() + end + end, + on_stdout = function(line) + if display_ai_status then + top_status:push(line) + end + end, + })) end return over_range |
