Update DevChat commands and add comment generation
This commit is contained in:
parent
19b1280222
commit
5be13ca16c
20
package.json
20
package.json
@ -671,11 +671,19 @@
|
||||
},
|
||||
{
|
||||
"command": "devchat.explain",
|
||||
"title": "Explain"
|
||||
"title": "Generate Explain"
|
||||
},
|
||||
{
|
||||
"command": "devchat.explain_chinese",
|
||||
"title": "代码解释"
|
||||
},
|
||||
{
|
||||
"command": "devchat.comments",
|
||||
"title": "Generate Comments"
|
||||
},
|
||||
{
|
||||
"command": "devchat.comments_chinese",
|
||||
"title": "生成注释"
|
||||
}
|
||||
],
|
||||
"keybindings": [
|
||||
@ -769,6 +777,16 @@
|
||||
"command": "devchat.explain_chinese",
|
||||
"when": "isChineseLocale && editorTextFocus && editorHasSelection",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "devchat.comments",
|
||||
"when": "!isChineseLocale && editorTextFocus && editorHasSelection",
|
||||
"group": "navigation"
|
||||
},
|
||||
{
|
||||
"command": "devchat.comments_chinese",
|
||||
"when": "isChineseLocale && editorTextFocus && editorHasSelection",
|
||||
"group": "navigation"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -462,11 +462,9 @@ export function registerDevChatChatCommand(context: vscode.ExtensionContext) {
|
||||
context.subscriptions.push(disposable);
|
||||
}
|
||||
|
||||
export function registerCodeLensExplainCommand(
|
||||
context: vscode.ExtensionContext
|
||||
) {
|
||||
export function registerCodeLensRangeCommand(context: vscode.ExtensionContext) {
|
||||
let disposable = vscode.commands.registerCommand(
|
||||
"CodeLens.Explain",
|
||||
"CodeLens.Range",
|
||||
async (message: string, pos: { start: number; end: number }) => {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (editor) {
|
||||
@ -550,10 +548,30 @@ function registerExplainCommand(context: vscode.ExtensionContext) {
|
||||
);
|
||||
}
|
||||
|
||||
function registerCommentCommand(context: vscode.ExtensionContext) {
|
||||
const callback = async () => {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (editor) {
|
||||
if (!(await ensureChatPanel(context))) {
|
||||
return;
|
||||
}
|
||||
|
||||
chatWithDevChat(ExtensionContextHolder.provider?.view()!, "/comments");
|
||||
}
|
||||
};
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand("devchat.comments", callback)
|
||||
);
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand("devchat.comments_chinese", callback)
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
registerOpenChatPanelCommand,
|
||||
registerAddContextCommand,
|
||||
registerAskForCodeCommand,
|
||||
registerAskForFileCommand,
|
||||
registerExplainCommand,
|
||||
registerCommentCommand,
|
||||
};
|
||||
|
@ -15,7 +15,8 @@ import {
|
||||
registerDevChatChatCommand,
|
||||
registerHandleUri,
|
||||
registerExplainCommand,
|
||||
registerCodeLensExplainCommand,
|
||||
registerCodeLensRangeCommand,
|
||||
registerCommentCommand,
|
||||
} from "./contributes/commands";
|
||||
import { regLanguageContext } from "./contributes/context";
|
||||
import { regDevChatView } from "./contributes/views";
|
||||
@ -441,6 +442,7 @@ async function activate(context: vscode.ExtensionContext) {
|
||||
registerAskForCodeCommand(context);
|
||||
registerAskForFileCommand(context);
|
||||
registerExplainCommand(context);
|
||||
registerCommentCommand(context);
|
||||
registerStatusBarItemClickCommand(context);
|
||||
|
||||
registerInstallCommandsCommand(context);
|
||||
@ -453,7 +455,7 @@ async function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
regPythonPathCommand(context);
|
||||
registerDevChatChatCommand(context);
|
||||
registerCodeLensExplainCommand(context);
|
||||
registerCodeLensRangeCommand(context);
|
||||
registerCodeLensProvider(context);
|
||||
|
||||
startRpcServer();
|
||||
|
@ -54,15 +54,20 @@ export class CodeLensManager {
|
||||
this.registrations = [
|
||||
{
|
||||
elementType: "function",
|
||||
objectName: "Add unit tests",
|
||||
objectName: "unit tests",
|
||||
promptGenerator:
|
||||
"/unit_tests {__filename__}:::{__functionName__}:::{__functionStartLine__}:::{__functionEndLine__}:::{__containerStartLine__}:::{__containerEndLine__}",
|
||||
},
|
||||
{
|
||||
elementType: "function",
|
||||
objectName: "Explain",
|
||||
objectName: "explain",
|
||||
promptGenerator: "/explain",
|
||||
},
|
||||
{
|
||||
elementType: "function",
|
||||
objectName: "docstring",
|
||||
promptGenerator: "/docstring",
|
||||
},
|
||||
// {
|
||||
// elementType: 'function',
|
||||
// objectName: 'generate unit tests',
|
||||
@ -212,10 +217,13 @@ class FunctionTestCodeLensProvider implements vscode.CodeLensProvider {
|
||||
`${parentRange ? parentRange.end.line : -1}`
|
||||
)
|
||||
.replace(/{__functionCode__}/g, functionCode); // Fixed syntax to replace all occurrences
|
||||
if (codelenRegister.objectName === "Explain") {
|
||||
if (
|
||||
codelenRegister.objectName === "explain" ||
|
||||
codelenRegister.objectName === "docstring"
|
||||
) {
|
||||
const lens = new vscode.CodeLens(range, {
|
||||
title: codelenRegister.objectName,
|
||||
command: "CodeLens.Explain",
|
||||
command: "CodeLens.Range",
|
||||
// arguments: [document.uri.fsPath, range, funcDef.name] // Commented out as it's not used
|
||||
arguments: [
|
||||
prompt,
|
||||
|
Loading…
x
Reference in New Issue
Block a user