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.9",
"refact-chat-js": "^2.0.10-alpha.2",
"uuid": "^9.0.1",
"vscode-languageclient": "^7.0.0"
},
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ async function pressed_escape()
}
if (editor) {
let state = estate.state_of_editor(editor, "pressed_escape");
global.side_panel?.toolEditChange(editor.document.uri.fsPath, false);
if (state) {
state.diff_lens_pos = Number.MAX_SAFE_INTEGER;
state.completion_lens_pos = Number.MAX_SAFE_INTEGER;
Expand Down
2 changes: 2 additions & 0 deletions src/interactiveDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,8 @@ export async function like_and_accept(editor: vscode.TextEditor)
// dataCollection.data_feedback_candidate_reset(state);
});
await thenable;
global.side_panel?.toolEditChange(editor.document.uri.fsPath, true);
await editor.document.save();
}


Expand Down
56 changes: 49 additions & 7 deletions src/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ import {
ideEscapeKeyPressed,
ideIsChatStreaming,
setCurrentProjectInfo,
ideToolEdit,
ideToolCall,
ToolEditResult,
ideToolCallResponse,
TextDocToolCall,
} from "refact-chat-js/dist/events";
import { basename, join } from "path";
import { diff_paste_back } from "./chatTab";
Expand Down Expand Up @@ -86,6 +88,7 @@ export class PanelWebview implements vscode.WebviewViewProvider {

public chat: chatTab.ChatTab | null = null;
public statistic: statisticTab.StatisticTab | null = null;
public tool_edit_in_progress: null | {chatId: string, toolCallId?: string} = null;
// public fim_debug: fimDebug.FimDebug | null = null;
// public chatHistoryProvider: ChatHistoryProvider|undefined;

Expand Down Expand Up @@ -539,7 +542,8 @@ export class PanelWebview implements vscode.WebviewViewProvider {
}

if(ideDiffPasteBackAction.match(e)) {
return this.handleDiffPasteBack(e.payload);
this.tool_edit_in_progress = e.payload.chatId ? {chatId: e.payload.chatId, toolCallId: e.payload.toolCallId} : null;
return this.handleDiffPasteBack(e.payload.content);
}


Expand All @@ -563,8 +567,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(ideToolCall.match(e)) {
this.tool_edit_in_progress = {chatId: e.payload.chatId, toolCallId: e.payload.toolCall.id};
return this.handleToolEdit(e.payload.toolCall, e.payload.edit);
}
// if(ideOpenChatInNewTab.match(e)) {
// return this.handleOpenInTab(e.payload);
Expand Down Expand Up @@ -598,12 +603,12 @@ export class PanelWebview implements vscode.WebviewViewProvider {

// }

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

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


Expand All @@ -627,14 +632,51 @@ export class PanelWebview implements vscode.WebviewViewProvider {
edit.insert(newFile, new vscode.Position(0, 0), content);
return vscode.workspace.applyEdit(edit).then(success => {
if (success) {
this.watchFileForSaveOrClose(document);
vscode.window.showTextDocument(document);
// TOOD: send message to ide when file is saved, or closed
} else {
vscode.window.showInformationMessage('Error: creating file ' + fileName);
}
});
});
}

watchFileForSaveOrClose(document: vscode.TextDocument) {
const disposables: vscode.Disposable[] = [];
const saveDisposable = vscode.workspace.onDidSaveTextDocument((savedDoc) => {
if (savedDoc.uri.toString() === document.uri.toString()) {
// Send message to webview that file was saved
this.toolEditChange(document.uri.fsPath, true);
disposables.forEach(d => d.dispose());
}
});
disposables.push(saveDisposable);

const closeDisposable = vscode.workspace.onDidCloseTextDocument((closedDoc) => {
if (closedDoc.uri.toString() === document.uri.toString()) {
// Send message to webview that file was closed
this.toolEditChange(document.uri.fsPath, false);
disposables.forEach(d => d.dispose());
}
});
disposables.push(closeDisposable);

this._disposables.push(...disposables);
}

toolEditChange(path: string, accepted: boolean | "indeterminate") {
if(this.tool_edit_in_progress) {
const action = ideToolCallResponse({
chatId: this.tool_edit_in_progress.chatId,
toolCallId: this.tool_edit_in_progress.toolCallId ?? "",
accepted
});
this._view?.webview.postMessage(action);
this.tool_edit_in_progress = null;
}
}

async addDiffToFile(fileName: string, content: string) {
const uri = this.filePathToUri(fileName);
const document = await vscode.workspace.openTextDocument(uri);
Expand Down
Loading