Skip to content

Commit 60d94ba

Browse files
committed
feat(ui): add filetype config for output buffer
1 parent a4fdf89 commit 60d94ba

5 files changed

Lines changed: 47 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ require('opencode').setup({
232232
use_vim_ui_select = false, -- If true, render questions/prompts with vim.ui.select instead of showing them inline in the output buffer.
233233
},
234234
output = {
235+
filetype = 'opencode_output', -- Filetype assigned to the output buffer (default: 'opencode_output')
235236
tools = {
236237
show_output = true, -- Show tools output [diffs, cmd output, etc.] (default: true)
237238
show_reasoning_output = true, -- Show reasoning/thinking steps output (default: true)

lua/opencode/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ M.defaults = {
137137
frames = { '', '', '', '', '', '', '', '', '', '' },
138138
},
139139
output = {
140+
filetype = 'opencode_output',
140141
rendering = {
141142
markdown_debounce_ms = 250,
142143
on_data_rendered = nil,

lua/opencode/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
---@field tools { show_output: boolean, show_reasoning_output: boolean }
179179
---@field rendering OpencodeUIOutputRenderingConfig
180180
---@field always_scroll_to_bottom boolean
181+
---@field filetype string
181182

182183
---@class OpencodeUIPickerConfig
183184
---@field snacks_layout? snacks.picker.layout.Config

lua/opencode/ui/output_window.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ M.namespace = vim.api.nvim_create_namespace('opencode_output')
66

77
function M.create_buf()
88
local output_buf = vim.api.nvim_create_buf(false, true)
9-
vim.api.nvim_set_option_value('filetype', 'opencode_output', { buf = output_buf })
9+
local filetype = config.ui.output.filetype or 'opencode_output'
10+
vim.api.nvim_set_option_value('filetype', filetype, { buf = output_buf })
1011

1112
local buffixwin = require('opencode.ui.buf_fix_win')
1213
buffixwin.fix_to_win(output_buf, function()

tests/unit/output_window_spec.lua

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
local config = require('opencode.config')
2+
local output_window = require('opencode.ui.output_window')
3+
4+
describe('output_window.create_buf', function()
5+
local original_config
6+
7+
before_each(function()
8+
original_config = vim.deepcopy(config.values)
9+
config.values = vim.deepcopy(config.defaults)
10+
end)
11+
12+
after_each(function()
13+
config.values = original_config
14+
end)
15+
16+
it('uses default output filetype', function()
17+
config.setup({})
18+
local buf = output_window.create_buf()
19+
20+
local filetype = vim.api.nvim_get_option_value('filetype', { buf = buf })
21+
assert.equals('opencode_output', filetype)
22+
23+
pcall(vim.api.nvim_buf_delete, buf, { force = true })
24+
end)
25+
26+
it('uses configured output filetype', function()
27+
config.setup({
28+
ui = {
29+
output = {
30+
filetype = 'markdown',
31+
},
32+
},
33+
})
34+
35+
local buf = output_window.create_buf()
36+
local filetype = vim.api.nvim_get_option_value('filetype', { buf = buf })
37+
38+
assert.equals('markdown', filetype)
39+
40+
pcall(vim.api.nvim_buf_delete, buf, { force = true })
41+
end)
42+
end)

0 commit comments

Comments
 (0)