Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(opencode): restore readText after format and await LSP.touchFile
- edit.ts: restore Filesystem.readText after Format.file() so the stored
  contentNew reflects the formatter's output, not the pre-format content.
  Removing this was incorrect — the original intent was to capture the
  final on-disk state for accurate diff/snapshot tracking.

- edit.ts, write.ts: restore await on LSP.touchFile so diagnostics are
  fetched after the LSP has processed the file change, not before.
  • Loading branch information
FindTea committed Apr 1, 2026
commit 469362a38007b63df59ba774626fc9970382ad1f
7 changes: 2 additions & 5 deletions packages/opencode/src/tool/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ export const EditTool = Tool.define("edit", {
file: filePath,
event: "change",
})
// Use the in-memory contentNew for diff computation instead of re-reading the file.
// Re-reading the file after Format.file() can be done lazily if the formatted
// content is needed; for the diff we already have both sides in memory.
contentNew = await Filesystem.readText(filePath)
await FileTime.read(ctx.sessionID, filePath)
})

Expand Down Expand Up @@ -165,8 +163,7 @@ export const EditTool = Tool.define("edit", {
})

let output = "Edit applied successfully."
// Notify LSP asynchronously so it does not block the edit response.
LSP.touchFile(filePath, true).catch(() => {})
await LSP.touchFile(filePath, true)
const diagnostics = await LSP.diagnostics()
const normalizedFilePath = Filesystem.normalizePath(filePath)
const issues = diagnostics[normalizedFilePath] ?? []
Expand Down
3 changes: 1 addition & 2 deletions packages/opencode/src/tool/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ export const WriteTool = Tool.define("write", {
await FileTime.read(ctx.sessionID, filepath)

let output = "Wrote file successfully."
// Notify LSP asynchronously so it does not block the write response.
LSP.touchFile(filepath, true).catch(() => {})
await LSP.touchFile(filepath, true)
const diagnostics = await LSP.diagnostics()
const normalizedFilepath = Filesystem.normalizePath(filepath)
let projectDiagnosticsCount = 0
Expand Down
Loading