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