✨ model role for inlineEdit
This commit is contained in:
parent
c3d3980e97
commit
721ce6c799
6 changed files with 411 additions and 367 deletions
6
core/index.d.ts
vendored
6
core/index.d.ts
vendored
|
|
@ -702,8 +702,14 @@ interface ContextMenuConfig {
|
|||
optimize?: string;
|
||||
fixGrammar?: string;
|
||||
}
|
||||
|
||||
interface ModelRoles {
|
||||
inlineEdit?: string;
|
||||
}
|
||||
|
||||
interface ExperimantalConfig {
|
||||
contextMenuPrompts?: ContextMenuConfig;
|
||||
modelRoles?: ModelRoles;
|
||||
}
|
||||
|
||||
export interface SerializedContinueConfig {
|
||||
|
|
|
|||
8
docs/static/schemas/config.json
vendored
8
docs/static/schemas/config.json
vendored
|
|
@ -1960,6 +1960,14 @@
|
|||
"title": "Experimental",
|
||||
"description": "Experimental properties are subject to change.",
|
||||
"properties": {
|
||||
"modelRoles": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"inlineEdit": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"contextMenuPrompts": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
|||
|
|
@ -1960,6 +1960,14 @@
|
|||
"title": "Experimental",
|
||||
"description": "Experimental properties are subject to change.",
|
||||
"properties": {
|
||||
"modelRoles": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"inlineEdit": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"contextMenuPrompts": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
|||
|
|
@ -1960,6 +1960,14 @@
|
|||
"title": "Experimental",
|
||||
"description": "Experimental properties are subject to change.",
|
||||
"properties": {
|
||||
"modelRoles": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"inlineEdit": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"contextMenuPrompts": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
|||
|
|
@ -2199,6 +2199,14 @@
|
|||
"title": "Experimental",
|
||||
"description": "Experimental properties are subject to change.",
|
||||
"properties": {
|
||||
"modelRoles": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"inlineEdit": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"contextMenuPrompts": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import * as os from "os";
|
|||
import * as path from "path";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
import { IDE } from "core";
|
||||
import { ContextMenuConfig, IDE } from "core";
|
||||
import { AutocompleteOutcome } from "core/autocomplete/completionProvider";
|
||||
import { ConfigHandler } from "core/config/handler";
|
||||
import { logDevData } from "core/util/devdata";
|
||||
|
|
@ -147,389 +147,395 @@ const commandsMap: (
|
|||
configHandler,
|
||||
diffManager,
|
||||
verticalDiffManager,
|
||||
) => ({
|
||||
"continue.acceptDiff": async (newFilepath?: string | vscode.Uri) => {
|
||||
if (newFilepath instanceof vscode.Uri) {
|
||||
newFilepath = newFilepath.fsPath;
|
||||
}
|
||||
verticalDiffManager.clearForFilepath(newFilepath, true);
|
||||
await diffManager.acceptDiff(newFilepath);
|
||||
},
|
||||
"continue.rejectDiff": async (newFilepath?: string | vscode.Uri) => {
|
||||
if (newFilepath instanceof vscode.Uri) {
|
||||
newFilepath = newFilepath.fsPath;
|
||||
}
|
||||
verticalDiffManager.clearForFilepath(newFilepath, false);
|
||||
await diffManager.rejectDiff(newFilepath);
|
||||
},
|
||||
"continue.acceptVerticalDiffBlock": (filepath?: string, index?: number) => {
|
||||
verticalDiffManager.acceptRejectVerticalDiffBlock(true, filepath, index);
|
||||
},
|
||||
"continue.rejectVerticalDiffBlock": (filepath?: string, index?: number) => {
|
||||
verticalDiffManager.acceptRejectVerticalDiffBlock(false, filepath, index);
|
||||
},
|
||||
"continue.quickFix": async (message: string, code: string, edit: boolean) => {
|
||||
sidebar.webviewProtocol?.request("newSessionWithPrompt", {
|
||||
prompt: `${
|
||||
edit ? "/edit " : ""
|
||||
}${code}\n\nHow do I fix this problem in the above code?: ${message}`,
|
||||
});
|
||||
|
||||
if (!edit) {
|
||||
vscode.commands.executeCommand("continue.continueGUIView.focus");
|
||||
}
|
||||
},
|
||||
"continue.focusContinueInput": async () => {
|
||||
if (!getFullScreenTab()) {
|
||||
vscode.commands.executeCommand("continue.continueGUIView.focus");
|
||||
}
|
||||
sidebar.webviewProtocol?.request("focusContinueInput", undefined);
|
||||
await addHighlightedCodeToContext(false, sidebar.webviewProtocol);
|
||||
},
|
||||
"continue.focusContinueInputWithoutClear": async () => {
|
||||
if (!getFullScreenTab()) {
|
||||
vscode.commands.executeCommand("continue.continueGUIView.focus");
|
||||
}
|
||||
sidebar.webviewProtocol?.request(
|
||||
"focusContinueInputWithoutClear",
|
||||
undefined,
|
||||
);
|
||||
await addHighlightedCodeToContext(true, sidebar.webviewProtocol);
|
||||
},
|
||||
"continue.toggleAuxiliaryBar": () => {
|
||||
vscode.commands.executeCommand("workbench.action.toggleAuxiliaryBar");
|
||||
},
|
||||
"continue.quickEdit": async (prompt?: string) => {
|
||||
const selectionEmpty = vscode.window.activeTextEditor?.selection.isEmpty;
|
||||
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
const existingHandler = verticalDiffManager.getHandlerForFile(
|
||||
editor?.document.uri.fsPath ?? "",
|
||||
);
|
||||
const previousInput = existingHandler?.input;
|
||||
|
||||
let defaultModelTitle = await sidebar.webviewProtocol.request(
|
||||
"getDefaultModelTitle",
|
||||
undefined,
|
||||
);
|
||||
) => {
|
||||
async function streamInlineEdit(
|
||||
promptName: keyof ContextMenuConfig,
|
||||
fallbackPrompt: string,
|
||||
) {
|
||||
const config = await configHandler.loadConfig();
|
||||
if (!defaultModelTitle) {
|
||||
defaultModelTitle = config.models[0]?.title!;
|
||||
}
|
||||
const quickPickItems =
|
||||
config.contextProviders
|
||||
?.filter((provider) => provider.description.type === "normal")
|
||||
.map((provider) => {
|
||||
return {
|
||||
label: provider.description.displayTitle,
|
||||
description: provider.description.title,
|
||||
detail: provider.description.description,
|
||||
};
|
||||
}) || [];
|
||||
|
||||
const addContextMsg = quickPickItems.length
|
||||
? " (or press enter to add context first)"
|
||||
: "";
|
||||
const textInputOptions: vscode.InputBoxOptions = {
|
||||
placeHolder: selectionEmpty
|
||||
? `Type instructions to generate code${addContextMsg}`
|
||||
: `Describe how to edit the highlighted code${addContextMsg}`,
|
||||
title: `${getPlatform() === "mac" ? "Cmd" : "Ctrl"}+I`,
|
||||
prompt: `[${defaultModelTitle}]`,
|
||||
value: prompt,
|
||||
};
|
||||
if (previousInput) {
|
||||
textInputOptions.value = previousInput + ", ";
|
||||
textInputOptions.valueSelection = [
|
||||
textInputOptions.value.length,
|
||||
textInputOptions.value.length,
|
||||
];
|
||||
}
|
||||
|
||||
let text = await vscode.window.showInputBox(textInputOptions);
|
||||
|
||||
if (text === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (text.length > 0 || quickPickItems.length === 0) {
|
||||
const modelName = await sidebar.webviewProtocol.request(
|
||||
const modelTitle =
|
||||
config.experimental?.modelRoles?.inlineEdit ??
|
||||
(await sidebar.webviewProtocol.request(
|
||||
"getDefaultModelTitle",
|
||||
undefined,
|
||||
));
|
||||
await verticalDiffManager.streamEdit(
|
||||
config.experimental?.contextMenuPrompts?.[promptName] ?? fallbackPrompt,
|
||||
modelTitle,
|
||||
);
|
||||
}
|
||||
return {
|
||||
"continue.acceptDiff": async (newFilepath?: string | vscode.Uri) => {
|
||||
if (newFilepath instanceof vscode.Uri) {
|
||||
newFilepath = newFilepath.fsPath;
|
||||
}
|
||||
verticalDiffManager.clearForFilepath(newFilepath, true);
|
||||
await diffManager.acceptDiff(newFilepath);
|
||||
},
|
||||
"continue.rejectDiff": async (newFilepath?: string | vscode.Uri) => {
|
||||
if (newFilepath instanceof vscode.Uri) {
|
||||
newFilepath = newFilepath.fsPath;
|
||||
}
|
||||
verticalDiffManager.clearForFilepath(newFilepath, false);
|
||||
await diffManager.rejectDiff(newFilepath);
|
||||
},
|
||||
"continue.acceptVerticalDiffBlock": (filepath?: string, index?: number) => {
|
||||
verticalDiffManager.acceptRejectVerticalDiffBlock(true, filepath, index);
|
||||
},
|
||||
"continue.rejectVerticalDiffBlock": (filepath?: string, index?: number) => {
|
||||
verticalDiffManager.acceptRejectVerticalDiffBlock(false, filepath, index);
|
||||
},
|
||||
"continue.quickFix": async (
|
||||
message: string,
|
||||
code: string,
|
||||
edit: boolean,
|
||||
) => {
|
||||
sidebar.webviewProtocol?.request("newSessionWithPrompt", {
|
||||
prompt: `${
|
||||
edit ? "/edit " : ""
|
||||
}${code}\n\nHow do I fix this problem in the above code?: ${message}`,
|
||||
});
|
||||
|
||||
if (!edit) {
|
||||
vscode.commands.executeCommand("continue.continueGUIView.focus");
|
||||
}
|
||||
},
|
||||
"continue.focusContinueInput": async () => {
|
||||
if (!getFullScreenTab()) {
|
||||
vscode.commands.executeCommand("continue.continueGUIView.focus");
|
||||
}
|
||||
sidebar.webviewProtocol?.request("focusContinueInput", undefined);
|
||||
await addHighlightedCodeToContext(false, sidebar.webviewProtocol);
|
||||
},
|
||||
"continue.focusContinueInputWithoutClear": async () => {
|
||||
if (!getFullScreenTab()) {
|
||||
vscode.commands.executeCommand("continue.continueGUIView.focus");
|
||||
}
|
||||
sidebar.webviewProtocol?.request(
|
||||
"focusContinueInputWithoutClear",
|
||||
undefined,
|
||||
);
|
||||
await verticalDiffManager.streamEdit(text, modelName);
|
||||
} else {
|
||||
// Pick context first
|
||||
const selectedProviders = await vscode.window.showQuickPick(
|
||||
quickPickItems,
|
||||
{
|
||||
title: "Add Context",
|
||||
canPickMany: true,
|
||||
},
|
||||
await addHighlightedCodeToContext(true, sidebar.webviewProtocol);
|
||||
},
|
||||
"continue.toggleAuxiliaryBar": () => {
|
||||
vscode.commands.executeCommand("workbench.action.toggleAuxiliaryBar");
|
||||
},
|
||||
"continue.quickEdit": async (prompt?: string) => {
|
||||
const selectionEmpty = vscode.window.activeTextEditor?.selection.isEmpty;
|
||||
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
const existingHandler = verticalDiffManager.getHandlerForFile(
|
||||
editor?.document.uri.fsPath ?? "",
|
||||
);
|
||||
const previousInput = existingHandler?.input;
|
||||
|
||||
const config = await configHandler.loadConfig();
|
||||
let defaultModelTitle =
|
||||
config.experimental?.modelRoles?.inlineEdit ??
|
||||
(await sidebar.webviewProtocol.request(
|
||||
"getDefaultModelTitle",
|
||||
undefined,
|
||||
));
|
||||
if (!defaultModelTitle) {
|
||||
defaultModelTitle = config.models[0]?.title!;
|
||||
}
|
||||
const quickPickItems =
|
||||
config.contextProviders
|
||||
?.filter((provider) => provider.description.type === "normal")
|
||||
.map((provider) => {
|
||||
return {
|
||||
label: provider.description.displayTitle,
|
||||
description: provider.description.title,
|
||||
detail: provider.description.description,
|
||||
};
|
||||
}) || [];
|
||||
|
||||
const addContextMsg = quickPickItems.length
|
||||
? " (or press enter to add context first)"
|
||||
: "";
|
||||
const textInputOptions: vscode.InputBoxOptions = {
|
||||
placeHolder: selectionEmpty
|
||||
? `Type instructions to generate code${addContextMsg}`
|
||||
: `Describe how to edit the highlighted code${addContextMsg}`,
|
||||
title: `${getPlatform() === "mac" ? "Cmd" : "Ctrl"}+I`,
|
||||
prompt: `[${defaultModelTitle}]`,
|
||||
value: prompt,
|
||||
};
|
||||
if (previousInput) {
|
||||
textInputOptions.value = previousInput + ", ";
|
||||
textInputOptions.valueSelection = [
|
||||
textInputOptions.value.length,
|
||||
textInputOptions.value.length,
|
||||
];
|
||||
}
|
||||
|
||||
let text = await vscode.window.showInputBox(textInputOptions);
|
||||
if (text) {
|
||||
const llm = await configHandler.llmFromTitle();
|
||||
const config = await configHandler.loadConfig();
|
||||
const context = (
|
||||
await Promise.all(
|
||||
selectedProviders?.map((providerTitle) => {
|
||||
const provider = config.contextProviders?.find(
|
||||
(provider) =>
|
||||
provider.description.title === providerTitle.description,
|
||||
);
|
||||
if (!provider) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return provider.getContextItems("", {
|
||||
embeddingsProvider: config.embeddingsProvider,
|
||||
reranker: config.reranker,
|
||||
ide,
|
||||
llm,
|
||||
fullInput: text || "",
|
||||
selectedCode: [],
|
||||
fetch: (url, init) =>
|
||||
fetchwithRequestOptions(url, init, config.requestOptions),
|
||||
});
|
||||
}) || [],
|
||||
)
|
||||
).flat();
|
||||
|
||||
text =
|
||||
context.map((item) => item.content).join("\n\n") +
|
||||
"\n\n---\n\n" +
|
||||
text;
|
||||
|
||||
await verticalDiffManager.streamEdit(text, defaultModelTitle);
|
||||
if (text === undefined) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
},
|
||||
"continue.writeCommentsForCode": async () => {
|
||||
await verticalDiffManager.streamEdit(
|
||||
(await configHandler.loadConfig()).experimental?.contextMenuPrompts
|
||||
?.comment ||
|
||||
|
||||
if (text.length > 0 || quickPickItems.length === 0) {
|
||||
await verticalDiffManager.streamEdit(text, defaultModelTitle);
|
||||
} else {
|
||||
// Pick context first
|
||||
const selectedProviders = await vscode.window.showQuickPick(
|
||||
quickPickItems,
|
||||
{
|
||||
title: "Add Context",
|
||||
canPickMany: true,
|
||||
},
|
||||
);
|
||||
|
||||
let text = await vscode.window.showInputBox(textInputOptions);
|
||||
if (text) {
|
||||
const llm = await configHandler.llmFromTitle();
|
||||
const config = await configHandler.loadConfig();
|
||||
const context = (
|
||||
await Promise.all(
|
||||
selectedProviders?.map((providerTitle) => {
|
||||
const provider = config.contextProviders?.find(
|
||||
(provider) =>
|
||||
provider.description.title === providerTitle.description,
|
||||
);
|
||||
if (!provider) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return provider.getContextItems("", {
|
||||
embeddingsProvider: config.embeddingsProvider,
|
||||
reranker: config.reranker,
|
||||
ide,
|
||||
llm,
|
||||
fullInput: text || "",
|
||||
selectedCode: [],
|
||||
fetch: (url, init) =>
|
||||
fetchwithRequestOptions(url, init, config.requestOptions),
|
||||
});
|
||||
}) || [],
|
||||
)
|
||||
).flat();
|
||||
|
||||
text =
|
||||
context.map((item) => item.content).join("\n\n") +
|
||||
"\n\n---\n\n" +
|
||||
text;
|
||||
|
||||
await verticalDiffManager.streamEdit(text, defaultModelTitle);
|
||||
}
|
||||
}
|
||||
},
|
||||
"continue.writeCommentsForCode": async () => {
|
||||
streamInlineEdit(
|
||||
"comment",
|
||||
"Write comments for this code. Do not change anything about the code itself.",
|
||||
await sidebar.webviewProtocol.request("getDefaultModelTitle", undefined),
|
||||
);
|
||||
},
|
||||
"continue.writeDocstringForCode": async () => {
|
||||
await verticalDiffManager.streamEdit(
|
||||
(await configHandler.loadConfig()).experimental?.contextMenuPrompts
|
||||
?.docstring ||
|
||||
"Write a docstring for this code. Do not change anything about the code itself.",
|
||||
await sidebar.webviewProtocol.request("getDefaultModelTitle", undefined),
|
||||
);
|
||||
},
|
||||
"continue.fixCode": async () => {
|
||||
await verticalDiffManager.streamEdit(
|
||||
(await configHandler.loadConfig()).experimental?.contextMenuPrompts
|
||||
?.fix || "Fix this code",
|
||||
await sidebar.webviewProtocol.request("getDefaultModelTitle", undefined),
|
||||
);
|
||||
},
|
||||
"continue.optimizeCode": async () => {
|
||||
await verticalDiffManager.streamEdit(
|
||||
(await configHandler.loadConfig()).experimental?.contextMenuPrompts
|
||||
?.optimize || "Optimize this code",
|
||||
await sidebar.webviewProtocol.request("getDefaultModelTitle", undefined),
|
||||
);
|
||||
},
|
||||
"continue.fixGrammar": async () => {
|
||||
await verticalDiffManager.streamEdit(
|
||||
(await configHandler.loadConfig()).experimental?.contextMenuPrompts
|
||||
?.fixGrammar ||
|
||||
"If there are any grammar or spelling mistakes in this writing, fix them. Do not make other large changes to the writing.",
|
||||
await sidebar.webviewProtocol.request("getDefaultModelTitle", undefined),
|
||||
);
|
||||
},
|
||||
"continue.viewLogs": async () => {
|
||||
// Open ~/.continue/continue.log
|
||||
const logFile = path.join(os.homedir(), ".continue", "continue.log");
|
||||
// Make sure the file/directory exist
|
||||
if (!fs.existsSync(logFile)) {
|
||||
fs.mkdirSync(path.dirname(logFile), { recursive: true });
|
||||
fs.writeFileSync(logFile, "");
|
||||
}
|
||||
|
||||
const uri = vscode.Uri.file(logFile);
|
||||
await vscode.window.showTextDocument(uri);
|
||||
},
|
||||
"continue.debugTerminal": async () => {
|
||||
const terminalContents = await ide.getTerminalContents();
|
||||
vscode.commands.executeCommand("continue.continueGUIView.focus");
|
||||
sidebar.webviewProtocol?.request("userInput", {
|
||||
input: `I got the following error, can you please help explain how to fix it?\n\n${terminalContents.trim()}`,
|
||||
});
|
||||
},
|
||||
"continue.hideInlineTip": () => {
|
||||
vscode.workspace
|
||||
.getConfiguration("continue")
|
||||
.update("showInlineTip", false, vscode.ConfigurationTarget.Global);
|
||||
},
|
||||
|
||||
// Commands without keyboard shortcuts
|
||||
"continue.addModel": () => {
|
||||
vscode.commands.executeCommand("continue.continueGUIView.focus");
|
||||
sidebar.webviewProtocol?.request("addModel", undefined);
|
||||
},
|
||||
"continue.openSettingsUI": () => {
|
||||
vscode.commands.executeCommand("continue.continueGUIView.focus");
|
||||
sidebar.webviewProtocol?.request("openSettings", undefined);
|
||||
},
|
||||
"continue.sendMainUserInput": (text: string) => {
|
||||
sidebar.webviewProtocol?.request("userInput", {
|
||||
input: text,
|
||||
});
|
||||
},
|
||||
"continue.shareSession": () => {
|
||||
sidebar.sendMainUserInput("/share");
|
||||
},
|
||||
"continue.selectRange": (startLine: number, endLine: number) => {
|
||||
if (!vscode.window.activeTextEditor) {
|
||||
return;
|
||||
}
|
||||
vscode.window.activeTextEditor.selection = new vscode.Selection(
|
||||
startLine,
|
||||
0,
|
||||
endLine,
|
||||
0,
|
||||
);
|
||||
},
|
||||
"continue.foldAndUnfold": (
|
||||
foldSelectionLines: number[],
|
||||
unfoldSelectionLines: number[],
|
||||
) => {
|
||||
vscode.commands.executeCommand("editor.unfold", {
|
||||
selectionLines: unfoldSelectionLines,
|
||||
});
|
||||
vscode.commands.executeCommand("editor.fold", {
|
||||
selectionLines: foldSelectionLines,
|
||||
});
|
||||
},
|
||||
"continue.sendToTerminal": (text: string) => {
|
||||
ide.runCommand(text);
|
||||
},
|
||||
"continue.newSession": () => {
|
||||
sidebar.webviewProtocol?.request("newSession", undefined);
|
||||
},
|
||||
"continue.viewHistory": () => {
|
||||
sidebar.webviewProtocol?.request("viewHistory", undefined);
|
||||
},
|
||||
"continue.toggleFullScreen": () => {
|
||||
// Check if full screen is already open by checking open tabs
|
||||
const fullScreenTab = getFullScreenTab();
|
||||
|
||||
// Check if the active editor is the Continue GUI View
|
||||
if (fullScreenTab && fullScreenTab.isActive) {
|
||||
//Full screen open and focused - close it
|
||||
vscode.commands.executeCommand("workbench.action.closeActiveEditor"); //this will trigger the onDidDispose listener below
|
||||
return;
|
||||
}
|
||||
|
||||
if (fullScreenTab) {
|
||||
//Full screen open, but not focused - focus it
|
||||
// Focus the tab
|
||||
const openOptions = {
|
||||
preserveFocus: true,
|
||||
preview: fullScreenTab.isPreview,
|
||||
viewColumn: fullScreenTab.group.viewColumn,
|
||||
};
|
||||
|
||||
vscode.commands.executeCommand(
|
||||
"vscode.open",
|
||||
(fullScreenTab.input as any).uri,
|
||||
openOptions,
|
||||
);
|
||||
return;
|
||||
}
|
||||
},
|
||||
"continue.writeDocstringForCode": async () => {
|
||||
streamInlineEdit(
|
||||
"docstring",
|
||||
"Write a docstring for this code. Do not change anything about the code itself.",
|
||||
);
|
||||
},
|
||||
"continue.fixCode": async () => {
|
||||
streamInlineEdit("fix", "Fix this code");
|
||||
},
|
||||
"continue.optimizeCode": async () => {
|
||||
streamInlineEdit("optimize", "Optimize this code");
|
||||
},
|
||||
"continue.fixGrammar": async () => {
|
||||
streamInlineEdit(
|
||||
"fixGrammar",
|
||||
"If there are any grammar or spelling mistakes in this writing, fix them. Do not make other large changes to the writing.",
|
||||
);
|
||||
},
|
||||
"continue.viewLogs": async () => {
|
||||
// Open ~/.continue/continue.log
|
||||
const logFile = path.join(os.homedir(), ".continue", "continue.log");
|
||||
// Make sure the file/directory exist
|
||||
if (!fs.existsSync(logFile)) {
|
||||
fs.mkdirSync(path.dirname(logFile), { recursive: true });
|
||||
fs.writeFileSync(logFile, "");
|
||||
}
|
||||
|
||||
//Full screen not open - open it
|
||||
const uri = vscode.Uri.file(logFile);
|
||||
await vscode.window.showTextDocument(uri);
|
||||
},
|
||||
"continue.debugTerminal": async () => {
|
||||
const terminalContents = await ide.getTerminalContents();
|
||||
vscode.commands.executeCommand("continue.continueGUIView.focus");
|
||||
sidebar.webviewProtocol?.request("userInput", {
|
||||
input: `I got the following error, can you please help explain how to fix it?\n\n${terminalContents.trim()}`,
|
||||
});
|
||||
},
|
||||
"continue.hideInlineTip": () => {
|
||||
vscode.workspace
|
||||
.getConfiguration("continue")
|
||||
.update("showInlineTip", false, vscode.ConfigurationTarget.Global);
|
||||
},
|
||||
|
||||
// Close the sidebar.webviews
|
||||
// vscode.commands.executeCommand("workbench.action.closeSidebar");
|
||||
vscode.commands.executeCommand("workbench.action.closeAuxiliaryBar");
|
||||
// vscode.commands.executeCommand("workbench.action.toggleZenMode");
|
||||
// Commands without keyboard shortcuts
|
||||
"continue.addModel": () => {
|
||||
vscode.commands.executeCommand("continue.continueGUIView.focus");
|
||||
sidebar.webviewProtocol?.request("addModel", undefined);
|
||||
},
|
||||
"continue.openSettingsUI": () => {
|
||||
vscode.commands.executeCommand("continue.continueGUIView.focus");
|
||||
sidebar.webviewProtocol?.request("openSettings", undefined);
|
||||
},
|
||||
"continue.sendMainUserInput": (text: string) => {
|
||||
sidebar.webviewProtocol?.request("userInput", {
|
||||
input: text,
|
||||
});
|
||||
},
|
||||
"continue.shareSession": () => {
|
||||
sidebar.sendMainUserInput("/share");
|
||||
},
|
||||
"continue.selectRange": (startLine: number, endLine: number) => {
|
||||
if (!vscode.window.activeTextEditor) {
|
||||
return;
|
||||
}
|
||||
vscode.window.activeTextEditor.selection = new vscode.Selection(
|
||||
startLine,
|
||||
0,
|
||||
endLine,
|
||||
0,
|
||||
);
|
||||
},
|
||||
"continue.foldAndUnfold": (
|
||||
foldSelectionLines: number[],
|
||||
unfoldSelectionLines: number[],
|
||||
) => {
|
||||
vscode.commands.executeCommand("editor.unfold", {
|
||||
selectionLines: unfoldSelectionLines,
|
||||
});
|
||||
vscode.commands.executeCommand("editor.fold", {
|
||||
selectionLines: foldSelectionLines,
|
||||
});
|
||||
},
|
||||
"continue.sendToTerminal": (text: string) => {
|
||||
ide.runCommand(text);
|
||||
},
|
||||
"continue.newSession": () => {
|
||||
sidebar.webviewProtocol?.request("newSession", undefined);
|
||||
},
|
||||
"continue.viewHistory": () => {
|
||||
sidebar.webviewProtocol?.request("viewHistory", undefined);
|
||||
},
|
||||
"continue.toggleFullScreen": () => {
|
||||
// Check if full screen is already open by checking open tabs
|
||||
const fullScreenTab = getFullScreenTab();
|
||||
|
||||
//create the full screen panel
|
||||
let panel = vscode.window.createWebviewPanel(
|
||||
"continue.continueGUIView",
|
||||
"Continue",
|
||||
vscode.ViewColumn.One,
|
||||
);
|
||||
// Check if the active editor is the Continue GUI View
|
||||
if (fullScreenTab && fullScreenTab.isActive) {
|
||||
//Full screen open and focused - close it
|
||||
vscode.commands.executeCommand("workbench.action.closeActiveEditor"); //this will trigger the onDidDispose listener below
|
||||
return;
|
||||
}
|
||||
|
||||
//Add content to the panel
|
||||
panel.webview.html = sidebar.getSidebarContent(
|
||||
extensionContext,
|
||||
panel,
|
||||
ide,
|
||||
configHandler,
|
||||
verticalDiffManager,
|
||||
undefined,
|
||||
undefined,
|
||||
true,
|
||||
);
|
||||
if (fullScreenTab) {
|
||||
//Full screen open, but not focused - focus it
|
||||
// Focus the tab
|
||||
const openOptions = {
|
||||
preserveFocus: true,
|
||||
preview: fullScreenTab.isPreview,
|
||||
viewColumn: fullScreenTab.group.viewColumn,
|
||||
};
|
||||
|
||||
//When panel closes, reset the webview and focus
|
||||
panel.onDidDispose(
|
||||
() => {
|
||||
sidebar.resetWebviewProtocolWebview();
|
||||
vscode.commands.executeCommand("continue.focusContinueInput");
|
||||
},
|
||||
null,
|
||||
extensionContext.subscriptions,
|
||||
);
|
||||
},
|
||||
"continue.openConfigJson": () => {
|
||||
ide.openFile(getConfigJsonPath());
|
||||
},
|
||||
"continue.selectFilesAsContext": (
|
||||
firstUri: vscode.Uri,
|
||||
uris: vscode.Uri[],
|
||||
) => {
|
||||
vscode.commands.executeCommand("continue.continueGUIView.focus");
|
||||
vscode.commands.executeCommand(
|
||||
"vscode.open",
|
||||
(fullScreenTab.input as any).uri,
|
||||
openOptions,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const uri of uris) {
|
||||
addEntireFileToContext(uri, false, sidebar.webviewProtocol);
|
||||
}
|
||||
},
|
||||
"continue.updateAllReferences": (filepath: vscode.Uri) => {
|
||||
// Get the cursor position in the editor
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
const position = editor.selection.active;
|
||||
sidebar.sendMainUserInput(
|
||||
`/references ${filepath.fsPath} ${position.line} ${position.character}`,
|
||||
);
|
||||
},
|
||||
"continue.logAutocompleteOutcome": (
|
||||
outcome: AutocompleteOutcome,
|
||||
logRejectionTimeout: NodeJS.Timeout,
|
||||
) => {
|
||||
clearTimeout(logRejectionTimeout);
|
||||
outcome.accepted = true;
|
||||
logDevData("autocomplete", outcome);
|
||||
Telemetry.capture("autocomplete", {
|
||||
accepted: outcome.accepted,
|
||||
modelName: outcome.modelName,
|
||||
modelProvider: outcome.modelProvider,
|
||||
time: outcome.time,
|
||||
cacheHit: outcome.cacheHit,
|
||||
});
|
||||
},
|
||||
"continue.toggleTabAutocompleteEnabled": () => {
|
||||
const config = vscode.workspace.getConfiguration("continue");
|
||||
const enabled = config.get("enableTabAutocomplete");
|
||||
config.update(
|
||||
"enableTabAutocomplete",
|
||||
!enabled,
|
||||
vscode.ConfigurationTarget.Global,
|
||||
);
|
||||
},
|
||||
});
|
||||
//Full screen not open - open it
|
||||
|
||||
// Close the sidebar.webviews
|
||||
// vscode.commands.executeCommand("workbench.action.closeSidebar");
|
||||
vscode.commands.executeCommand("workbench.action.closeAuxiliaryBar");
|
||||
// vscode.commands.executeCommand("workbench.action.toggleZenMode");
|
||||
|
||||
//create the full screen panel
|
||||
let panel = vscode.window.createWebviewPanel(
|
||||
"continue.continueGUIView",
|
||||
"Continue",
|
||||
vscode.ViewColumn.One,
|
||||
);
|
||||
|
||||
//Add content to the panel
|
||||
panel.webview.html = sidebar.getSidebarContent(
|
||||
extensionContext,
|
||||
panel,
|
||||
ide,
|
||||
configHandler,
|
||||
verticalDiffManager,
|
||||
undefined,
|
||||
undefined,
|
||||
true,
|
||||
);
|
||||
|
||||
//When panel closes, reset the webview and focus
|
||||
panel.onDidDispose(
|
||||
() => {
|
||||
sidebar.resetWebviewProtocolWebview();
|
||||
vscode.commands.executeCommand("continue.focusContinueInput");
|
||||
},
|
||||
null,
|
||||
extensionContext.subscriptions,
|
||||
);
|
||||
},
|
||||
"continue.openConfigJson": () => {
|
||||
ide.openFile(getConfigJsonPath());
|
||||
},
|
||||
"continue.selectFilesAsContext": (
|
||||
firstUri: vscode.Uri,
|
||||
uris: vscode.Uri[],
|
||||
) => {
|
||||
vscode.commands.executeCommand("continue.continueGUIView.focus");
|
||||
|
||||
for (const uri of uris) {
|
||||
addEntireFileToContext(uri, false, sidebar.webviewProtocol);
|
||||
}
|
||||
},
|
||||
"continue.updateAllReferences": (filepath: vscode.Uri) => {
|
||||
// Get the cursor position in the editor
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
const position = editor.selection.active;
|
||||
sidebar.sendMainUserInput(
|
||||
`/references ${filepath.fsPath} ${position.line} ${position.character}`,
|
||||
);
|
||||
},
|
||||
"continue.logAutocompleteOutcome": (
|
||||
outcome: AutocompleteOutcome,
|
||||
logRejectionTimeout: NodeJS.Timeout,
|
||||
) => {
|
||||
clearTimeout(logRejectionTimeout);
|
||||
outcome.accepted = true;
|
||||
logDevData("autocomplete", outcome);
|
||||
Telemetry.capture("autocomplete", {
|
||||
accepted: outcome.accepted,
|
||||
modelName: outcome.modelName,
|
||||
modelProvider: outcome.modelProvider,
|
||||
time: outcome.time,
|
||||
cacheHit: outcome.cacheHit,
|
||||
});
|
||||
},
|
||||
"continue.toggleTabAutocompleteEnabled": () => {
|
||||
const config = vscode.workspace.getConfiguration("continue");
|
||||
const enabled = config.get("enableTabAutocomplete");
|
||||
config.update(
|
||||
"enableTabAutocomplete",
|
||||
!enabled,
|
||||
vscode.ConfigurationTarget.Global,
|
||||
);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export function registerAllCommands(
|
||||
context: vscode.ExtensionContext,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue