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

Revert "Toolbox2 messages in thread" #52

Merged
merged 1 commit into from
Nov 23, 2023
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
22 changes: 0 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
"engines": {
"vscode": "^1.69.0"
},
"enabledApiProposals": [
"contribCommentThreadAdditionalMenu"
],
"categories": [
"Programming Languages",
"Snippets",
Expand Down Expand Up @@ -142,15 +139,6 @@
},
"properties": [],
"commands": [
{
"command": "refactaicmd.sendChatToSidebar",
"title": "Open in Sidebar",
"enablement": "refactaicmd.openSidebarButtonEnabled"
},
{
"command": "refactaicmd.closeInlineChat",
"title": "Close"
},
{
"command": "refactaicmd.activateToolbox",
"title": "Activate",
Expand Down Expand Up @@ -233,16 +221,6 @@
"submenu": "refact-access-menu",
"group": "z_commands"
}
],
"comments/commentThread/additionalActions": [
{
"command": "refactaicmd.sendChatToSidebar",
"group": "inline@1"
},
{
"command": "refactaicmd.closeInlineChat",
"group": "inline@2"
}
]
},
"submenus": [
Expand Down
15 changes: 2 additions & 13 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ declare global {
var chat_models: string[];
var have_caps: boolean;
var comment_disposables: vscode.Disposable[];
var comment_file_uri: vscode.Uri|undefined;
}

async function pressed_call_chat() {
Expand All @@ -58,17 +57,8 @@ async function pressed_escape()
completionProvider.on_esc_pressed();
let editor = vscode.window.activeTextEditor;
if (global.comment_disposables) {
let original_editor_uri = rconsoleProvider.refact_console_close();
if (original_editor_uri !== undefined) {
// find editor
let original_editor = vscode.window.visibleTextEditors.find((e) => {
return e.document.uri === original_editor_uri;
});
if (original_editor) {
editor = original_editor;
}
}
// don't return, remove all other things too -- we are here because Esc in the comment thread
rconsoleProvider.refact_console_close();
return;
}
if (editor) {
let state = estate.state_of_editor(editor, "pressed_escape");
Expand Down Expand Up @@ -122,7 +112,6 @@ async function code_lens_clicked(arg0: any)
}
if (arg0 === "APPROVE") {
await interactiveDiff.like_and_accept(editor);
rconsoleProvider.refact_console_close();
} else if (arg0 === "REJECT") {
await pressed_escape(); // might return to highlight
} else if (arg0 === "RERUN") {
Expand Down
65 changes: 19 additions & 46 deletions src/rconsoleCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import * as interactiveDiff from "./interactiveDiff";
import * as estate from "./estate";


export type ThreadCallback = (role: string, answer: string) => void;
export type Messages = [string, string][];
export type ThreadEndCallback = (messages: Messages) => void;



export let commands_available: { [key: string]: string } = {
"shorter": "Make code shorter",
"bugs": "Find and fix bugs",
Expand Down Expand Up @@ -59,10 +53,10 @@ function get_chars(str: string): Set<string>
}

export function get_hints(
msgs: Messages,
msgs: [string, string][],
unfinished_text: string,
selected_range: vscode.Range
): [string, string, string] {
): [string, string] {
if (unfinished_text.startsWith("/")) {
let cmd_score: { [key: string]: number } = {};
for (let cmd in commands_available) {
Expand All @@ -78,20 +72,20 @@ export function get_hints(
let text = commands_available[cmd] || "";
result += `<a href=\"x\"><b>/${cmd}</b> ${text}</a><br>\n`;
}
return [result, "Available commands:", top3[0][0]];
return [result, "Available commands:"];
} else {
if (!selected_range.isEmpty) {
let lines_n = selected_range.end.line - selected_range.start.line + 1;
return [`How to change these ${lines_n} lines? Also try "explain this" or commands starting with \"/\".`, "🪄 Selected text", ""];
return [`How to change these ${lines_n} lines? Also try "explain this" or commands starting with \"/\".`, "🪄 Selected text"];
} else {
return [`What would you like to generate? Also try commands starting with \"/\".`, "🪄 New Code", ""];
return [`What would you like to generate? Also try commands starting with \"/\".`, "🪄 New Code"];
}
}
}

export function initial_messages(working_on_attach_filename: string, working_on_attach_code: string)
{
let messages: Messages = [];
let messages: [string, string][] = [];
let single_file_json = JSON.stringify([{
"file_name": working_on_attach_filename,
"file_content": working_on_attach_code,
Expand All @@ -101,12 +95,10 @@ export function initial_messages(working_on_attach_filename: string, working_on_
}

export async function stream_chat_without_visible_chat(
messages: Messages,
messages: [string, string][],
editor: vscode.TextEditor,
selected_range: vscode.Range,
cancelToken: vscode.CancellationToken,
thread_callback: ThreadCallback,
end_thread_callback: ThreadEndCallback,
cancelToken: vscode.CancellationToken
) {
let state = estate.state_of_editor(editor, "invisible_chat");
if (!state) {
Expand Down Expand Up @@ -153,9 +145,6 @@ export async function stream_chat_without_visible_chat(
if (role0) {
answer_role = role0;
}
if(answer_role && answer) {
thread_callback(answer_role, answer);
}
}
}

Expand All @@ -175,21 +164,11 @@ export async function stream_chat_without_visible_chat(
largest_block = block;
}
}

end_thread_callback(messages);

if (largest_block) {
chatTab.diff_paste_back(
editor,
selected_range,
largest_block,
);
} else {
let state = estate.state_of_document(editor.document);
if (state) {
await estate.switch_mode(state, estate.Mode.Normal);
}
}
chatTab.diff_paste_back(
editor,
selected_range,
largest_block,
);
} else {
let state = estate.state_of_editor(editor, "streaming_end_callback");
if (state) {
Expand All @@ -210,7 +189,7 @@ export async function stream_chat_without_visible_chat(
));
}

function _run_command(cmd: string, doc_uri: string, messages: Messages, update_thread_callback: ThreadCallback, end_thread_callback: ThreadEndCallback)
function _run_command(cmd: string, doc_uri: string)
{
let text = commands_available[cmd] || "";
let editor = vscode.window.visibleTextEditors.find((editor) => {
Expand All @@ -221,30 +200,24 @@ function _run_command(cmd: string, doc_uri: string, messages: Messages, update_t
return;
}
let [official_selection, working_on_attach_code, working_on_attach_filename, code_snippet] = chatTab.attach_code_from_editor(editor);
// let messages: [string, string][] = initial_messages(working_on_attach_filename, working_on_attach_code);
const messageWithUserInput = [
...messages
];
messageWithUserInput.push(["user", "```\n" + code_snippet + "\n```\n\n" + text + "\n"]);
let messages: [string, string][] = initial_messages(working_on_attach_filename, working_on_attach_code);
messages.push(["user", "```\n" + code_snippet + "\n```\n\n" + text + "\n"]);
let cancellationTokenSource = new vscode.CancellationTokenSource();
let cancellationToken = cancellationTokenSource.token;
rconsoleCommands.stream_chat_without_visible_chat(
messageWithUserInput,
messages,
editor,
official_selection,
cancellationToken,
update_thread_callback,
end_thread_callback
);
}

export function register_commands(): vscode.Disposable[]
{
let dispos = [];

for (let cmd in commands_available) {
let d = vscode.commands.registerCommand('refactaicmd.cmd_' + cmd, (doc_uri, messages: Messages, update_thread_callback: ThreadCallback, end_thread_callback: ThreadEndCallback) => {
_run_command(cmd, doc_uri, messages, update_thread_callback, end_thread_callback);
let d = vscode.commands.registerCommand('refactaicmd.cmd_' + cmd, (doc_uri) => {
_run_command(cmd, doc_uri);
});
dispos.push(d);
}
Expand Down
Loading