Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"fetch-h2": "^3.0.2",
"json5": "^2.2.3",
"marked": "^4.0.8",
"refact-chat-js": "~v2.0.6-alpha.1",
"refact-chat-js": "~v2.0.8-alpha.2",
"uuid": "^9.0.1",
"vscode-languageclient": "^7.0.0"
},
Expand Down
85 changes: 21 additions & 64 deletions src/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ import {
ideNewFileAction,
ideOpenSettingsAction,
ideDiffPasteBackAction,
ideDiffPreviewAction,
type ChatThread,
type DiffPreviewResponse,
resetDiffApi,
ideAnimateFileStart,
ideAnimateFileStop,
ideWriteResultsToFile,
type PatchResult,
ideChatPageChange,
ideEscapeKeyPressed,
ideIsChatStreaming,
setCurrentProjectInfo
setCurrentProjectInfo,
ideToolEdit,
ToolEditResult,
} from "refact-chat-js/dist/events";
import { basename, join } from "path";
import { diff_paste_back } from "./chatTab";
Expand Down Expand Up @@ -69,6 +66,9 @@ export async function open_chat_tab(
{role: "user", content: question},
] : [],
model: model,
new_chat_suggested: {
wasSuggested: false,
}
};
global.side_panel.goto_chat(chat); // changes html

Expand Down Expand Up @@ -267,10 +267,7 @@ export class PanelWebview implements vscode.WebviewViewProvider {
this._view?.webview.postMessage(message);
}

sendClearDiffCacheMessage() {
const message = resetDiffApi();
this._view?.webview.postMessage(message);
}



public new_statistic(view: vscode.WebviewView)
Expand Down Expand Up @@ -545,9 +542,6 @@ export class PanelWebview implements vscode.WebviewViewProvider {
return this.handleDiffPasteBack(e.payload);
}

if (ideDiffPreviewAction.match(e)) {
return this.handleDiffPreview(e.payload);
}

if(ideAnimateFileStart.match(e)) {
return this.startFileAnimation(e.payload);
Expand All @@ -557,10 +551,6 @@ export class PanelWebview implements vscode.WebviewViewProvider {
return this.stopFileAnimation(e.payload);
}

if(ideWriteResultsToFile.match(e)) {
return this.writeResultsToFile(e.payload);
}

if(ideChatPageChange.match(e)) {
return this.handleCurrentChatPage(e.payload);
}
Expand All @@ -573,6 +563,9 @@ export class PanelWebview implements vscode.WebviewViewProvider {
return this.handleEscapePressed(e.payload);
}

if(ideToolEdit.match(e)) {
return this.handleToolEdit(e.payload.path, e.payload.edit);
}
// if(ideOpenChatInNewTab.match(e)) {
// return this.handleOpenInTab(e.payload);
// }
Expand Down Expand Up @@ -605,6 +598,16 @@ export class PanelWebview implements vscode.WebviewViewProvider {

// }

async handleToolEdit(path: string, toolEdit: ToolEditResult) {
if(!toolEdit.file_before && toolEdit.file_after) {
return this.createNewFileWithContent(path, toolEdit.file_after);
}

return this.addDiffToFile(path, toolEdit.file_after);
}


// This isn't called
async deleteFile(fileName: string) {
const uri = this.filePathToUri(fileName);
const edit = new vscode.WorkspaceEdit();
Expand All @@ -625,7 +628,6 @@ export class PanelWebview implements vscode.WebviewViewProvider {
return vscode.workspace.applyEdit(edit).then(success => {
if (success) {
vscode.window.showTextDocument(document);
this.refetchDiffsOnSave(document);
} else {
vscode.window.showInformationMessage('Error: creating file ' + fileName);
}
Expand All @@ -648,10 +650,9 @@ export class PanelWebview implements vscode.WebviewViewProvider {
range,
content
);
// TODO: can remove this when diff api is removed.
this.refetchDiffsOnSave(document);
}

// this isn't called
async editFileWithContent(fileName: string, content: string) {
const uri = this.filePathToUri(fileName);
const document = await vscode.workspace.openTextDocument(uri);
Expand All @@ -673,17 +674,6 @@ export class PanelWebview implements vscode.WebviewViewProvider {
}


async writeResultsToFile(results: PatchResult[]) {
for(const result of results) {
if(result.file_name_add) {
this.createNewFileWithContent(result.file_name_add, result.file_text);
} else if(result.file_name_edit) {
this.editFileWithContent(result.file_name_edit, result.file_text);
} else if (result.file_name_delete) {
this.deleteFile(result.file_name_delete);
}
}
}

async handleCurrentChatPage(page: string) {
this.context.globalState.update("chat_page", JSON.stringify(page));
Expand Down Expand Up @@ -795,39 +785,6 @@ export class PanelWebview implements vscode.WebviewViewProvider {

}

private refetchDiffsOnSave(document: vscode.TextDocument) {
const disposables: vscode.Disposable[] = [];
const dispose = () => disposables.forEach(d => d.dispose());
disposables.push(vscode.workspace.onDidSaveTextDocument((savedDocument) => {
if(savedDocument.uri.fsPath === document.uri.fsPath) {
this.sendClearDiffCacheMessage();
dispose();
}
}));
disposables.push(vscode.workspace.onDidCloseTextDocument((closedDocument) => {
if(closedDocument.uri.fsPath === document.uri.fsPath) {
dispose();
}
}));
}

private async handleDiffPreview(response: DiffPreviewResponse) {

const openFiles = this.getOpenFiles();

for (const change of response.results) {
if (change.file_name_edit !== null && change.file_text !== null) {
this.addDiffToFile(change.file_name_edit, change.file_text);
} else if(change.file_name_add !== null && change.file_text!== null && openFiles.includes(change.file_name_add) === false) {
this.createNewFileWithContent(change.file_name_add, change.file_text);
} else if(change.file_name_add !== null && change.file_text!== null && openFiles.includes(change.file_name_add)) {
this.addDiffToFile(change.file_name_add, change.file_text);
} else if(change.file_name_delete) {
this.deleteFile(change.file_name_delete);
}
}
}


async handleOpenFile(file: {file_name:string, line?: number}) {
const uri = this.filePathToUri(file.file_name);
Expand Down
Loading