mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 20:31:37 -05:00
Get write_to_file streaming working
This commit is contained in:
51
src/integrations/editor/DiffViewProvider.ts
Normal file
51
src/integrations/editor/DiffViewProvider.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import * as vscode from "vscode"
|
||||
import * as diff from "diff"
|
||||
|
||||
export class DiffViewProvider implements vscode.TextDocumentContentProvider {
|
||||
private _onDidChange = new vscode.EventEmitter<vscode.Uri>()
|
||||
onDidChange = this._onDidChange.event
|
||||
|
||||
private originalContent: string = ""
|
||||
private newContent: string = ""
|
||||
private fileName: string = ""
|
||||
|
||||
constructor() {
|
||||
// Register the provider
|
||||
vscode.workspace.registerTextDocumentContentProvider("claude-dev-diff", this)
|
||||
}
|
||||
|
||||
initialize(fileName: string, originalContent: string) {
|
||||
this.fileName = fileName
|
||||
this.originalContent = originalContent
|
||||
this.newContent = originalContent
|
||||
}
|
||||
|
||||
updateNewContent(updatedContent: string) {
|
||||
this.newContent = updatedContent
|
||||
this._onDidChange.fire(this.getDiffUri())
|
||||
}
|
||||
|
||||
provideTextDocumentContent(uri: vscode.Uri): string {
|
||||
return this.createDiffContent()
|
||||
}
|
||||
|
||||
private createDiffContent(): string {
|
||||
const diffResult = diff.createPatch(this.fileName, this.originalContent, this.newContent)
|
||||
return diffResult
|
||||
}
|
||||
|
||||
getDiffUri(): vscode.Uri {
|
||||
return vscode.Uri.parse(`claude-dev-diff:${this.fileName}`).with({
|
||||
query: Buffer.from(this.originalContent).toString("base64"),
|
||||
})
|
||||
}
|
||||
|
||||
async showDiff() {
|
||||
await vscode.commands.executeCommand(
|
||||
"vscode.diff",
|
||||
this.getDiffUri(),
|
||||
vscode.Uri.file(this.fileName),
|
||||
`${this.fileName}: Original ↔ Claude's Changes (Editable)`
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user