Skip to content
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
1 change: 1 addition & 0 deletions src/interactiveDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ 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);
}


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 @@
ideEscapeKeyPressed,
ideIsChatStreaming,
setCurrentProjectInfo,
ideToolEdit,
ideToolCall,

Check failure on line 33 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (x86_64-unknown-linux-gnu)

Module '"refact-chat-js/dist/events"' has no exported member 'ideToolCall'.

Check failure on line 33 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (aarch64-unknown-linux-gnu)

Module '"refact-chat-js/dist/events"' has no exported member 'ideToolCall'.
ToolEditResult,
ideToolCallResponse,

Check failure on line 35 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (x86_64-unknown-linux-gnu)

'"refact-chat-js/dist/events"' has no exported member named 'ideToolCallResponse'. Did you mean 'isToolResponse'?

Check failure on line 35 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (aarch64-unknown-linux-gnu)

'"refact-chat-js/dist/events"' has no exported member named 'ideToolCallResponse'. Did you mean 'isToolResponse'?
TextDocToolCall,

Check failure on line 36 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (x86_64-unknown-linux-gnu)

Module '"refact-chat-js/dist/events"' has no exported member 'TextDocToolCall'.

Check failure on line 36 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (aarch64-unknown-linux-gnu)

Module '"refact-chat-js/dist/events"' has no exported member '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 @@

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 @@
}

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;

Check failure on line 545 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (x86_64-unknown-linux-gnu)

Property 'chatId' does not exist on type 'string'.

Check failure on line 545 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (x86_64-unknown-linux-gnu)

Property 'chatId' does not exist on type 'string'.

Check failure on line 545 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (x86_64-unknown-linux-gnu)

Property 'toolCallId' does not exist on type 'string'.

Check failure on line 545 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (aarch64-unknown-linux-gnu)

Property 'chatId' does not exist on type 'string'.

Check failure on line 545 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (aarch64-unknown-linux-gnu)

Property 'chatId' does not exist on type 'string'.

Check failure on line 545 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (aarch64-unknown-linux-gnu)

Property 'toolCallId' does not exist on type 'string'.
return this.handleDiffPasteBack(e.payload.content);

Check failure on line 546 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (x86_64-unknown-linux-gnu)

Property 'content' does not exist on type 'string'.

Check failure on line 546 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (aarch64-unknown-linux-gnu)

Property 'content' does not exist on type 'string'.
}


Expand All @@ -563,8 +567,9 @@
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};

Check failure on line 571 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (x86_64-unknown-linux-gnu)

Property 'payload' does not exist on type 'object & Record<"type", unknown>'.

Check failure on line 571 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (x86_64-unknown-linux-gnu)

Property 'payload' does not exist on type 'object & Record<"type", unknown>'.

Check failure on line 571 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (aarch64-unknown-linux-gnu)

Property 'payload' does not exist on type 'object & Record<"type", unknown>'.

Check failure on line 571 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (aarch64-unknown-linux-gnu)

Property 'payload' does not exist on type 'object & Record<"type", unknown>'.
return this.handleToolEdit(e.payload.toolCall, e.payload.edit);

Check failure on line 572 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (x86_64-unknown-linux-gnu)

Property 'payload' does not exist on type 'object & Record<"type", unknown>'.

Check failure on line 572 in src/sidebar.ts

View workflow job for this annotation

GitHub Actions / dist (aarch64-unknown-linux-gnu)

Property 'payload' does not exist on type 'object & Record<"type", unknown>'.
}
// if(ideOpenChatInNewTab.match(e)) {
// return this.handleOpenInTab(e.payload);
Expand Down Expand Up @@ -598,12 +603,12 @@

// }

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 @@
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