MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / update

Method update

src/integrations/editor/DiffViewProvider.ts:249–324  ·  view source on GitHub ↗
(accumulatedContent: string, isFinal: boolean)

Source from the content-addressed store, hash-verified

247 }
248
249 async update(accumulatedContent: string, isFinal: boolean) {
250 if (!this.relPath || !this.activeLineController || !this.fadedOverlayController) {
251 throw new Error("Required values not set")
252 }
253
254 this.newContent = accumulatedContent
255 const accumulatedLines = accumulatedContent.split("\n")
256
257 if (!isFinal) {
258 accumulatedLines.pop() // Remove the last partial line only if it's not the final update.
259 }
260
261 const diffEditor = this.activeDiffEditor
262 const document = diffEditor?.document
263
264 if (!diffEditor || !document) {
265 throw new Error("User closed text editor, unable to edit file...")
266 }
267
268 // Place cursor at the beginning of the diff editor to keep it out of
269 // the way of the stream animation, but do this without stealing focus
270 const beginningOfDocument = new vscode.Position(0, 0)
271 diffEditor.selection = new vscode.Selection(beginningOfDocument, beginningOfDocument)
272
273 const endLine = accumulatedLines.length
274 // Replace all content up to the current line with accumulated lines.
275 const edit = new vscode.WorkspaceEdit()
276 const rangeToReplace = new vscode.Range(0, 0, endLine, 0)
277 const contentToReplace =
278 accumulatedLines.slice(0, endLine).join("\n") + (accumulatedLines.length > 0 ? "\n" : "")
279 edit.replace(document.uri, rangeToReplace, this.stripAllBOMs(contentToReplace))
280 await vscode.workspace.applyEdit(edit)
281 // Update decorations.
282 this.activeLineController.setActiveLine(endLine)
283 this.fadedOverlayController.updateOverlayAfterLine(endLine, document.lineCount)
284 // Scroll to the current line without stealing focus.
285 const ranges = this.activeDiffEditor?.visibleRanges
286 if (ranges && ranges.length > 0 && ranges[0].start.line < endLine && ranges[0].end.line > endLine) {
287 this.scrollEditorToLine(endLine)
288 }
289
290 // Update the streamedLines with the new accumulated content.
291 this.streamedLines = accumulatedLines
292
293 if (isFinal) {
294 // Handle any remaining lines if the new content is shorter than the
295 // original.
296 if (this.streamedLines.length < document.lineCount) {
297 const edit = new vscode.WorkspaceEdit()
298 edit.delete(document.uri, new vscode.Range(this.streamedLines.length, 0, document.lineCount, 0))
299 await vscode.workspace.applyEdit(edit)
300 }
301
302 // Preserve empty last line if original content had one.
303 const hasEmptyLastLine = this.originalContent?.endsWith("\n")
304
305 if (hasEmptyLastLine && !accumulatedContent.endsWith("\n")) {
306 accumulatedContent += "\n"

Callers

nothing calls this directly

Calls 9

replaceMethod · 0.95
stripAllBOMsMethod · 0.95
scrollEditorToLineMethod · 0.95
deleteMethod · 0.95
popMethod · 0.80
applyEditMethod · 0.80
setActiveLineMethod · 0.80
clearMethod · 0.65

Tested by

no test coverage detected