diff options
| author | Dung Duc Huynh (Kaka) <870029+jellydn@users.noreply.github.com> | 2026-02-09 08:00:13 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-09 08:00:13 +0800 |
| commit | 5efe8b9af39f21c27a35552cda4ffbfd67ec85e7 (patch) | |
| tree | 8f249a5e56904a686808dc497d6b16414cd3d786 /lua/99/init.lua | |
| parent | 7f35ae57c862fcf08b470165d8ff1759a10eb9b7 (diff) | |
| parent | d9dfb2336364fa0985137b56d8b13dc806fea7a7 (diff) | |
| download | a4-5efe8b9af39f21c27a35552cda4ffbfd67ec85e7.tar.xz a4-5efe8b9af39f21c27a35552cda4ffbfd67ec85e7.zip | |
Merge branch 'master' into feature/blink-cmp
Diffstat (limited to 'lua/99/init.lua')
| -rw-r--r-- | lua/99/init.lua | 133 |
1 files changed, 64 insertions, 69 deletions
diff --git a/lua/99/init.lua b/lua/99/init.lua index e5ac73a..54a68e9 100644 --- a/lua/99/init.lua +++ b/lua/99/init.lua @@ -254,26 +254,37 @@ local function set_selection_marks() ) end ---- @param cb fun(ok: boolean, o: _99.ops.Opts?): nil +--- @param cb fun(context: _99.RequestContext, o: _99.ops.Opts?): nil --- @param context _99.RequestContext --- @param opts _99.ops.Opts ---- @return fun(ok: boolean, response: string): nil -local function wrap_window_capture(cb, context, opts) - --- @param ok boolean - --- @param response string - return function(ok, response) - context.logger:debug("capture_prompt", "success", ok, "response", response) - if not ok then - return cb(false) - end - local rules_and_names = Agents.by_name(_99_state.rules, response) - opts.additional_rules = opts.additional_rules or {} - for _, r in ipairs(rules_and_names.rules) do - table.insert(opts.additional_rules, r) - end - opts.additional_prompt = response - cb(true, opts) - end +local function capture_prompt(cb, context, opts) + Window.capture_input({ + --- @param ok boolean + --- @param response string + cb = function(ok, response) + context.logger:debug( + "capture_prompt", + "success", + ok, + "response", + response + ) + if not ok then + return + end + local rules_and_names = Agents.by_name(_99_state.rules, response) + opts.additional_rules = opts.additional_rules or {} + for _, r in ipairs(rules_and_names.rules) do + table.insert(opts.additional_rules, r) + end + opts.additional_prompt = response + cb(context, opts) + end, + on_load = function() + Extensions.setup_buffer(_99_state) + end, + rules = _99_state.rules, + }) end --- @param operation_name string @@ -311,66 +322,50 @@ function _99:rule_from_path(path) return Agents.get_rule_by_path(_99_state.rules, path) end ---- @param opts? _99.ops.Opts -function _99.fill_in_function_prompt(opts) - opts = process_opts(opts) - local context = get_context("fill-in-function-with-prompt") +--- @param opts? _99.ops.SearchOpts +function _99.search(opts) + local o = process_opts(opts) --[[ @as _99.ops.SearchOpts ]] + local context = get_context("search") + if o.additional_prompt then + ops.search(context, o) + return + else + capture_prompt(ops.search, context, o) + end +end - context.logger:debug("start") - Window.capture_input({ - cb = wrap_window_capture(function(ok, o) - if not ok then - return - end - assert(o ~= nil, "if ok, then opts must exist") - ops.fill_in_function(context, o) - end, context, opts), - on_load = function() - Extensions.setup_buffer(_99_state) - end, - rules = _99_state.rules, - }) +--- @param opts _99.ops.Opts +function _99.visual_prompt(opts) + print("use visual, visual_prompt has been deprecated") + _99.visual(opts) end ---- @param opts? _99.ops.Opts -function _99.fill_in_function(opts) - opts = process_opts(opts) - ops.fill_in_function(get_context("fill_in_function"), opts) +function _99.fill_in_function() + error( + "function has been removed. Just use visual. I really hate fill in function, sorry :)" + ) end ---- @param opts _99.ops.Opts -function _99.visual_prompt(opts) - opts = process_opts(opts) - local context = get_context("over-range-with-prompt") - context.logger:debug("start") - Window.capture_input({ - cb = wrap_window_capture(function(ok, o) - if not ok then - return - end - assert(o ~= nil, "if ok, then opts must exist") - _99.visual(context, o) - end, context, opts), - on_load = function() - Extensions.setup_buffer(_99_state) - end, - rules = _99_state.rules, - }) +function _99.fill_in_function_prompt() + error( + "function has been removed. Just use visual. I really hate fill in function, sorry :)" + ) end ---- @param context _99.RequestContext? --- @param opts _99.ops.Opts? -function _99.visual(context, opts) +function _99.visual(opts) opts = process_opts(opts) - --- TODO: Talk to teej about this. - --- Visual selection marks are only set in place post visual selection. - --- that means for this function to work i must escape out of visual mode - --- which i dislike very much. because maybe you dont want this - set_selection_marks() - - context = context or get_context("over-range") - local range = Range.from_visual_selection() - ops.over_range(context, range, opts) + local context = get_context("visual") + local function perform_range() + set_selection_marks() + local range = Range.from_visual_selection() + ops.over_range(context, range, opts) + end + if opts.additional_prompt then + perform_range() + else + capture_prompt(perform_range, context, opts) + end end --- View all the logs that are currently cached. Cached log count is determined |
