-
-
Notifications
You must be signed in to change notification settings - Fork 100
Conversation
Summary
Add PR-style diff review UI for opencode changes.
This is my rough draft based on some discussion here. I'll be honest and that the session_diff.lua was mostly AI coded, but was verified and checked for accuracy.
Please pull it if you are interested, its been working well for me so far
Screenshots
Key Points
- SSE: Uses
message.updatedevent (contains only current cycle diffs, unlikesession.diffwhich
accumulates everything) for capturing thebefore, andafterfor only files touched in the current cycle. - Diff display:
- Simple
vim.diff()unified view - A more complex
pr reviewstyle enhanced diff view that works withhunk staging
- Simple
note: DiffView.nvim sadly does not really support what we want, since it only works with git rev not local temp files(we are not using git, we dont get much from DiffView.nvim other than the nice UI
Files
lua/opencode/diff.lua- Core review logicplugin/events/session_diff.lua- Event listenerDIFF_FEATURE.md- Full documentation
TODOs
- better abstraction/file organization
- better user command
- the ability to see the most recent diff
- slightly better-looking UI
- the ability to set keymaps
-
planmode should show diff but non-editable - What should happen to diff if files outside of current dir are modified
- Add toggle file panel keymap
- Delay the events until idle or that do it without setting focus?
- MORE testing~~~
Bugs
- The highlighting on the current file can be off in certain scenarios, treesitter problem. Incorrect timing, re-open fixes it
- Shows only new addition for my lua files, no idea why, this is because of symlink, This is a opencode problem.
Nice to have?
- any permission event dont automatically switch the focus back to nvim
| @@ -0,0 +1,14 @@ | |||
| -- Debug helper: Add this to your Neovim config temporarily to see ALL opencode events | |||
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.
note: ignore this file, only for debugging, will be removed
4684c3a to
1c8f8f0
Compare
I didn't test this super extensively, especially with new providers. lmk if you find a cause or fix along the way! |
3001781 to
cafdc6f
Compare
|
Hi, how is this going? |
|
@froats , still in testing mode, i havent had too much chance to work on this. Theres something wrong with opening the current version, treesitter sometimes is not correctly attached. Other than that and some QoL stuff, i have been using it without a problem. Although i dont really use the diff features(accept hunk/reject hunk)that often(hunk definition is not that accurate). Please give it a try if you are interested. It is 80% there. I also just attached a screenshot as well. |
|
Opencode actually stores snapshots (git commits in a shadow repo) per-message in |
thank you, didnt know about this. Will check it out tomorrow on MLK day. |
I made a PR #137! |
de5f1cc to
5de2380
Compare
Neovim can create separate buffers for the same file if accessed via different paths.
This causes issues with the diff view where the actual file might be loaded under
one path while the diff tries to open it under another.
This commit normalizes all file paths by resolving symlinks and converting to
absolute paths, ensuring consistent buffer identity.
opening it with :diffsplit reuses the buffer without triggering FileType events.
For users who rely on FileType autocmds to attach Treesitter (via vim.treesitter.start),
this causes the diff view to show the file without syntax highlighting.
This commit detects if the buffer is already loaded and forces a reload with :edit!
before opening in diffsplit. This ensures FileType events fire properly and Treesitter
attaches to the buffer.
Fixes intermittent "no grammar for filetype found" errors in diff view.
The previous approach of reloading the buffer before diffsplit was not effective
because the reload happened in the wrong context and didn't trigger FileType events
when the buffer was subsequently opened in diffsplit.
This commit takes a direct approach:
1. Open the file with diffsplit
2. Explicitly run :filetype detect to ensure filetype is set
3. Directly call vim.treesitter.start() to attach Treesitter highlighting
This ensures syntax highlighting works regardless of whether the buffer was
previously loaded or how FileType autocmds are configured.
Fixes the issue where right pane has no filetype and no Treesitter highlighting.
cafdc6f to
4a6c770
Compare
66f04d7 to
a4dff90
Compare