Skip to content

[FEATURE]: expose a plugin-safe file refresh hook for edits #26118

@Zireael

Description

@Zireael

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request 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

  1. Run a plugin that writes to a source file.
  2. Let it successfully modify the file.
  3. Check your editor state - diagnostics and file watchers are now completely out of sync with the disk.
  4. 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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions