Skip to content

Commit dc1d61c

Browse files
committed
fix: load model info synchronously and use %= for winbar right-alignment
- Fall back to :wait(200) in get_model_info when :peek() returns nil so providers data is available on first render, enabling percentage - Replace manual space-padding winbar alignment with neovim's %= statusline directive for reliable right-alignment regardless of description character width
1 parent 8375a9d commit dc1d61c

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

lua/opencode/config_file.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ end
6969
--- @return OpencodeModel|nil Model information with variants
7070
M.get_model_info = function(provider, model)
7171
local providers_response = M.get_opencode_providers():peek()
72+
if not providers_response then
73+
local ok, result = pcall(function()
74+
return M.get_opencode_providers():wait(200)
75+
end)
76+
if ok then
77+
providers_response = result
78+
end
79+
end
7280

7381
local providers = providers_response and providers_response.providers or {}
7482

lua/opencode/ui/topbar.lua

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,8 @@ local function format_token_info()
4646
return result
4747
end
4848

49-
local function create_winbar_text(description, token_info, win_width)
50-
local left_content = ''
51-
local right_content = token_info
52-
53-
local desc_width = win_width - util.strdisplaywidth(left_content) - util.strdisplaywidth(right_content)
54-
55-
local desc_formatted
56-
if #description >= desc_width then
57-
local ellipsis = '... '
58-
desc_formatted = description:sub(1, desc_width - #ellipsis) .. ellipsis
59-
else
60-
desc_formatted = description .. string.rep(' ', math.floor(desc_width - #description))
61-
end
62-
63-
return left_content .. desc_formatted .. right_content
49+
local function create_winbar_text(description, token_info, _)
50+
return description .. '%=' .. token_info
6451
end
6552

6653
local function get_session_desc()

0 commit comments

Comments
 (0)