feat(context): context bar - #69
Conversation
cameronr
commented
Oct 27, 2025
Ooh, I'm looking forward to this! |
sudo-tee
commented
Oct 27, 2025
Yes I have some small issues after the rebase. But it's coming together. |
502a4c1 to
ab1e7fdComparesudo-tee
commented
Oct 30, 2025
Whenever you have time you can have a look ? You can review the code if you like and also tell me if the feature works for you. I think it's going to be a nice feature but I might be biased :) |
cameronr
commented
Oct 30, 2025
Yes, I'm very excited for this feature! will test and review today. |
sudo-tee
commented
Oct 30, 2025
Thanks for the great feedback. You are right about the padding. I added it for looks because it looked weird with the winbar ( mostly my frontend dev background though it looked better 😅). I like the suggestion to align it to the right. I will see what I can do about it. I also saw some quirky behaviour with the padded line. I will remove it and see if it feels better. Don't hesitate if you have other ideas to improve it. Thanks for your review. |
cameronr
left a comment
There was a problem hiding this comment.
A really nice feature and will be great when it goes out!
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| local _, col = unpack(vim.api.nvim_win_get_cursor(0)) | ||
| local line = vim.api.nvim_get_current_line() | ||
| local key = config.get_key_for_function('input_window', 'context_items') | ||
| local completion_text = key .. (item.label or item.insert_text or '') | ||
| local text_start = col - #completion_text | ||
| if text_start >= 0 and line:sub(text_start + 1, col) == completion_text then | ||
| line = line:sub(1, text_start) .. line:sub(col + 1) | ||
| input_win.set_current_line(line) | ||
| vim.api.nvim_win_set_cursor(0, { vim.api.nvim_win_get_cursor(0)[1], text_start }) | ||
| elseif col > 0 and line:sub(col, col) == key then | ||
| line = line:sub(1, col - 1) .. line:sub(col + 1) | ||
| input_win.set_current_line(line) | ||
| end |
There was a problem hiding this comment.
emmylua_ls suggests a nil check on col (and maybe this is a slightly cleaner way to get col):
localcol=vim.api.nvim_win_get_cursor(0)[2]
ifnotcolthenreturnendUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| vim.api.nvim_create_autocmd('BufWritePost', { | ||
| pattern = '*', | ||
| callback = function(args) | ||
| local buf = args.buf | ||
| local curr_buf = state.current_code_buf or vim.api.nvim_get_current_buf() | ||
| if buf == curr_buf and util.is_buf_a_file(buf) then | ||
| M.load() | ||
| end | ||
| end, | ||
| }) | ||
| vim.api.nvim_create_autocmd('DiagnosticChanged', { | ||
| pattern = '*', | ||
| callback = function(args) | ||
| local buf = args.buf | ||
| local curr_buf = state.current_code_buf or vim.api.nvim_get_current_buf() | ||
| if buf == curr_buf and util.is_buf_a_file(buf) and M.is_context_enabled('diagnostics') then | ||
| M.load() | ||
| end | ||
| end, | ||
| }) |
There was a problem hiding this comment.
could consider not setting up these autocmds if context is disabled?
There was a problem hiding this comment.
I see your point, but if you toggle it later with something like
Opencode run context=enabled=true hello there
you might end up with some stale context.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| -- context | ||
| last_sent_context = nil, | ||
| current_context_config = {}, | ||
| context_updated_at = nil, |
There was a problem hiding this comment.
I only see context_updated_at written to. Is it actually used/needed?
There was a problem hiding this comment.
The context_bar is listening to it
This related to the reactive_state file. I wanted to wrap the context to be able to subscribe to individual fields, but it ended up more complex than just having a timestamp. It's a bit of an anti-pattern but LuaJit does not support ipairs in memtables so we cannot loop over indexed arrays when wrapped in memtables.
Maybe I will find a better pattern later, but this one works for now and is simple enough
Uh oh!
There was an error while loading. Please reload this page.
dda859d to
7121f13Comparesudo-tee
commented
Oct 31, 2025
I did align the bar to the right and removed padding, It was a really great suggestion. It seems to work really well. I didn't encounter cursor jumps. Let me know what you think. There is still a couple of stuff I want to add like un the user message show that diagnostics have been shared like with section and now cursor data, a part from that I'm almost done |
I took a quick look and it looks great! My only other thought was if we should move the guard icon to be left aligned in the context bar? I think that would make more sense and probably look good? |
cameronr
commented
Oct 31, 2025
Actually, now that I think about it, I wonder if the agent mode should be there too? It's not as clear (input guard is clearly input related) where as agent mode is more output related. That said, making sure the mode is set correctly before submitting is important and reducing the visual distance to verify that could be an improvement. Maybe it's worth at least looking at? |
sudo-tee
commented
Oct 31, 2025
Those are great suggestions. Current Model is also something related to input, but this could make the bar a little to crowded I will play around with that idea. |
sudo-tee
commented
Oct 31, 2025
Yeah, mode may be a stretch. My last idea is trying mode on the left rather than the right. My thinking is that from left to right it's conceptually:
but it's possible that mode on the left just won't look good :) if it doesn't look good, we can leave it up in the output_window winbar for now. |
sudo-tee
commented
Nov 1, 2025
With the bar aligned to the right there is no need for the icon anymore
Uh oh!
There was an error while loading. Please reload this page.






This PR is adding a context bar to manage/view context being sent by the plugin