update oc.nvim
This commit is contained in:
@@ -20,6 +20,36 @@ in {
|
|||||||
render-markdown-nvim
|
render-markdown-nvim
|
||||||
];
|
];
|
||||||
extraConfigLua = ''
|
extraConfigLua = ''
|
||||||
|
local api = vim.api
|
||||||
|
local opencode_output_filetype = 'opencode_output'
|
||||||
|
local opencode_window_filetypes = {
|
||||||
|
opencode = true,
|
||||||
|
opencode_output = true,
|
||||||
|
}
|
||||||
|
|
||||||
|
local palette = {
|
||||||
|
base = '#eff1f5',
|
||||||
|
mantle = '#e6e9ef',
|
||||||
|
surface0 = '#ccd0da',
|
||||||
|
surface1 = '#bcc0cc',
|
||||||
|
text = '#4c4f69',
|
||||||
|
subtext0 = '#6c6f85',
|
||||||
|
overlay0 = '#9ca0b0',
|
||||||
|
blue = '#1e66f5',
|
||||||
|
lavender = '#7287fd',
|
||||||
|
sapphire = '#209fb5',
|
||||||
|
teal = '#179299',
|
||||||
|
green = '#40a02b',
|
||||||
|
mauve = '#8839ef',
|
||||||
|
peach = '#fe640b',
|
||||||
|
}
|
||||||
|
|
||||||
|
local function set_highlights(highlights)
|
||||||
|
for group, spec in pairs(highlights) do
|
||||||
|
api.nvim_set_hl(0, group, spec)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local opencode_markdown_conceal_query = vim.treesitter.query.parse('markdown_inline', [[
|
local opencode_markdown_conceal_query = vim.treesitter.query.parse('markdown_inline', [[
|
||||||
[
|
[
|
||||||
(emphasis_delimiter)
|
(emphasis_delimiter)
|
||||||
@@ -66,28 +96,7 @@ in {
|
|||||||
] @conceal)
|
] @conceal)
|
||||||
]])
|
]])
|
||||||
|
|
||||||
local function set_opencode_output_conceal()
|
local function collect_conceal_marks(ctx)
|
||||||
if vim.bo.filetype ~= 'opencode_output' then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.wo.conceallevel = 3
|
|
||||||
vim.wo.concealcursor = 'nvic'
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.treesitter.language.register('markdown', 'opencode_output')
|
|
||||||
vim.treesitter.language.register('markdown_inline', 'opencode_output')
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd({ 'FileType', 'BufWinEnter', 'WinEnter' }, {
|
|
||||||
callback = set_opencode_output_conceal,
|
|
||||||
})
|
|
||||||
|
|
||||||
require('render-markdown').setup({
|
|
||||||
anti_conceal = { enabled = false },
|
|
||||||
custom_handlers = {
|
|
||||||
markdown_inline = {
|
|
||||||
extends = true,
|
|
||||||
parse = function(ctx)
|
|
||||||
local marks = {}
|
local marks = {}
|
||||||
|
|
||||||
for _, node in opencode_markdown_conceal_query:iter_captures(ctx.root, ctx.buf) do
|
for _, node in opencode_markdown_conceal_query:iter_captures(ctx.root, ctx.buf) do
|
||||||
@@ -105,15 +114,112 @@ in {
|
|||||||
end
|
end
|
||||||
|
|
||||||
return marks
|
return marks
|
||||||
end,
|
end
|
||||||
|
|
||||||
|
local function set_opencode_output_conceal()
|
||||||
|
if vim.bo.filetype ~= opencode_output_filetype then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.wo.conceallevel = 3
|
||||||
|
vim.wo.concealcursor = 'nvic'
|
||||||
|
end
|
||||||
|
|
||||||
|
local function hide_opencode_statusline()
|
||||||
|
if not opencode_window_filetypes[vim.bo.filetype] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.wo.statusline = ' '
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.treesitter.language.register('markdown', opencode_output_filetype)
|
||||||
|
vim.treesitter.language.register('markdown_inline', opencode_output_filetype)
|
||||||
|
|
||||||
|
api.nvim_create_autocmd({ 'FileType', 'BufWinEnter', 'WinEnter' }, {
|
||||||
|
callback = set_opencode_output_conceal,
|
||||||
|
})
|
||||||
|
api.nvim_create_autocmd({ 'FileType', 'BufWinEnter', 'WinEnter', 'BufEnter' }, {
|
||||||
|
pattern = '*',
|
||||||
|
callback = hide_opencode_statusline,
|
||||||
|
})
|
||||||
|
|
||||||
|
set_highlights({
|
||||||
|
RenderMarkdownCode = { bg = palette.mantle },
|
||||||
|
RenderMarkdownCodeBorder = { fg = palette.surface0, bg = palette.mantle },
|
||||||
|
RenderMarkdownCodeInline = { bg = palette.mantle },
|
||||||
|
RenderMarkdownH1 = { fg = palette.blue, bold = true },
|
||||||
|
RenderMarkdownH2 = { fg = palette.mauve, bold = true },
|
||||||
|
RenderMarkdownH3 = { fg = palette.teal, bold = true },
|
||||||
|
RenderMarkdownH4 = { fg = palette.peach, bold = true },
|
||||||
|
OpencodeInputLegend = { fg = palette.subtext0, bold = true },
|
||||||
|
OpencodeAgentBuild = { bg = palette.overlay0, fg = palette.base, bold = true },
|
||||||
|
})
|
||||||
|
|
||||||
|
local render_markdown_config = {
|
||||||
|
anti_conceal = { enabled = false },
|
||||||
|
heading = {
|
||||||
|
icons = { '◆ ', '◇ ', '○ ', '· ', '· ', '· ' },
|
||||||
|
backgrounds = {},
|
||||||
|
position = 'inline',
|
||||||
|
width = 'block',
|
||||||
|
left_pad = 0,
|
||||||
|
right_pad = 2,
|
||||||
|
border = false,
|
||||||
|
sign = false,
|
||||||
|
},
|
||||||
|
code = {
|
||||||
|
sign = false,
|
||||||
|
width = 'full',
|
||||||
|
left_pad = 2,
|
||||||
|
right_pad = 0,
|
||||||
|
border = 'thin',
|
||||||
|
language_icon = false,
|
||||||
|
language_name = true,
|
||||||
|
},
|
||||||
|
bullet = {
|
||||||
|
icons = { '·', '–', '·', '–' },
|
||||||
|
},
|
||||||
|
custom_handlers = {
|
||||||
|
markdown_inline = {
|
||||||
|
extends = true,
|
||||||
|
parse = collect_conceal_marks,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
file_types = { 'opencode_output' },
|
file_types = { opencode_output_filetype },
|
||||||
win_options = {
|
win_options = {
|
||||||
conceallevel = { rendered = 3 },
|
conceallevel = { rendered = 3 },
|
||||||
concealcursor = { rendered = "nvic" },
|
concealcursor = { rendered = 'nvic' },
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
|
||||||
|
require('render-markdown').setup(render_markdown_config)
|
||||||
|
|
||||||
|
local opencode_icon_overrides = {
|
||||||
|
header_user = '│',
|
||||||
|
header_assistant = '│',
|
||||||
|
run = '▸',
|
||||||
|
task = '◦',
|
||||||
|
read = '◦',
|
||||||
|
edit = '◦',
|
||||||
|
write = '◦',
|
||||||
|
plan = '◦',
|
||||||
|
search = '◦',
|
||||||
|
web = '◦',
|
||||||
|
list = '◦',
|
||||||
|
tool = '◦',
|
||||||
|
snapshot = '◦',
|
||||||
|
restore_point = '◦',
|
||||||
|
file = '·',
|
||||||
|
folder = '·',
|
||||||
|
attached_file = '·',
|
||||||
|
agent = '·',
|
||||||
|
reference = '·',
|
||||||
|
reasoning = '◦',
|
||||||
|
question = '?',
|
||||||
|
border = '│',
|
||||||
|
}
|
||||||
|
|
||||||
require('opencode').setup({
|
require('opencode').setup({
|
||||||
server = {
|
server = {
|
||||||
url = 'http://127.0.0.1',
|
url = 'http://127.0.0.1',
|
||||||
@@ -125,9 +231,13 @@ in {
|
|||||||
wrap = true,
|
wrap = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
debug = {
|
||||||
|
show_ids = false,
|
||||||
|
},
|
||||||
ui = {
|
ui = {
|
||||||
icons = {
|
icons = {
|
||||||
preset = 'nerdfonts',
|
preset = 'nerdfonts',
|
||||||
|
overrides = opencode_icon_overrides,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -139,12 +249,10 @@ in {
|
|||||||
local icons = require('opencode.ui.icons')
|
local icons = require('opencode.ui.icons')
|
||||||
local util = require('opencode.util')
|
local util = require('opencode.util')
|
||||||
|
|
||||||
formatter._format_reasoning = function(output, part)
|
local function format_reasoning_title(part)
|
||||||
local text = vim.trim(part.text or "")
|
|
||||||
local start_line = output:get_line_count() + 1
|
|
||||||
|
|
||||||
local title = 'Reasoning'
|
local title = 'Reasoning'
|
||||||
local time = part.time
|
local time = part.time
|
||||||
|
|
||||||
if time and type(time) == 'table' and time.start then
|
if time and type(time) == 'table' and time.start then
|
||||||
local duration_text = util.format_duration_seconds(time.start, time['end'])
|
local duration_text = util.format_duration_seconds(time.start, time['end'])
|
||||||
if duration_text then
|
if duration_text then
|
||||||
@@ -152,7 +260,27 @@ in {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
format_utils.format_action(output, icons.get('reasoning'), title, "")
|
return title
|
||||||
|
end
|
||||||
|
|
||||||
|
local function highlight_reasoning_block(output, start_line)
|
||||||
|
local end_line = output:get_line_count()
|
||||||
|
|
||||||
|
if end_line - start_line > 1 then
|
||||||
|
formatter.add_vertical_border(output, start_line, end_line, 'OpencodeToolBorder', -1, 'OpencodeReasoningText')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
output:add_extmark(start_line - 1, {
|
||||||
|
line_hl_group = 'OpencodeReasoningText',
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
formatter._format_reasoning = function(output, part)
|
||||||
|
local text = vim.trim(part.text or "")
|
||||||
|
local start_line = output:get_line_count() + 1
|
||||||
|
|
||||||
|
format_utils.format_action(output, icons.get('reasoning'), format_reasoning_title(part), "")
|
||||||
|
|
||||||
if config.ui.output.tools.show_reasoning_output and text ~= "" then
|
if config.ui.output.tools.show_reasoning_output and text ~= "" then
|
||||||
output:add_empty_line()
|
output:add_empty_line()
|
||||||
@@ -160,14 +288,7 @@ in {
|
|||||||
output:add_empty_line()
|
output:add_empty_line()
|
||||||
end
|
end
|
||||||
|
|
||||||
local end_line = output:get_line_count()
|
highlight_reasoning_block(output, start_line)
|
||||||
if end_line - start_line > 1 then
|
|
||||||
formatter.add_vertical_border(output, start_line, end_line, 'OpencodeToolBorder', -1, 'OpencodeReasoningText')
|
|
||||||
else
|
|
||||||
output:add_extmark(start_line - 1, {
|
|
||||||
line_hl_group = 'OpencodeReasoningText',
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
|
|||||||
Reference in New Issue
Block a user