Skip to content

Commit 7ed41d1

Browse files
authored
feat(ui): add enable_treesitter_markdown config for markdown rendering in output window (#297)
This should help with #293
1 parent f18d895 commit 7ed41d1

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ require('opencode').setup({
201201
},
202202
},
203203
ui = {
204+
enable_treesitter_markdown = true, -- Use Treesitter for markdown rendering in the output window (default: true).
204205
position = 'right', -- 'right' (default), 'left' or 'current'. Position of the UI split. 'current' uses the current window for the output.
205206
input_position = 'bottom', -- 'bottom' (default) or 'top'. Position of the input window
206207
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
636637
- `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.
637638

638639
Example keymap for silent add:
640+
639641
```lua
640642
['<leader>oY'] = { 'add_visual_selection', { open_input = false }, mode = {'v'} }
641643
```

lua/opencode/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ M.defaults = {
107107
},
108108
},
109109
ui = {
110+
enable_treesitter_markdown = true,
110111
position = 'right',
111112
input_position = 'bottom',
112113
window_width = 0.40,

lua/opencode/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
---@field frames string[]
113113

114114
---@class OpencodeUIConfig
115+
---@field enable_treesitter_markdown boolean
115116
---@field position 'right'|'left'|'current' # Position of the UI (default: 'right')
116117
---@field input_position 'bottom'|'top' # Position of the input window (default: 'bottom')
117118
---@field window_width number

lua/opencode/ui/ui.lua

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ local function capture_hidden_snapshot(windows)
7676
output_view = ok and type(view) == 'table' and view or nil,
7777
focused_window = focused,
7878
position = config.ui.position,
79-
owner_tab = state.are_windows_in_current_tab()
80-
and vim.api.nvim_get_current_tabpage() or nil,
79+
owner_tab = state.are_windows_in_current_tab() and vim.api.nvim_get_current_tabpage() or nil,
8180
}
8281
end
8382

@@ -92,8 +91,12 @@ function M.close_windows(windows, persist)
9291
end
9392

9493
local function prepare_window_close()
95-
if M.is_opencode_focused() then M.return_to_last_code_win() end
96-
if state.display_route then state.display_route = nil end
94+
if M.is_opencode_focused() then
95+
M.return_to_last_code_win()
96+
end
97+
if state.display_route then
98+
state.display_route = nil
99+
end
97100

98101
pcall(vim.api.nvim_del_augroup_by_name, 'OpencodeResize')
99102
pcall(vim.api.nvim_del_augroup_by_name, 'OpencodeWindows')
@@ -145,7 +148,9 @@ function M.hide_visible_windows(windows)
145148
end
146149
if windows.input_buf and vim.api.nvim_buf_is_valid(windows.input_buf) then
147150
local ok, lines = pcall(vim.api.nvim_buf_get_lines, windows.input_buf, 0, -1, false)
148-
if ok then state.input_content = lines end
151+
if ok then
152+
state.input_content = lines
153+
end
149154
end
150155
state.stash_hidden_buffers(snapshot)
151156
if state.windows == windows then
@@ -242,7 +247,9 @@ function M.restore_hidden_windows()
242247

243248
vim.schedule(function()
244249
local w = state.windows
245-
if not w then return end
250+
if not w then
251+
return
252+
end
246253

247254
if hidden.output_was_at_bottom then
248255
renderer.scroll_to_bottom(true)
@@ -323,8 +330,10 @@ function M.create_split_windows(input_buf, output_buf)
323330
end
324331

325332
function M.create_windows()
326-
vim.treesitter.language.register('markdown', 'opencode_output')
327-
vim.treesitter.language.register('markdown', 'opencode')
333+
if config.ui.enable_treesitter_markdown then
334+
vim.treesitter.language.register('markdown', 'opencode_output')
335+
vim.treesitter.language.register('markdown', 'opencode')
336+
end
328337

329338
local autocmds = require('opencode.ui.autocmds')
330339

0 commit comments

Comments
 (0)