-
Notifications
You must be signed in to change notification settings - Fork 28
feat(context): context bar #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Ooh, I'm looking forward to this! |
|
Yes I have some small issues after the rebase. But it's coming together. |
502a4c1 to
ab1e7fd
Compare
|
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 :) |
|
Yes, I'm very excited for this feature! will test and review today. |
|
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A really nice feature and will be great when it goes out!
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emmylua_ls suggests a nil check on col (and maybe this is a slightly cleaner way to get col):
local col = vim.api.nvim_win_get_cursor(0)[2]
if not col then
return
end| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could consider not setting up these autocmds if context is disabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| -- context | ||
| last_sent_context = nil, | ||
| current_context_config = {}, | ||
| context_updated_at = nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only see context_updated_at written to. Is it actually used/needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
dda859d to
7121f13
Compare
|
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? |
|
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? |
|
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. |
|
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. |
With the bar aligned to the right there is no need for the icon anymore






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