Feature hasn't been suggested before.
Describe the enhancement you want to request
Description
Right now, when a plugin writes or edits files, there's no supported way to trigger the same post-edit refresh that Opencode's built-in tools handle.
The native read, edit, write, and apply_patch flows do more than just swap out text on disk. They also affect the LSP state and fire off file change events so diagnostics and symbol data stay fresh. Plugin tools don't get a public hook for this. If we build a custom tool that writes to a file, the editor state just sits there and gets stale after a successful write.
I wrote a custom plugin that shadows native tools, and noticed that automatic LSP diagnostics stopped working.
Environment
- Opencode version: latest, currently 1.14.33
- OS: All
- Context: Plugin tools running operations like write or apply_patch
- Observed in: Plugin tool execution paths
Steps to Reproduce
- Run a plugin that writes to a source file.
- Let it successfully modify the file.
- Check your editor state - diagnostics and file watchers are now completely out of sync with the disk.
- There is no way that I can see to force a state refresh without modifying Opencode's internal services.
Expected Behavior
When my plugin changes a file, it should be able to ping Opencode so it can update the LSP and file watchers, exactly like the native tools do.
Actual Behavior
We can write files just fine, but there's zero public API to:
- Broadcast a file edited/watcher updated event
- Tell the LSP to refresh the document after a mutation
- Replicate the native post-edit flow without using private APIs
Because of this, plugin implementations literally cannot match native tool parity.
- Diagnostics stay stuck in the past after a successful edit.
- Symbol navigation lags behind what's actually on disk.
Suggested Implementation
A small host-side API would fix this. Something simple like:
- notifyFileChanged(file, event)
- touchFile(file, diagnostics = "document")
Or even better, just expose a single helper method that handles the whole native post-mutation refresh sequence.
Feature hasn't been suggested before.
Describe the enhancement you want to request
Description
Right now, when a plugin writes or edits files, there's no supported way to trigger the same post-edit refresh that Opencode's built-in tools handle.
The native
read,edit,write, andapply_patchflows do more than just swap out text on disk. They also affect the LSP state and fire off file change events so diagnostics and symbol data stay fresh. Plugin tools don't get a public hook for this. If we build a custom tool that writes to a file, the editor state just sits there and gets stale after a successful write.I wrote a custom plugin that shadows native tools, and noticed that automatic LSP diagnostics stopped working.
Environment
Steps to Reproduce
Expected Behavior
When my plugin changes a file, it should be able to ping Opencode so it can update the LSP and file watchers, exactly like the native tools do.
Actual Behavior
We can write files just fine, but there's zero public API to:
Because of this, plugin implementations literally cannot match native tool parity.
Suggested Implementation
A small host-side API would fix this. Something simple like:
Or even better, just expose a single helper method that handles the whole native post-mutation refresh sequence.