Skip to content
Merged
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
Address review comments
  • Loading branch information
AlexandraBuzila committed Jun 6, 2025
commit 2069d0e073009340aa45180279a9d4a2a038d68b
21 changes: 8 additions & 13 deletions packages/ai-chat/src/browser/change-set-file-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ export class ChangeSetFileElement implements ChangeSetElement {
* This includes loading the original content from the file system.
*/
async ensureInitialized(): Promise<void> {
if (this._initializationPromise) {
await this._initializationPromise;
}
await this._initializationPromise;
}

/**
Expand All @@ -128,6 +126,10 @@ export class ChangeSetFileElement implements ChangeSetElement {
protected listenForOriginalFileChanges(): void {
this.toDispose.push(this.fileService.onDidFilesChange(async event => {
if (!event.contains(this.uri)) { return; }
if (!this._initialized && this._initializationPromise) {
// make sure we are initialized
await this._initializationPromise;
}
// If we are applied, the tricky thing becomes the question what to revert to; otherwise, what to apply.
const newContent = await this.changeSetFileService.read(this.uri).catch(() => '');
this.readOnlyResource.update({ contents: newContent });
Expand Down Expand Up @@ -156,8 +158,8 @@ export class ChangeSetFileElement implements ChangeSetElement {
this.toDispose.push(this._readOnlyResource);

// If not yet initialized, update the resource once initialization completes
if (!this._initialized && this._initializationPromise) {
this._initializationPromise.then(() => {
if (!this._initialized) {
this._initializationPromise?.then(() => {
this._readOnlyResource?.update({ contents: this._originalContent ?? '' });
});
}
Expand Down Expand Up @@ -271,14 +273,7 @@ export class ChangeSetFileElement implements ChangeSetElement {

onShow(): void {
// Ensure we have the latest state when showing
if (!this._initialized && this._initializationPromise) {
this._initializationPromise.then(() => {
// Update the change resource with the correct target state after initialization
this.changeResource.update({ contents: this.targetState, onSave: content => this.writeChanges(content) });
});
} else {
this.changeResource.update({ contents: this.targetState, onSave: content => this.writeChanges(content) });
}
this.changeResource.update({ contents: this.targetState, onSave: content => this.writeChanges(content) });
}

async revert(): Promise<void> {
Expand Down
Loading