Skip to content

Commit 335ed75

Browse files
committed
fix(formatter): extmarks should be 0 indexed
To be consistent with nvim apis
1 parent bd7ca59 commit 335ed75

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

lua/opencode/ui/formatter.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function M._format_revert_message(session_data, start_idx)
140140
local col = #(' ' .. file .. ': ')
141141
for _, diff in ipairs(file_diff) do
142142
local hl_group = diff:sub(1, 1) == '+' and 'OpencodeDiffAddText' or 'OpencodeDiffDeleteText'
143-
output:add_extmark(line_idx, {
143+
output:add_extmark(line_idx - 1, {
144144
virt_text = { { diff, hl_group } },
145145
virt_text_pos = 'inline',
146146
virt_text_win_col = col,
@@ -259,7 +259,7 @@ function M.format_message_header(message)
259259
display_name = role:upper()
260260
end
261261

262-
output:add_extmark(output:get_line_count(), {
262+
output:add_extmark(output:get_line_count() - 1, {
263263
virt_text = {
264264
{ icon, role_hl },
265265
{ ' ' },
@@ -636,7 +636,7 @@ function M._format_diff(output, code, file_type)
636636
local hl_group = first_char == '+' and 'OpencodeDiffAdd' or 'OpencodeDiffDelete'
637637
output:add_line(' ' .. line:sub(2))
638638
local line_idx = output:get_line_count()
639-
output:add_extmark(line_idx, function()
639+
output:add_extmark(line_idx - 1, function()
640640
return {
641641
end_col = 0,
642642
end_row = line_idx,
@@ -665,7 +665,7 @@ end
665665
---@param win_col number
666666
function M._add_vertical_border(output, start_line, end_line, hl_group, win_col)
667667
for line = start_line, end_line do
668-
output:add_extmark(line, {
668+
output:add_extmark(line - 1, {
669669
virt_text = { { require('opencode.ui.icons').get('border'), hl_group } },
670670
virt_text_pos = 'overlay',
671671
virt_text_win_col = win_col,

lua/opencode/ui/mention.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function M.highlight_mentions_in_output(output, text, mentions, start_line)
6767
local start_pos, end_pos = string.find(line, mention.value, 1, true)
6868

6969
if start_pos then
70-
output:add_extmark(start_line + i, {
70+
output:add_extmark(start_line + i - 1, {
7171
start_col = start_pos - 1,
7272
end_col = end_pos,
7373
hl_group = 'OpencodeMention',
@@ -80,7 +80,7 @@ function M.highlight_mentions_in_output(output, text, mentions, start_line)
8080
local col_start = char_start - line_start
8181
local col_end = math.min(char_end - line_start + 1, #line)
8282

83-
output:add_extmark(start_line + i, {
83+
output:add_extmark(start_line + i - 1, {
8484
start_col = col_start,
8585
end_col = col_end,
8686
hl_group = 'OpencodeMention',

lua/opencode/ui/output_window.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function M.set_extmarks(extmarks, line_offset)
119119
for line_idx, marks in pairs(extmarks) do
120120
for _, mark in ipairs(marks) do
121121
local actual_mark = type(mark) == 'function' and mark() or mark
122-
local target_line = line_offset + line_idx - 1
122+
local target_line = line_offset + line_idx
123123
if actual_mark.end_row then
124124
actual_mark.end_row = actual_mark.end_row + line_offset
125125
end

0 commit comments

Comments
 (0)