summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua/99/geo.lua3
-rw-r--r--lua/99/init.lua6
-rw-r--r--lua/99/ops/marks.lua10
-rw-r--r--lua/99/ops/request_status.lua8
-rw-r--r--lua/99/ops/visual.lua14
-rw-r--r--scratch/refresh.lua10
6 files changed, 27 insertions, 24 deletions
diff --git a/lua/99/geo.lua b/lua/99/geo.lua
index 96f9898..f2c0d13 100644
--- a/lua/99/geo.lua
+++ b/lua/99/geo.lua
@@ -217,8 +217,6 @@ function Range.from_visual_selection()
local buffer = vim.api.nvim_get_current_buf()
local start_pos = vim.fn.getpos("'<")
local end_pos = vim.fn.getpos("'>")
- print("range#start", vim.inspect(start_pos))
- print("range#end", vim.inspect(end_pos))
local start = Point:new(start_pos[2], start_pos[3])
local end_ = Point:new(end_pos[2], end_pos[3])
@@ -227,7 +225,6 @@ function Range.from_visual_selection()
--- row length
local end_r, _ = end_:to_vim()
local end_line = vim.api.nvim_buf_get_lines(buffer, end_r, end_r + 1, false)[1]
- print("range#line", string.format("'%s'", end_line))
local actual_end = Point:new(end_pos[2], math.min(end_pos[3], #end_line + 1))
return Range:new(buffer, start, actual_end)
diff --git a/lua/99/init.lua b/lua/99/init.lua
index 34f5f1d..ee3e327 100644
--- a/lua/99/init.lua
+++ b/lua/99/init.lua
@@ -104,8 +104,8 @@ local _99 = {
FATAL = Level.FATAL,
}
-local function reselect()
- vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>gv", true, false, true), "x", false)
+local function set_selection_marks()
+ vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "x", false)
end
--- @param operation_name string
@@ -129,7 +129,7 @@ function _99.visual()
---
--- Therefore i did something so very cursed. escape sets the mark, gv sets
--- the previous visual selection. super cursed
- reselect()
+ set_selection_marks()
local context = get_context("visual")
local range = Range.from_visual_selection()
diff --git a/lua/99/ops/marks.lua b/lua/99/ops/marks.lua
index 1a4e7a7..fbe26ba 100644
--- a/lua/99/ops/marks.lua
+++ b/lua/99/ops/marks.lua
@@ -19,7 +19,15 @@ function Mark.mark_above_range(range)
local start = range.start
local line, _ = start:to_vim()
local above = line == 0 and line or line - 1
- local id = vim.api.nvim_buf_set_extmark(buffer, nsid, above, 0, {})
+
+ 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,
diff --git a/lua/99/ops/request_status.lua b/lua/99/ops/request_status.lua
index d104dda..f05121d 100644
--- a/lua/99/ops/request_status.lua
+++ b/lua/99/ops/request_status.lua
@@ -33,14 +33,14 @@ end
--- @field lines string[]
--- @field max_lines number
--- @field running boolean
---- @field mark _99.Mark?
+--- @field mark _99.Mark
local RequestStatus = {}
RequestStatus.__index = RequestStatus
--- @param update_time number
--- @param max_lines number
--- @param title_line string
---- @param mark _99.Mark?
+--- @param mark _99.Mark
--- @return _99.RequestStatus
function RequestStatus.new(update_time, max_lines, title_line, mark)
local self = setmetatable({}, RequestStatus)
@@ -77,9 +77,7 @@ function RequestStatus:start()
end
self.status_line:update()
- if self.mark then
- self.mark:set_virtual_text(self:get())
- end
+ self.mark:set_virtual_text(self:get())
vim.defer_fn(update_spinner, self.update_time)
end
diff --git a/lua/99/ops/visual.lua b/lua/99/ops/visual.lua
index edca0b0..b42bad9 100644
--- a/lua/99/ops/visual.lua
+++ b/lua/99/ops/visual.lua
@@ -12,15 +12,16 @@ local function visual(context, range)
local logger = context.logger:set_area("visual")
local request = Request.new(context)
- local top_mark, bottom_mark = Mark.mark_range(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))
local display_ai_status = context._99.ai_stdout_rows > 1
- local top_status = RequestStatus.new(250, context._99.ai_stdout_rows or 1, "Implementing...")
- local bottom_status = RequestStatus.new(250, 1, "Implementing...")
+ 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()
@@ -44,8 +45,15 @@ local function visual(context, range)
if not valid then
logger:fatal("the original visual_selection has been destroyed. You cannot delete the original visual selection during a request")
end
+
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, "")
+
new_range:replace_text(lines)
end
end,
diff --git a/scratch/refresh.lua b/scratch/refresh.lua
index 42ba7e4..2d7b27b 100644
--- a/scratch/refresh.lua
+++ b/scratch/refresh.lua
@@ -1,17 +1,9 @@
R("99")
+local foo_bar = {fizz = 3}
function fizz_buzz(count)
local result = {}
for i = 1, count do
- if i % 15 == 0 then
- table.insert(result, "FizzBuzz")
- elseif i % 3 == 0 then
- table.insert(result, "Fizz")
- elseif i % 5 == 0 then
- table.insert(result, "Buzz")
- else
- table.insert(result, i)
- end
end
return result
end