Skip to content

Commit

Permalink
Improve incremental document update (#4277)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkukielka committed May 23, 2024
1 parent 6a8964e commit 8ced089
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 5 additions & 1 deletion agent/src/AgentWorkspaceDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class AgentWorkspaceDocuments implements vscode_shim.WorkspaceDocuments {
const changes = applyContentChanges(fromCache, document.contentChanges)
contentChanges.push(...changes.contentChanges)
document.underlying.content = changes.newText
} else if (document.content !== undefined) {
} else if (document.content !== undefined && document.content != null) {
for (const change of calculateContentChanges(fromCache, document.content)) {
contentChanges.push(change)
}
Expand All @@ -67,6 +67,10 @@ export class AgentWorkspaceDocuments implements vscode_shim.WorkspaceDocuments {
document.underlying.selection = fromCache.protocolDocument.selection
}

if (document.visibleRange === undefined) {
document.underlying.visibleRange = fromCache.protocolDocument.visibleRange
}

fromCache.update(document)

return { document: fromCache, contentChanges }
Expand Down
13 changes: 8 additions & 5 deletions agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,14 @@ export class Agent extends MessageHandler implements ExtensionClient {
this.workspace.loadDocumentWithChanges(documentWithUri)
const textEditor = this.workspace.newTextEditor(textDocument)
this.workspace.setActiveTextEditor(textEditor)
vscode_shim.onDidChangeTextDocument.fire({
document: textDocument,
contentChanges,
reason: undefined,
})

if (contentChanges) {
vscode_shim.onDidChangeTextDocument.fire({
document: textDocument,
contentChanges,
reason: undefined,
})
}

if (document.selection) {
vscode_shim.onDidChangeTextEditorSelection.fire({
Expand Down

0 comments on commit 8ced089

Please sign in to comment.