Skip to content

Commit e31ce17

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 25ad56c commit e31ce17

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
@@ -343,10 +343,19 @@ local function format_selection_part(selection)
343343
}
344344
end
345345

346+
---@param diagnostics vim.Diagnostic[]
346347
local function format_diagnostics_part(diagnostics)
348+
local diag_list = {}
349+
for _, diag in ipairs(diagnostics) do
350+
local short_msg = diag.message:gsub('%s+', ' '):gsub('^%s', ''):gsub('%s$', '')
351+
table.insert(
352+
diag_list,
353+
{ msg = short_msg, severity = diag.severity, pos = 'l' .. diag.lnum + 1 .. ':c' .. diag.col + 1 }
354+
)
355+
end
347356
return {
348357
type = 'text',
349-
text = vim.json.encode({ context_type = 'diagnostics', content = diagnostics }),
358+
text = vim.json.encode({ context_type = 'diagnostics', content = diag_list }),
350359
synthetic = true,
351360
}
352361
end

0 commit comments

Comments
 (0)