Skip to content

Commit 30ace5e

Browse files
committed
feat(context): reduce diagnostic token count drastically
Only send important information for context not everything vim diagnostics. This reduces the token count by almost 3x
1 parent 0370e7f commit 30ace5e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lua/opencode/context.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,19 @@ local function format_selection_part(selection)
358358
}
359359
end
360360

361+
---@param diagnostics vim.Diagnostic[]
361362
local function format_diagnostics_part(diagnostics)
363+
local diag_list = {}
364+
for _, diag in ipairs(diagnostics) do
365+
local short_msg = diag.message:gsub('%s+', ' '):gsub('^%s', ''):gsub('%s$', '')
366+
table.insert(
367+
diag_list,
368+
{ msg = short_msg, severity = diag.severity, pos = 'l' .. diag.lnum + 1 .. ':c' .. diag.col + 1 }
369+
)
370+
end
362371
return {
363372
type = 'text',
364-
text = vim.json.encode({ context_type = 'diagnostics', content = diagnostics }),
373+
text = vim.json.encode({ context_type = 'diagnostics', content = diag_list }),
365374
synthetic = true,
366375
}
367376
end

0 commit comments

Comments
 (0)