Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lua/opencode/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ function M.focus_input()
end

function M.debug_output()
local config = require('opencode.config').get()
local config = require('opencode.config')
if not config.debug.enabled then
vim.notify('Debugging is not enabled in the config', vim.log.levels.WARN)
return
Expand All @@ -310,7 +310,7 @@ function M.debug_output()
end

function M.debug_message()
local config = require('opencode.config').get()
local config = require('opencode.config')
if not config.debug.enabled then
vim.notify('Debugging is not enabled in the config', vim.log.levels.WARN)
return
Expand All @@ -320,7 +320,7 @@ function M.debug_message()
end

function M.debug_session()
local config = require('opencode.config').get()
local config = require('opencode.config')
if not config.debug.enabled then
vim.notify('Debugging is not enabled in the config', vim.log.levels.WARN)
return
Expand Down
26 changes: 15 additions & 11 deletions lua/opencode/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -221,26 +221,19 @@ function M.setup(opts)
end
end

-- vim.notify(vim.inspect(opts))
M.values = vim.tbl_deep_extend('force', M.values, opts --[[@as OpencodeConfig]])
-- vim.notify(vim.inspect(M.values))

update_keymap_prefix(M.values.keymap_prefix, M.defaults.keymap_prefix)
end

function M.get(key)
if key then
return M.values[key]
end
return M.values
end

--- Get the key binding for a specific function in a scope
--- @param scope 'editor'|'input_window'|'output_window'
--- @param function_name string
--- @return string|nil
function M.get_key_for_function(scope, function_name)
local config_data = M.get()

local keymap_config = config_data.keymap and config_data.keymap[scope]
local keymap_config = M.values.keymap and M.values.keymap[scope]
if not keymap_config then
return nil
end
Expand Down Expand Up @@ -278,4 +271,15 @@ function M.normalize_keymap(legacy_config, filter_functions)
return converted
end

return M
---@export Config
return setmetatable(M, {
__index = function(_, key)
return M.values[key]
end,
__newindex = function(_, key, value)
M.values[key] = value
end,
__tostring = function(_)
return vim.inspect(M.values)
end,
})
2 changes: 1 addition & 1 deletion lua/opencode/context.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Gathers editor context

local util = require('opencode.util')
local config = require('opencode.config').get()
local config = require('opencode.config')
local state = require('opencode.state')

local M = {}
Expand Down
2 changes: 1 addition & 1 deletion lua/opencode/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local server_job = require('opencode.server_job')
local input_window = require('opencode.ui.input_window')
local util = require('opencode.util')
local Promise = require('opencode.promise')
local config = require('opencode.config').get()
local config = require('opencode.config')

---@param parent_id string?
function M.select_session(parent_id)
Expand Down
20 changes: 9 additions & 11 deletions lua/opencode/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,34 +111,32 @@ local function check_configuration()
return
end

local values = config.get()

local valid_positions = { 'left', 'right', 'top', 'bottom' }
if not vim.tbl_contains(valid_positions, values.ui.position) then
if not vim.tbl_contains(valid_positions, config.ui.position) then
health.warn(
string.format('Invalid UI position: %s', values.ui.position),
string.format('Invalid UI position: %s', config.ui.position),
{ 'Valid positions: ' .. table.concat(valid_positions, ', ') }
)
else
health.ok(string.format('UI position: %s', values.ui.position))
health.ok(string.format('UI position: %s', config.ui.position))
end

if values.ui.window_width <= 0 or values.ui.window_width > 1 then
if config.ui.window_width <= 0 or config.ui.window_width > 1 then
health.warn(
string.format('Invalid window width: %s', values.ui.window_width),
string.format('Invalid window width: %s', config.ui.window_width),
{ 'Window width should be between 0 and 1 (percentage of screen)' }
)
else
health.ok(string.format('Window width: %s', values.ui.window_width))
health.ok(string.format('Window width: %s', config.ui.window_width))
end

if values.ui.input_height <= 0 or values.ui.input_height > 1 then
if config.ui.input_height <= 0 or config.ui.input_height > 1 then
health.warn(
string.format('Invalid input height: %s', values.ui.input_height),
string.format('Invalid input height: %s', config.ui.input_height),
{ 'Input height should be between 0 and 1 (percentage of screen)' }
)
else
health.ok(string.format('Input height: %s', values.ui.input_height))
health.ok(string.format('Input height: %s', config.ui.input_height))
end

health.ok('Configuration loaded successfully')
Expand Down
2 changes: 1 addition & 1 deletion lua/opencode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function M.setup(opts)
require('opencode.core').setup()
config.setup(opts)
api.setup()
keymap.setup(config.get('keymap'))
keymap.setup(config.keymap)

require('opencode.ui.completion').setup()
require('opencode.event_manager').setup()
Expand Down
2 changes: 1 addition & 1 deletion lua/opencode/keymap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function M.toggle_permission_keymap(buf)
local config = require('opencode.config')
local api = require('opencode.api')

local permission_config = config.get().keymap.permission
local permission_config = config.keymap.permission
if not permission_config then
return
end
Expand Down
2 changes: 1 addition & 1 deletion lua/opencode/state.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local config = require('opencode.config').get()
local config = require('opencode.config')

---@class OpencodeWindowState
---@field input_win number|nil
Expand Down
1 change: 0 additions & 1 deletion lua/opencode/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
---@field defaults OpencodeConfig
---@field values OpencodeConfig
---@field setup fun(opts?: OpencodeConfig): nil
---@field get fun(key?: string): any
---@field get_key_for_function fun(scope: 'editor'|'input_window'|'output_window', function_name: string): string|nil
---@field normalize_keymap fun(legacy_config: table, filter_functions?: table): table

Expand Down
2 changes: 1 addition & 1 deletion lua/opencode/ui/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function M.on_complete(item)
end

function M.get_completion_engine()
local config = require('opencode.config').get()
local config = require('opencode.config')
local engine = config.preferred_completion
if not engine then
local ok_cmp = pcall(require, 'cmp')
Expand Down
2 changes: 1 addition & 1 deletion lua/opencode/ui/completion/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local command_source = {
name = 'commands',
priority = 1,
complete = function(context)
local config = require('opencode.config').get()
local config = require('opencode.config')
local input_text = vim.api.nvim_buf_get_lines(0, 0, -1, false)

if not context.line:match('^' .. vim.pesc(context.trigger_char) .. '[^%s/]*$') then
Expand Down
2 changes: 1 addition & 1 deletion lua/opencode/ui/completion/files.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local config = require('opencode.config').get()
local config = require('opencode.config')
local M = {}

local last_successful_tool = nil
Expand Down
2 changes: 1 addition & 1 deletion lua/opencode/ui/completion/subagents.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local subagent_source = {
name = 'subagents',
complete = function(context)
local subagents = require('opencode.config_file').get_subagents()
local config = require('opencode.config').get()
local config = require('opencode.config')
local config_mod = require('opencode.config')
local expected_trigger = config_mod.get_key_for_function('input_window', 'mention')
if context.trigger_char ~= expected_trigger then
Expand Down
2 changes: 1 addition & 1 deletion lua/opencode/ui/file_picker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local M = {}
local function get_best_picker()
local config = require('opencode.config')

local preferred_picker = config.get('preferred_picker')
local preferred_picker = config.preferred_picker
if preferred_picker and preferred_picker ~= '' then
return preferred_picker
end
Expand Down
2 changes: 1 addition & 1 deletion lua/opencode/ui/footer.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local state = require('opencode.state')
local config = require('opencode.config').get()
local config = require('opencode.config')
local util = require('opencode.util')
local icons = require('opencode.ui.icons')
local output_window = require('opencode.ui.output_window')
Expand Down
2 changes: 1 addition & 1 deletion lua/opencode/ui/icons.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Centralized icon utility with presets and overrides
local config = require('opencode.config').get()
local config = require('opencode.config')

local M = {}

Expand Down
14 changes: 5 additions & 9 deletions lua/opencode/ui/input_window.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local state = require('opencode.state')
local config = require('opencode.config').get()
local config = require('opencode.config')
local M = {}

function M.create_buf()
Expand Down Expand Up @@ -131,10 +131,9 @@ function M.refresh_placeholder(windows, input_lines)
local ns_id = vim.api.nvim_create_namespace('input_placeholder')
local win_width = vim.api.nvim_win_get_width(windows.input_win)
local padding = string.rep(' ', win_width)
local config_mod = require('opencode.config')
local slash_key = config_mod.get_key_for_function('input_window', 'slash_commands')
local mention_key = config_mod.get_key_for_function('input_window', 'mention')
local mention_file_key = config_mod.get_key_for_function('input_window', 'mention_file')
local slash_key = config.get_key_for_function('input_window', 'slash_commands')
local mention_key = config.get_key_for_function('input_window', 'mention')
local mention_file_key = config.get_key_for_function('input_window', 'mention_file')

vim.api.nvim_buf_set_extmark(windows.input_buf, ns_id, 0, 0, {
virt_text = {
Expand Down Expand Up @@ -200,10 +199,7 @@ end

function M.setup_keymaps(windows)
local keymap = require('opencode.keymap')
local config_mod = require('opencode.config')
local input_keymaps = config_mod.get('keymap').input_window

keymap.setup_window_keymaps(input_keymaps, windows.input_buf)
keymap.setup_window_keymaps(config.keymap.input_window, windows.input_buf)
end

function M.setup_autocmds(windows, group)
Expand Down
2 changes: 1 addition & 1 deletion lua/opencode/ui/loading_animation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function M._get_frames()
if M._animation.frames then
return M._animation.frames
end
local ui_config = config.get('ui')
local ui_config = config.ui
if ui_config and ui_config.loading_animation and ui_config.loading_animation.frames then
return ui_config.loading_animation.frames
end
Expand Down
2 changes: 1 addition & 1 deletion lua/opencode/ui/output.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local state = require('opencode.state')
local config = require('opencode.config').get()
local config = require('opencode.config')
local Output = {}
Output.__index = Output

Expand Down
7 changes: 2 additions & 5 deletions lua/opencode/ui/output_window.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local state = require('opencode.state')
local config = require('opencode.config').get()
local config = require('opencode.config')

local M = {}

Expand Down Expand Up @@ -113,10 +113,7 @@ end

function M.setup_keymaps(windows)
local keymap = require('opencode.keymap')
local config_mod = require('opencode.config')
local output_keymaps = config_mod.get('keymap').output_window

keymap.setup_window_keymaps(output_keymaps, windows.output_buf)
keymap.setup_window_keymaps(config.keymap.output_window, windows.output_buf)
end

function M.setup_autocmds(windows, group)
Expand Down
2 changes: 1 addition & 1 deletion lua/opencode/ui/session_formatter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local icons = require('opencode.ui.icons')
local util = require('opencode.util')
local Output = require('opencode.ui.output')
local state = require('opencode.state')
local config = require('opencode.config').get()
local config = require('opencode.config')
local snapshot = require('opencode.snapshot')

local M = {
Expand Down
2 changes: 1 addition & 1 deletion lua/opencode/ui/topbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local function format_model_info()
state.current_model = info and info.model
end

local config = require('opencode.config').get()
local config = require('opencode.config')
local parts = {}

if config.ui.display_model and state.current_model then
Expand Down
4 changes: 2 additions & 2 deletions lua/opencode/ui/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function M.create_split_windows(input_buf, output_buf)
if state.windows then
M.close_windows(state.windows)
end
local ui_conf = config.get('ui')
local ui_conf = config.ui

local main_win = open_split(ui_conf.position, 'vertical')
vim.api.nvim_set_current_win(main_win)
Expand Down Expand Up @@ -240,7 +240,7 @@ function M.toggle_pane()
end

function M.swap_position()
local ui_conf = config.get('ui')
local ui_conf = config.ui
local new_pos = (ui_conf.position == 'left') and 'right' or 'left'
config.values.ui.position = new_pos

Expand Down
2 changes: 1 addition & 1 deletion tests/minimal/plugin_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ describe('opencode.nvim plugin', function()
})

local config = require('opencode.config')
assert.equal('<leader>test', config.get('keymap').prompt)
assert.equal('<leader>test', config.keymap.prompt)
end)
end)