Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken authored Jun 18, 2024
1 parent 3b94c28 commit b631c0a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,101 +54,105 @@ export class ChatTextEditContentPart extends Disposable {
if (rendererOptions.renderTextEditsAsSummary?.(chatTextEdit.uri)) {
if (isResponseVM(element) && element.response.value.every(item => item.kind === 'textEditGroup')) {
this.element = $('.interactive-edits-summary', undefined, !element.isComplete ? localize('editsSummary1', "Making changes...") : localize('editsSummary', "Made changes."));
} else {
this.element = $('div');
}

// TODO@roblourens this case is now handled outside this Part in ChatListRenderer, but can it be cleaned up?
// return;
}
} else {

const cts = new CancellationTokenSource();

let isDisposed = false;
this._register(toDisposable(() => {
isDisposed = true;
cts.dispose(true);
}));
const cts = new CancellationTokenSource();

this.ref = this._register(diffEditorPool.get());
let isDisposed = false;
this._register(toDisposable(() => {
isDisposed = true;
cts.dispose(true);
}));

// Attach this after updating text/layout of the editor, so it should only be fired when the size updates later (horizontal scrollbar, wrapping)
// not during a renderElement OR a progressive render (when we will be firing this event anyway at the end of the render)
this._register(this.ref.object.onDidChangeContentHeight(() => {
this._onDidChangeHeight.fire();
}));
this.ref = this._register(diffEditorPool.get());

// Attach this after updating text/layout of the editor, so it should only be fired when the size updates later (horizontal scrollbar, wrapping)
// not during a renderElement OR a progressive render (when we will be firing this event anyway at the end of the render)
this._register(this.ref.object.onDidChangeContentHeight(() => {
this._onDidChangeHeight.fire();
}));

const data: ICodeCompareBlockData = {
element,
edit: chatTextEdit,
diffData: (async () => {
const data: ICodeCompareBlockData = {
element,
edit: chatTextEdit,
diffData: (async () => {

const ref = await this.textModelService.createModelReference(chatTextEdit.uri);
const ref = await this.textModelService.createModelReference(chatTextEdit.uri);

if (isDisposed) {
ref.dispose();
return;
}
if (isDisposed) {
ref.dispose();
return;
}

this._register(ref);
this._register(ref);

const original = ref.object.textEditorModel;
let originalSha1: string = '';
const original = ref.object.textEditorModel;
let originalSha1: string = '';

if (chatTextEdit.state) {
originalSha1 = chatTextEdit.state.sha1;
} else {
const sha1 = new DefaultModelSHA1Computer();
if (sha1.canComputeSHA1(original)) {
originalSha1 = sha1.computeSHA1(original);
chatTextEdit.state = { sha1: originalSha1, applied: 0 };
}
}

const modified = this.modelService.createModel(
createTextBufferFactoryFromSnapshot(original.createSnapshot()),
{ languageId: original.getLanguageId(), onDidChange: Event.None },
URI.from({ scheme: Schemas.vscodeChatCodeBlock, path: original.uri.path, query: generateUuid() }),
false
);
const modRef = await this.textModelService.createModelReference(modified.uri);
this._register(modRef);

const editGroups: ISingleEditOperation[][] = [];
if (isResponseVM(element)) {
const chatModel = this.chatService.getSession(element.sessionId)!;

for (const request of chatModel.getRequests()) {
if (!request.response) {
continue;
if (chatTextEdit.state) {
originalSha1 = chatTextEdit.state.sha1;
} else {
const sha1 = new DefaultModelSHA1Computer();
if (sha1.canComputeSHA1(original)) {
originalSha1 = sha1.computeSHA1(original);
chatTextEdit.state = { sha1: originalSha1, applied: 0 };
}
for (const item of request.response.response.value) {
if (item.kind !== 'textEditGroup' || item.state?.applied || !isEqual(item.uri, chatTextEdit.uri)) {
}

const modified = this.modelService.createModel(
createTextBufferFactoryFromSnapshot(original.createSnapshot()),
{ languageId: original.getLanguageId(), onDidChange: Event.None },
URI.from({ scheme: Schemas.vscodeChatCodeBlock, path: original.uri.path, query: generateUuid() }),
false
);
const modRef = await this.textModelService.createModelReference(modified.uri);
this._register(modRef);

const editGroups: ISingleEditOperation[][] = [];
if (isResponseVM(element)) {
const chatModel = this.chatService.getSession(element.sessionId)!;

for (const request of chatModel.getRequests()) {
if (!request.response) {
continue;
}
for (const group of item.edits) {
const edits = group.map(TextEdit.asEditOperation);
editGroups.push(edits);
for (const item of request.response.response.value) {
if (item.kind !== 'textEditGroup' || item.state?.applied || !isEqual(item.uri, chatTextEdit.uri)) {
continue;
}
for (const group of item.edits) {
const edits = group.map(TextEdit.asEditOperation);
editGroups.push(edits);
}
}
if (request.response === element.model) {
break;
}
}
if (request.response === element.model) {
break;
}
}
}

for (const edits of editGroups) {
modified.pushEditOperations(null, edits, () => null);
}

return {
modified,
original,
originalSha1
} satisfies ICodeCompareBlockDiffData;
})()
};
this.ref.object.render(data, currentWidth, cts.token);

this.element = this.ref.object.element;
for (const edits of editGroups) {
modified.pushEditOperations(null, edits, () => null);
}

return {
modified,
original,
originalSha1
} satisfies ICodeCompareBlockDiffData;
})()
};
this.ref.object.render(data, currentWidth, cts.token);

this.element = this.ref.object.element;
}
}

layout(width: number): void {
Expand Down
3 changes: 0 additions & 3 deletions src/vs/workbench/contrib/chat/browser/chatListRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,9 +935,6 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
}

private renderTextEdit(element: ChatTreeItem, chatTextEdit: IChatTextEditGroup, templateData: IChatListItemTemplate): IMarkdownRenderResult | undefined {
if (this.rendererOptions.renderTextEditsAsSummary?.(chatTextEdit.uri) && !(isResponseVM(element) && element.response.value.every(item => item.kind === 'textEditGroup'))) {
return;
}

const store = new DisposableStore();
const textEditPart = store.add(this.instantiationService.createInstance(ChatTextEditContentPart, chatTextEdit, element, this.rendererOptions, this._diffEditorPool, this._currentLayoutWidth));
Expand Down

0 comments on commit b631c0a

Please sign in to comment.