diff options
| author | theprimeagain <the.primeagen@gmail.com> | 2026-02-23 19:50:47 -0700 |
|---|---|---|
| committer | theprimeagain <the.primeagen@gmail.com> | 2026-02-23 19:50:47 -0700 |
| commit | 6d80dccf18b0bb66415d355857cb5c11d777d297 (patch) | |
| tree | d5ab4ce9c663d7209099301afdcb293093ca1652 /lua/99/ops | |
| parent | 6a64e0b2f4c7f1e3911db1f8318e5d7c68cb8dff (diff) | |
| download | a4-6d80dccf18b0bb66415d355857cb5c11d777d297.tar.xz a4-6d80dccf18b0bb66415d355857cb5c11d777d297.zip | |
beginning the vibe work
Diffstat (limited to 'lua/99/ops')
| -rw-r--r-- | lua/99/ops/init.lua | 1 | ||||
| -rw-r--r-- | lua/99/ops/qfix-helpers.lua | 43 | ||||
| -rw-r--r-- | lua/99/ops/search.lua | 46 | ||||
| -rw-r--r-- | lua/99/ops/vibe.lua | 52 |
4 files changed, 101 insertions, 41 deletions
diff --git a/lua/99/ops/init.lua b/lua/99/ops/init.lua index e4596c2..d45b1a5 100644 --- a/lua/99/ops/init.lua +++ b/lua/99/ops/init.lua @@ -35,4 +35,5 @@ return { 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/qfix-helpers.lua b/lua/99/ops/qfix-helpers.lua new file mode 100644 index 0000000..8d7ee63 --- /dev/null +++ b/lua/99/ops/qfix-helpers.lua @@ -0,0 +1,43 @@ +local M = {} + +--- @return _99.Search.Result | nil +function M.parse_line(line) + local parts = vim.split(line, ":", { plain = true }) + if #parts ~= 3 then + return nil + end + + local filepath = parts[1] + local lnum = parts[2] + local comma_parts = vim.split(parts[3], ",", { plain = true }) + local col = comma_parts[1] + local notes = nil + + if #comma_parts >= 2 then + notes = table.concat(comma_parts, ",", 2) + end + + return { + filename = filepath, + lnum = tonumber(lnum) or 1, + col = tonumber(col) or 1, + text = notes or "", + } +end + +--- @param response string +--- @return _99.Search.Result[] +function M.create_qfix_entries(response) + local lines = vim.split(response, "\n") + local qf_list = {} --[[ @as _99.Search.Result[] ]] + + for _, line in ipairs(lines) do + local res = M.parse_line(line) + if res then + table.insert(qf_list, res) + end + end + return qf_list +end + +return M diff --git a/lua/99/ops/search.lua b/lua/99/ops/search.lua index dda70d1..0619f47 100644 --- a/lua/99/ops/search.lua +++ b/lua/99/ops/search.lua @@ -1,59 +1,23 @@ local make_prompt = require("99.ops.make-prompt") local CleanUp = require("99.ops.clean-up") +local QFixHelpers = require("99.ops.qfix-helpers") local make_clean_up = CleanUp.make_clean_up local make_observer = CleanUp.make_observer ---- @class _99.Search.Result ---- @field filename string ---- @field lnum number ---- @field col number ---- @field text string - ---- @return _99.Search.Result | nil -local function parse_line(line) - local parts = vim.split(line, ":", { plain = true }) - if #parts ~= 3 then - return nil - end - - local filepath = parts[1] - local lnum = parts[2] - local comma_parts = vim.split(parts[3], ",", { plain = true }) - local col = comma_parts[1] - local notes = nil - - if #comma_parts >= 2 then - notes = table.concat(comma_parts, ",", 2) - end - - return { - filename = filepath, - lnum = tonumber(lnum) or 1, - col = tonumber(col) or 1, - text = notes or "", - } -end - --- @param context _99.Prompt --- @param response string local function create_search_locations(context, response) - local lines = vim.split(response, "\n") - local qf_list = {} - - for _, line in ipairs(lines) do - local res = parse_line(line) - if res then - table.insert(qf_list, res) - end - end + local qf_list = QFixHelpers.create_qfix_entries(response) + context.logger:set_area("search"):debug("qf_list created", "qf_list", qf_list) context.data = { type = "search", qfix_items = qf_list, + response = response, } if #qf_list > 0 then - require("99").qfix_search_results(context.xid) + require("99").qfix(context.xid) else vim.notify("No search results found", vim.log.levels.INFO) end diff --git a/lua/99/ops/vibe.lua b/lua/99/ops/vibe.lua new file mode 100644 index 0000000..291fc45 --- /dev/null +++ b/lua/99/ops/vibe.lua @@ -0,0 +1,52 @@ +local make_prompt = require("99.ops.make-prompt") +local CleanUp = require("99.ops.clean-up") + +local make_clean_up = CleanUp.make_clean_up +local make_observer = CleanUp.make_observer + +--- @class _99.Search.Result +--- @field filename string +--- @field lnum number +--- @field col number +--- @field text string + +--- @param context _99.Prompt +---@param opts _99.ops.SearchOpts +local function search(context, opts) + opts = opts or {} + + local logger = context.logger:set_area("search") + logger:debug("search", "with opts", opts.additional_prompt) + + local clean_up = make_clean_up(function() + context:stop() + end) + + local prompt, refs = + make_prompt(context, context._99.prompts.prompts.semantic_search(), opts) + + context:add_prompt_content(prompt) + context:add_references(refs) + context:add_clean_up(clean_up) + + --- TODO: part of the context request clean up there needs to be a refactoring of + --- make observer... it really should just be within the context observer creation. + --- same with cleanup.. that should just be clean_ups from context, instead of a + --- once cleanup function wrapper. + --- + --- i think an interface, CleanUpI could be something that is worth it :) + context:start_request(make_observer(clean_up, function(status, response) + if status == "cancelled" then + logger:debug("request cancelled for search") + elseif status == "failed" then + logger:error( + "request failed for search", + "error response", + response or "no response provided" + ) + elseif status == "success" then + create_search_locations(context, response) + end + end)) +end +return search |
