summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authortheprimeagain <the.primeagen@gmail.com>2026-03-03 09:12:20 -0700
committertheprimeagain <the.primeagen@gmail.com>2026-03-03 09:12:20 -0700
commitec9872f7df7f4eb8b319719c1c253eb3ea8877ed (patch)
treeef94cf1e471dd664077d01117c55e550557fef01 /lua
parenta158ddd960d3da6e66cd4fb63bc911f28917df7a (diff)
downloada4-ec9872f7df7f4eb8b319719c1c253eb3ea8877ed.tar.xz
a4-ec9872f7df7f4eb8b319719c1c253eb3ea8877ed.zip
open order and scrolloffset
Diffstat (limited to 'lua')
-rw-r--r--lua/99/state.lua12
-rw-r--r--lua/99/state/tracking.lua11
-rw-r--r--lua/99/test/open_spec.lua4
-rw-r--r--lua/99/test/state_spec.lua65
-rw-r--r--lua/99/test/tracking_spec.lua19
-rw-r--r--lua/99/window/init.lua17
6 files changed, 120 insertions, 8 deletions
diff --git a/lua/99/state.lua b/lua/99/state.lua
index 6e38c5f..a67acee 100644
--- a/lua/99/state.lua
+++ b/lua/99/state.lua
@@ -2,6 +2,7 @@ local utils = require("99.utils")
local Agents = require("99.extensions.agents")
local Extensions = require("99.extensions")
local Tracking = require("99.state.tracking")
+local Window = require("99.window")
local _99_STATE_FILE = "state"
local function default_completion()
@@ -98,6 +99,17 @@ function State:tmp_dir()
return get_tmp_dir(self)
end
+--- @return boolean
+function State:active()
+ _ = self
+ if Window.has_active_window() then
+ return true
+ end
+
+ local qf = vim.fn.getqflist({ winid = 0 })
+ return qf.winid ~= 0
+end
+
--- TODO: This is something to understand. I bet that this is going to need
--- a lot of performance tuning. I am just reading every file, and this could
--- take a decent amount of time if there are lots of rules.
diff --git a/lua/99/state/tracking.lua b/lua/99/state/tracking.lua
index 220681d..ae280cb 100644
--- a/lua/99/state/tracking.lua
+++ b/lua/99/state/tracking.lua
@@ -116,13 +116,14 @@ end
--- @return _99.Prompt[]
function Tracking:successful()
- local out = {}
- for _, r in ipairs(self.history) do
- if r.state == "success" then
- table.insert(out, r)
+ local requests = {}
+ for i = #self.history, 1, -1 do
+ local request = self.history[i]
+ if request.state == "success" then
+ table.insert(requests, request)
end
end
- return out
+ return requests
end
--- @return _99.State.Tracking.Serialized
diff --git a/lua/99/test/open_spec.lua b/lua/99/test/open_spec.lua
index a463212..b6cff76 100644
--- a/lua/99/test/open_spec.lua
+++ b/lua/99/test/open_spec.lua
@@ -93,7 +93,7 @@ describe("open", function()
select_content(1)
_99.open()
- eq(QFixHelpers.create_qfix_entries(s), qfix_items())
+ some_window_has(t)
select_content(2)
_99.open()
@@ -101,7 +101,7 @@ describe("open", function()
select_content(3)
_99.open()
- some_window_has(t)
+ eq(QFixHelpers.create_qfix_entries(s), qfix_items())
end)
it("views logs for selected request xid", function()
diff --git a/lua/99/test/state_spec.lua b/lua/99/test/state_spec.lua
new file mode 100644
index 0000000..d0e470c
--- /dev/null
+++ b/lua/99/test/state_spec.lua
@@ -0,0 +1,65 @@
+-- luacheck: globals describe it assert before_each after_each
+local _99 = require("99")
+local Window = require("99.window")
+local test_utils = require("99.test.test_utils")
+local eq = assert.are.same
+
+describe("state", function()
+ local provider
+ local previous_list_uis
+
+ before_each(function()
+ provider = test_utils.TestProvider.new()
+ _99.setup(test_utils.get_test_setup_options({
+ in_flight_options = { enable = false },
+ }, provider))
+
+ previous_list_uis = vim.api.nvim_list_uis
+ vim.api.nvim_list_uis = function()
+ return {
+ { width = 120, height = 40 },
+ }
+ end
+ end)
+
+ after_each(function()
+ Window.clear_active_popups()
+ vim.cmd("silent! cclose")
+ vim.api.nvim_list_uis = previous_list_uis
+ end)
+
+ it("is active when capture input window is open", function()
+ local state = _99.__get_state()
+ eq(false, state:active())
+
+ Window.capture_input("Prompt", {
+ cb = function() end,
+ keymap = {
+ [":w"] = "submit",
+ },
+ })
+
+ eq(true, state:active())
+ end)
+
+ it("is active when quickfix window is open", function()
+ local state = _99.__get_state()
+ local buffer = test_utils.create_file({ "hello" }, "lua", 1, 0)
+ eq(false, state:active())
+
+ vim.fn.setqflist({}, "r", {
+ title = "99 Results",
+ items = {
+ {
+ bufnr = buffer,
+ lnum = 1,
+ col = 1,
+ text = "note",
+ },
+ },
+ })
+ vim.cmd("copen")
+
+ eq(true, state:active())
+ end)
+end)
diff --git a/lua/99/test/tracking_spec.lua b/lua/99/test/tracking_spec.lua
index 8d64660..670bccc 100644
--- a/lua/99/test/tracking_spec.lua
+++ b/lua/99/test/tracking_spec.lua
@@ -57,4 +57,23 @@ describe("tracking", function()
Tracking.__config.serialize_count = previous_counts
end)
+
+ it("successful returns things in reverse order", function()
+ local provider = test_utils.TestProvider.new()
+ _99.setup(test_utils.get_test_setup_options({
+ in_flight_options = { enable = false },
+ }, provider))
+ test_utils.create_file({ "local value = 1" }, "lua", 1, 0)
+
+ run(provider, "search", "success", "first success")
+ run(provider, "search", "failed", "failed request")
+ run(provider, "vibe", "success", "second success")
+ run(provider, "tutorial", "success", "third success")
+
+ local successful = _99.__get_state().tracking:successful()
+ eq(3, #successful)
+ eq("third success", successful[1].user_prompt)
+ eq("second success", successful[2].user_prompt)
+ eq("first success", successful[3].user_prompt)
+ end)
end)
diff --git a/lua/99/window/init.lua b/lua/99/window/init.lua
index 01de82b..01dc414 100644
--- a/lua/99/window/init.lua
+++ b/lua/99/window/init.lua
@@ -451,7 +451,8 @@ local function create_window_legend(win, keymap)
vim.bo[keymap_win.buf_id].modifiable = false
vim.bo[keymap_win.buf_id].readonly = true
- vim.wo[win.win_id].scrolloff = keyoffset
+ -- one for the border, one for the extra space, and then keymap count
+ vim.wo[win.win_id].scrolloff = keyoffset + 2
end
--- @param name string
@@ -628,6 +629,20 @@ function M.has_active_status_window()
return has
end
+--- @return boolean
+function M.has_active_window()
+ for _, w in ipairs(M.active_windows) do
+ if
+ w.type == "capture_input"
+ and win_valid(w.win_id)
+ and buf_valid(w.buf_id)
+ then
+ return true
+ end
+ end
+ return false
+end
+
function M.refresh_active_windows()
--- @type _99.window.Window[]
local actives = {}