From 7818704cfc3b7decfacb8f30b9d8e530eb9c98cc Mon Sep 17 00:00:00 2001 From: Francis Belanger Date: Tue, 24 Feb 2026 09:13:39 -0500 Subject: [PATCH] feat(ui): add enable_treesitter_markdown config for markdown rendering in output window This should help with #293 --- README.md | 2 ++ lua/opencode/config.lua | 1 + lua/opencode/types.lua | 1 + lua/opencode/ui/ui.lua | 25 +++++++++++++++++-------- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index bf895cbf..d41f4353 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,7 @@ require('opencode').setup({ }, }, ui = { + enable_treesitter_markdown = true, -- Use Treesitter for markdown rendering in the output window (default: true). position = 'right', -- 'right' (default), 'left' or 'current'. Position of the UI split. 'current' uses the current window for the output. input_position = 'bottom', -- 'bottom' (default) or 'top'. Position of the input window window_width = 0.40, -- Width as percentage of editor width @@ -636,6 +637,7 @@ The plugin provides the following actions that can be triggered via keymaps, com - `open_input` (boolean, default: `true`): Whether to open the input window after adding the selection. Set to `false` to add selection silently without changing focus. Example keymap for silent add: + ```lua ['oY'] = { 'add_visual_selection', { open_input = false }, mode = {'v'} } ``` diff --git a/lua/opencode/config.lua b/lua/opencode/config.lua index 573e888d..c930a233 100644 --- a/lua/opencode/config.lua +++ b/lua/opencode/config.lua @@ -107,6 +107,7 @@ M.defaults = { }, }, ui = { + enable_treesitter_markdown = true, position = 'right', input_position = 'bottom', window_width = 0.40, diff --git a/lua/opencode/types.lua b/lua/opencode/types.lua index b52d085c..cd29fcc9 100644 --- a/lua/opencode/types.lua +++ b/lua/opencode/types.lua @@ -112,6 +112,7 @@ ---@field frames string[] ---@class OpencodeUIConfig +---@field enable_treesitter_markdown boolean ---@field position 'right'|'left'|'current' # Position of the UI (default: 'right') ---@field input_position 'bottom'|'top' # Position of the input window (default: 'bottom') ---@field window_width number diff --git a/lua/opencode/ui/ui.lua b/lua/opencode/ui/ui.lua index fd69d6ee..887afccc 100644 --- a/lua/opencode/ui/ui.lua +++ b/lua/opencode/ui/ui.lua @@ -76,8 +76,7 @@ local function capture_hidden_snapshot(windows) output_view = ok and type(view) == 'table' and view or nil, focused_window = focused, position = config.ui.position, - owner_tab = state.are_windows_in_current_tab() - and vim.api.nvim_get_current_tabpage() or nil, + owner_tab = state.are_windows_in_current_tab() and vim.api.nvim_get_current_tabpage() or nil, } end @@ -92,8 +91,12 @@ function M.close_windows(windows, persist) end local function prepare_window_close() - if M.is_opencode_focused() then M.return_to_last_code_win() end - if state.display_route then state.display_route = nil end + if M.is_opencode_focused() then + M.return_to_last_code_win() + end + if state.display_route then + state.display_route = nil + end pcall(vim.api.nvim_del_augroup_by_name, 'OpencodeResize') pcall(vim.api.nvim_del_augroup_by_name, 'OpencodeWindows') @@ -145,7 +148,9 @@ function M.hide_visible_windows(windows) end if windows.input_buf and vim.api.nvim_buf_is_valid(windows.input_buf) then local ok, lines = pcall(vim.api.nvim_buf_get_lines, windows.input_buf, 0, -1, false) - if ok then state.input_content = lines end + if ok then + state.input_content = lines + end end state.stash_hidden_buffers(snapshot) if state.windows == windows then @@ -242,7 +247,9 @@ function M.restore_hidden_windows() vim.schedule(function() local w = state.windows - if not w then return end + if not w then + return + end if hidden.output_was_at_bottom then renderer.scroll_to_bottom(true) @@ -323,8 +330,10 @@ function M.create_split_windows(input_buf, output_buf) end function M.create_windows() - vim.treesitter.language.register('markdown', 'opencode_output') - vim.treesitter.language.register('markdown', 'opencode') + if config.ui.enable_treesitter_markdown then + vim.treesitter.language.register('markdown', 'opencode_output') + vim.treesitter.language.register('markdown', 'opencode') + end local autocmds = require('opencode.ui.autocmds')