✨ context menu actions for common edits

This commit is contained in:
Nate Sesti 2023-12-31 13:11:37 -05:00
parent ad840c2e63
commit 0c98cbb393
3 changed files with 57 additions and 13 deletions

View file

@ -132,6 +132,26 @@
"category": "Continue",
"title": "View History",
"icon": "$(history)"
},
{
"command": "continue.writeCommentsForCode",
"category": "Continue",
"title": "Write Comments for this Code"
},
{
"command": "continue.writeDocstringForCode",
"category": "Continue",
"title": "Write a Docstring for this Code"
},
{
"command": "continue.fixCode",
"category": "Continue",
"title": "Fix this Code"
},
{
"command": "continue.optimizeCode",
"category": "Continue",
"title": "Optimize this Code"
}
],
"keybindings": [
@ -198,12 +218,27 @@
],
"continue.continueSubMenu": [
{
"command": "continue.focusContinueInput",
"when": "editorHasSelection",
"group": "Continue"
"command": "continue.focusContinueInputWithoutClear",
"group": "Continue",
"when": "editorHasSelection"
},
{
"command": "continue.focusContinueInputWithoutClear",
"command": "continue.writeCommentsForCode",
"group": "Continue",
"when": "editorHasSelection"
},
{
"command": "continue.writeDocstringForCode",
"group": "Continue",
"when": "editorHasSelection"
},
{
"command": "continue.fixCode",
"group": "Continue",
"when": "editorHasSelection"
},
{
"command": "continue.optimizeCode",
"group": "Continue",
"when": "editorHasSelection"
}

View file

@ -115,6 +115,18 @@ const commandsMap: { [command: string]: (...args: any) => any } = {
await streamEdit(text);
}
},
"continue.writeCommentsForCode": async () => {
await streamEdit("Write comments for this code");
},
"continue.writeDocstringForCode": async () => {
await streamEdit("Write a docstring for this code");
},
"continue.fixCode": async () => {
await streamEdit("Fix this code");
},
"continue.optimizeCode": async () => {
await streamEdit("Optimize this code");
},
"continue.viewLogs": async () => {
// Open ~/.continue/continue.log
const logFile = path.join(os.homedir(), ".continue", "continue.log");

View file

@ -178,6 +178,10 @@ export class VerticalPerLineDiffHandler {
]);
}
}
initialize() {
this.updateIndexLineDecorations();
}
}
class VerticalPerLineDiffManager {
@ -257,20 +261,13 @@ export async function streamEdit(input: string) {
editor.selection.active
);
diffHandler.initialize();
for await (const diffLine of streamDiffLines(rangeContent, llm, input)) {
if (diffHandler.isCancelled) {
break;
}
console.log(
(diffLine.type === "new"
? "+ "
: diffLine.type === "old"
? "- "
: " ") + diffLine.line
);
await diffHandler.handleDiffLine(diffLine);
}
}
// Shortcuts to accept / reject
}