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 | |
| parent | 701b4c34a1e3de34327d21cc6f51c79b49d26b51 (diff) | |
| download | a4-6c88a9537ae829cd8a4b92312e115c311e6beb42.tar.xz a4-6c88a9537ae829cd8a4b92312e115c311e6beb42.zip | |
fuzzy_find: for agents stuff
Diffstat (limited to 'lua/99/ops')
| -rw-r--r-- | lua/99/ops/clean-up.lua | 24 | ||||
| -rw-r--r-- | lua/99/ops/fill-in-function.lua | 165 | ||||
| -rw-r--r-- | lua/99/ops/implement-fn.lua | 128 | ||||
| -rw-r--r-- | lua/99/ops/init.lua | 6 | ||||
| -rw-r--r-- | lua/99/ops/marks.lua | 148 | ||||
| -rw-r--r-- | lua/99/ops/over-range.lua | 146 | ||||
| -rw-r--r-- | lua/99/ops/request_status.lua | 72 |
7 files changed, 341 insertions, 348 deletions
diff --git a/lua/99/ops/clean-up.lua b/lua/99/ops/clean-up.lua index a9545b1..d56b6de 100644 --- a/lua/99/ops/clean-up.lua +++ b/lua/99/ops/clean-up.lua @@ -2,18 +2,18 @@ ---@param clean_up_fn fun(): nil ---@return fun(): nil return function(context, clean_up_fn) - local called = false - local request_id = -1 - local function clean_up() - if called then - return - end - - called = true - clean_up_fn() - context._99:remove_active_request(request_id) + local called = false + local request_id = -1 + local function clean_up() + if called then + return end - request_id = context._99:add_active_request(clean_up) - return clean_up + called = true + clean_up_fn() + context._99:remove_active_request(request_id) + end + request_id = context._99:add_active_request(clean_up) + + return clean_up end diff --git a/lua/99/ops/fill-in-function.lua b/lua/99/ops/fill-in-function.lua index b29c3da..7d25ef5 100644 --- a/lua/99/ops/fill-in-function.lua +++ b/lua/99/ops/fill-in-function.lua @@ -10,108 +10,105 @@ local make_clean_up = require("99.ops.clean-up") --- @param context _99.RequestContext --- @param res string local function update_file_with_changes(context, res) - local buffer = context.buffer - local mark = context.marks.function_location - local logger = - context.logger:set_area("fill_in_function#update_file_with_changes") + local buffer = context.buffer + local mark = context.marks.function_location + local logger = + context.logger:set_area("fill_in_function#update_file_with_changes") - logger:assert( - mark and buffer, - "mark and buffer have to be set on the location object" - ) - logger:assert(mark:is_valid(), "mark is no longer valid") + logger:assert( + mark and buffer, + "mark and buffer have to be set on the location object" + ) + logger:assert(mark:is_valid(), "mark is no longer valid") - local func_start = Point.from_mark(mark) - local ts = editor.treesitter - local func = ts.containing_function(context, func_start) + local func_start = Point.from_mark(mark) + local ts = editor.treesitter + local func = ts.containing_function(context, func_start) - logger:assert( - func, - "update_file_with_changes: unable to find function at mark location" - ) + logger:assert( + func, + "update_file_with_changes: unable to find function at mark location" + ) - local lines = vim.split(res, "\n") + local lines = vim.split(res, "\n") - -- lua docs ignore next error, func being tested already in assert - -- TODO: fix this? - func:replace_text(lines) + -- lua docs ignore next error, func being tested already in assert + -- TODO: fix this? + func:replace_text(lines) end --- @param context _99.RequestContext --- @param additional_prompt string? local function fill_in_function(context, additional_prompt) - local logger = context.logger:set_area("fill_in_function") - local ts = editor.treesitter - local buffer = vim.api.nvim_get_current_buf() - local cursor = Point:from_cursor() - local func = ts.containing_function(context, cursor) + local logger = context.logger:set_area("fill_in_function") + local ts = editor.treesitter + local buffer = vim.api.nvim_get_current_buf() + local cursor = Point:from_cursor() + local func = ts.containing_function(context, cursor) - if not func then - logger:fatal("fill_in_function: unable to find any containing function") - return - end + if not func then + logger:fatal("fill_in_function: unable to find any containing function") + return + end - context.range = func.function_range + context.range = func.function_range - local virt_line_count = context._99.ai_stdout_rows - if virt_line_count >= 0 then - context.marks.function_location = Mark.mark_func_body(buffer, func) - end + local virt_line_count = context._99.ai_stdout_rows + if virt_line_count >= 0 then + context.marks.function_location = Mark.mark_func_body(buffer, func) + end - local request = Request.new(context) - local full_prompt = context._99.prompts.prompts.fill_in_function() - if additional_prompt then - full_prompt = - context._99.prompts.prompts.prompt(additional_prompt, full_prompt) - end - request:add_prompt_content(full_prompt) + local request = Request.new(context) + local full_prompt = context._99.prompts.prompts.fill_in_function() + if additional_prompt then + full_prompt = + context._99.prompts.prompts.prompt(additional_prompt, full_prompt) + end + request:add_prompt_content(full_prompt) - local request_status = RequestStatus.new( - 250, - context._99.ai_stdout_rows, - "Loading", - context.marks.function_location - ) - request_status:start() + local request_status = RequestStatus.new( + 250, + context._99.ai_stdout_rows, + "Loading", + context.marks.function_location + ) + request_status:start() - local clean_up = make_clean_up(context, function() - context:clear_marks() - request:cancel() - request_status:stop() - end) + local clean_up = make_clean_up(context, function() + context:clear_marks() + request:cancel() + request_status:stop() + end) - request:start({ - on_stdout = function(line) - request_status:push(line) - end, - on_complete = function(status, response) - logger:info("on_complete", "status", status, "response", response) - vim.schedule(clean_up) + request:start({ + on_stdout = function(line) + request_status:push(line) + end, + on_complete = function(status, response) + logger:info("on_complete", "status", status, "response", response) + vim.schedule(clean_up) - if status == "failed" then - if context._99.display_errors then - Window.display_error( - "Error encountered while processing fill_in_function\n" - .. ( - response - or "No Error text provided. Check logs" - ) - ) - end - logger:error( - "unable to fill in function, enable and check logger for more details" - ) - elseif status == "cancelled" then - logger:debug("fill_in_function was cancelled") - -- TODO: small status window here - elseif status == "success" then - update_file_with_changes(context, response) - end - end, - on_stderr = function(line) - logger:debug("fill_in_function#on_stderr", "line", line) - end, - }) + if status == "failed" then + if context._99.display_errors then + Window.display_error( + "Error encountered while processing fill_in_function\n" + .. (response or "No Error text provided. Check logs") + ) + end + logger:error( + "unable to fill in function, enable and check logger for more details" + ) + elseif status == "cancelled" then + logger:debug("fill_in_function was cancelled") + -- TODO: small status window here + elseif status == "success" then + update_file_with_changes(context, response) + end + end, + on_stderr = function(line) + logger:debug("fill_in_function#on_stderr", "line", line) + end, + }) end return fill_in_function diff --git a/lua/99/ops/implement-fn.lua b/lua/99/ops/implement-fn.lua index 85cac0f..efec8a3 100644 --- a/lua/99/ops/implement-fn.lua +++ b/lua/99/ops/implement-fn.lua @@ -10,83 +10,83 @@ local make_clean_up = require("99.ops.clean-up") --- @param context _99.RequestContext --- @param response string local function update_code(context, response) - local code_mark = context.marks.code_placement - local logger = context.logger:set_area("implement_fn#update_code") - local point = Point.from_mark(code_mark) + local code_mark = context.marks.code_placement + local logger = context.logger:set_area("implement_fn#update_code") + local point = Point.from_mark(code_mark) - logger:debug("setting text at mark", "Point", point) - code_mark:set_text_at_mark("\n" .. response) + logger:debug("setting text at mark", "Point", point) + code_mark:set_text_at_mark("\n" .. response) end --- @param context _99.RequestContext local function implement_fn(context) - local ts = editor.treesitter - local cursor = Point:from_cursor() - local buffer = vim.api.nvim_get_current_buf() - local fn_call = ts.fn_call(buffer, cursor) - local logger = context.logger:set_area("implement_fn") + local ts = editor.treesitter + local cursor = Point:from_cursor() + local buffer = vim.api.nvim_get_current_buf() + local fn_call = ts.fn_call(buffer, cursor) + local logger = context.logger:set_area("implement_fn") - if not fn_call then - logger:fatal( - "cannot implement function, cursor was not on an identifier that is a function call" - ) - return - end + if not fn_call then + logger:fatal( + "cannot implement function, cursor was not on an identifier that is a function call" + ) + return + end - local range = Range:from_ts_node(fn_call, buffer) - local request = Request.new(context) + local range = Range:from_ts_node(fn_call, buffer) + local request = Request.new(context) - context.marks.end_of_fn_call = Mark.mark_end_of_range(buffer, range) - local func = ts.containing_function(buffer, cursor) - if func then - context.marks.code_placement = Mark.mark_above_func(buffer, func) - else - context.marks.code_placement = Mark.mark_above_range(range) - end + context.marks.end_of_fn_call = Mark.mark_end_of_range(buffer, range) + local func = ts.containing_function(buffer, cursor) + if func then + context.marks.code_placement = Mark.mark_above_func(buffer, func) + else + context.marks.code_placement = Mark.mark_above_range(range) + end - local code_placement = RequestStatus.new( - 250, - context._99.ai_stdout_rows, - "Loading", - context.marks.code_placement - ) - local at_call_site = RequestStatus.new( - 250, - 1, - "Implementing Function", - context.marks.end_of_fn_call - ) + local code_placement = RequestStatus.new( + 250, + context._99.ai_stdout_rows, + "Loading", + context.marks.code_placement + ) + local at_call_site = RequestStatus.new( + 250, + 1, + "Implementing Function", + context.marks.end_of_fn_call + ) - code_placement:start() - at_call_site:start() + code_placement:start() + at_call_site:start() - local clean_up = make_clean_up(context, function() - context:clear_marks() - request:cancel() - code_placement:stop() - at_call_site:stop() - end) + local clean_up = make_clean_up(context, function() + context:clear_marks() + request:cancel() + code_placement:stop() + at_call_site:stop() + end) - request:add_prompt_content(context._99.prompts.prompts.implement_function) - request:start({ - on_stdout = function(line) - code_placement:push(line) - end, - on_complete = function(status, response) - vim.schedule(clean_up) - if status ~= "success" then - logger:fatal( - "unable to implement function, enable and check logger for more details" - ) - end - pcall(update_code, context, response) - end, - on_stderr = function(line) - logger:error("stderr", "line", line) - end, - }) + request:add_prompt_content(context._99.prompts.prompts.implement_function) + request:start({ + on_stdout = function(line) + code_placement:push(line) + end, + on_complete = function(status, response) + vim.schedule(clean_up) + if status ~= "success" then + logger:fatal( + "unable to implement function, enable and check logger for more details" + ) + end + pcall(update_code, context, response) + end, + on_stderr = function(line) + logger:error("stderr", "line", line) + end, + }) - return request + return request end return implement_fn diff --git a/lua/99/ops/init.lua b/lua/99/ops/init.lua index 38368f9..c807761 100644 --- a/lua/99/ops/init.lua +++ b/lua/99/ops/init.lua @@ -1,5 +1,5 @@ return { - fill_in_function = require("99.ops.fill-in-function"), - implement_fn = require("99.ops.implement-fn"), - over_range = require("99.ops.over-range"), + fill_in_function = require("99.ops.fill-in-function"), + implement_fn = require("99.ops.implement-fn"), + over_range = require("99.ops.over-range"), } diff --git a/lua/99/ops/marks.lua b/lua/99/ops/marks.lua index 0f8a837..3571f1d 100644 --- a/lua/99/ops/marks.lua +++ b/lua/99/ops/marks.lua @@ -15,134 +15,132 @@ Mark.__index = Mark --- @param range _99.Range --- @return _99.Mark function Mark.mark_above_range(range) - local buffer = range.buffer - local start = range.start - local line, _ = start:to_vim() - local above = line == 0 and line or line - 1 + local buffer = range.buffer + local start = range.start + local line, _ = start:to_vim() + local above = line == 0 and line or line - 1 - -- luacheck: ignore - local id = nil - if above == line then - id = vim.api.nvim_buf_set_extmark(buffer, nsid, above, 0, {}) - else - local text = - vim.api.nvim_buf_get_lines(buffer, above, above + 1, false)[1] - local ending = #text - id = vim.api.nvim_buf_set_extmark(buffer, nsid, above, ending, {}) - end + -- luacheck: ignore + local id = nil + if above == line then + id = vim.api.nvim_buf_set_extmark(buffer, nsid, above, 0, {}) + else + local text = vim.api.nvim_buf_get_lines(buffer, above, above + 1, false)[1] + local ending = #text + id = vim.api.nvim_buf_set_extmark(buffer, nsid, above, ending, {}) + end - return setmetatable({ - id = id, - buffer = buffer, - nsid = nsid, - }, Mark) + return setmetatable({ + id = id, + buffer = buffer, + nsid = nsid, + }, Mark) end --- @param range _99.Range --- @return _99.Mark --- @return _99.Mark function Mark.mark_range(range) - local buffer = range.buffer - return Mark.mark_point(buffer, range.start), - Mark.mark_point(buffer, range.end_) + local buffer = range.buffer + return Mark.mark_point(buffer, range.start), + Mark.mark_point(buffer, range.end_) end --- @return boolean function Mark:is_valid() - local pos = - vim.api.nvim_buf_get_extmark_by_id(self.buffer, self.nsid, self.id, {}) - return #pos > 0 + local pos = + vim.api.nvim_buf_get_extmark_by_id(self.buffer, self.nsid, self.id, {}) + return #pos > 0 end --- @param buffer number --- @param point _99.Point --- @return _99.Mark function Mark.mark_point(buffer, point) - local line, col = point:to_vim() - local id = vim.api.nvim_buf_set_extmark(buffer, nsid, line, col, {}) + local line, col = point:to_vim() + local id = vim.api.nvim_buf_set_extmark(buffer, nsid, line, col, {}) - return setmetatable({ - id = id, - buffer = buffer, - nsid = nsid, - }, Mark) + return setmetatable({ + id = id, + buffer = buffer, + nsid = nsid, + }, Mark) end --- @param buffer number --- @param func _99.treesitter.Function --- @return _99.Mark function Mark.mark_above_func(buffer, func) - local start = func.function_range.start - local line, col = start:to_vim() - local id = vim.api.nvim_buf_set_extmark(buffer, nsid, line - 1, col, {}) + local start = func.function_range.start + local line, col = start:to_vim() + local id = vim.api.nvim_buf_set_extmark(buffer, nsid, line - 1, col, {}) - return setmetatable({ - id = id, - buffer = buffer, - nsid = nsid, - }, Mark) + return setmetatable({ + id = id, + buffer = buffer, + nsid = nsid, + }, Mark) end ---@param buffer number ---@param range _99.Range ---@return _99.Mark function Mark.mark_end_of_range(buffer, range) - local end_ = range.end_ - local line, col = end_:to_vim() - local id = vim.api.nvim_buf_set_extmark(buffer, nsid, line, col + 1, {}) + local end_ = range.end_ + local line, col = end_:to_vim() + local id = vim.api.nvim_buf_set_extmark(buffer, nsid, line, col + 1, {}) - return setmetatable({ - id = id, - buffer = buffer, - nsid = nsid, - }, Mark) + return setmetatable({ + id = id, + buffer = buffer, + nsid = nsid, + }, Mark) end --- @param buffer number --- @param func _99.treesitter.Function --- @return _99.Mark function Mark.mark_func_body(buffer, func) - local start = func.function_range.start - local line, col = start:to_vim() - local id = vim.api.nvim_buf_set_extmark(buffer, nsid, line, col, {}) + local start = func.function_range.start + local line, col = start:to_vim() + local id = vim.api.nvim_buf_set_extmark(buffer, nsid, line, col, {}) - return setmetatable({ - id = id, - buffer = buffer, - nsid = nsid, - }, Mark) + return setmetatable({ + id = id, + buffer = buffer, + nsid = nsid, + }, Mark) end --- @param lines string[] function Mark:set_virtual_text(lines) - local pos = - vim.api.nvim_buf_get_extmark_by_id(self.buffer, nsid, self.id, {}) - assert(#pos > 0, "extmark is broken. it does not exist") - local row, col = pos[1], pos[2] + local pos = vim.api.nvim_buf_get_extmark_by_id(self.buffer, nsid, self.id, {}) + assert(#pos > 0, "extmark is broken. it does not exist") + local row, col = pos[1], pos[2] - local formatted_lines = {} - for _, line in ipairs(lines) do - table.insert(formatted_lines, { - { line, "Comment" }, - }) - end - - vim.api.nvim_buf_set_extmark(self.buffer, nsid, row, col, { - id = self.id, - virt_lines = formatted_lines, + local formatted_lines = {} + for _, line in ipairs(lines) do + table.insert(formatted_lines, { + { line, "Comment" }, }) + end + + vim.api.nvim_buf_set_extmark(self.buffer, nsid, row, col, { + id = self.id, + virt_lines = formatted_lines, + }) end --- @param text string function Mark:set_text_at_mark(text) - local point = Point.from_mark(self) - local row, col = point:to_vim() - local lines = vim.split(text, "\n") - vim.api.nvim_buf_set_text(self.buffer, row, col, row, col, lines) + local point = Point.from_mark(self) + local row, col = point:to_vim() + local lines = vim.split(text, "\n") + vim.api.nvim_buf_set_text(self.buffer, row, col, row, col, lines) end function Mark:delete() - vim.api.nvim_buf_del_extmark(self.buffer, nsid, self.id) + vim.api.nvim_buf_del_extmark(self.buffer, nsid, self.id) end return Mark 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 diff --git a/lua/99/ops/request_status.lua b/lua/99/ops/request_status.lua index f05121d..9b3dc5e 100644 --- a/lua/99/ops/request_status.lua +++ b/lua/99/ops/request_status.lua @@ -1,5 +1,5 @@ local braille_chars = - { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" } + { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" } --- @class _99.StatusLine --- @field index number @@ -10,21 +10,21 @@ StatusLine.__index = StatusLine --- @param title_line string --- @return _99.StatusLine function StatusLine.new(title_line) - local self = setmetatable({}, StatusLine) - self.index = 1 - self.title_line = title_line - return self + local self = setmetatable({}, StatusLine) + self.index = 1 + self.title_line = title_line + return self end function StatusLine:update() - self.index = self.index + 1 + self.index = self.index + 1 end --- @return string function StatusLine:to_string() - return braille_chars[self.index % #braille_chars + 1] - .. " " - .. self.title_line + return braille_chars[self.index % #braille_chars + 1] + .. " " + .. self.title_line end --- @class _99.RequestStatus @@ -43,50 +43,50 @@ RequestStatus.__index = RequestStatus --- @param mark _99.Mark --- @return _99.RequestStatus function RequestStatus.new(update_time, max_lines, title_line, mark) - local self = setmetatable({}, RequestStatus) - self.update_time = update_time - self.max_lines = max_lines - self.status_line = StatusLine.new(title_line) - self.lines = {} - self.running = false - self.mark = mark - return self + local self = setmetatable({}, RequestStatus) + self.update_time = update_time + self.max_lines = max_lines + self.status_line = StatusLine.new(title_line) + self.lines = {} + self.running = false + self.mark = mark + return self end --- @return string[] function RequestStatus:get() - local result = { self.status_line:to_string() } - for _, line in ipairs(self.lines) do - table.insert(result, line) - end - return result + local result = { self.status_line:to_string() } + for _, line in ipairs(self.lines) do + table.insert(result, line) + end + return result end --- @param line string function RequestStatus:push(line) - table.insert(self.lines, line) - if #self.lines > self.max_lines - 1 then - table.remove(self.lines, 1) - end + table.insert(self.lines, line) + if #self.lines > self.max_lines - 1 then + table.remove(self.lines, 1) + end end function RequestStatus:start() - local function update_spinner() - if not self.running then - return - end - - self.status_line:update() - self.mark:set_virtual_text(self:get()) - vim.defer_fn(update_spinner, self.update_time) + local function update_spinner() + if not self.running then + return end - self.running = true + self.status_line:update() + self.mark:set_virtual_text(self:get()) vim.defer_fn(update_spinner, self.update_time) + end + + self.running = true + vim.defer_fn(update_spinner, self.update_time) end function RequestStatus:stop() - self.running = false + self.running = false end return RequestStatus |
