Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix https://github.com/microsoft/vscode-copilot/issues/6236 #216367

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading