support commitmsg code block

This commit is contained in:
bobo.yang 2023-05-04 07:27:26 +08:00
parent 7667ab9431
commit ef8f2a461e
6 changed files with 26 additions and 5 deletions

View File

@ -5,5 +5,6 @@ As a software developer assistant, your task is to provide clear and concise res
3. Enclose messages in code blocks using triple backticks (```).
4. Utilize the <context>, if provided, to create the summary.
5. Utilize the previous messages, if provided in the end of this prompt, to create the summary. Note that not all previous messages are necessarily relevant.
6. Please output commit message in a markdown code block, flag as commitmsg type.
If you need more information, feel free to ask.

View File

@ -7,6 +7,7 @@ import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { promisify } from 'util';
import ExtensionContextHolder from './extensionContext';
const mkdirAsync = promisify(fs.mkdir);
const execAsync = promisify(exec);
@ -53,6 +54,9 @@ export const commitMessageCommand: Command = {
const diff_file = path.join(tempDir, 'diff_output.txt');
await writeDiffFile(diff_file);
return `[instruction|./commonInstructions.txt] [instruction|./commitMessageCommandInstructions.txt] [context|${diff_file}] Write a commit message`;
const commonInstructions = vscode.Uri.joinPath(ExtensionContextHolder.context?.extensionUri as vscode.Uri, 'instructions/commonInstructions.txt');
const commitMsgInstructions = vscode.Uri.joinPath(ExtensionContextHolder.context?.extensionUri as vscode.Uri, 'instructions/commitMessageCommandInstructions.txt');
return `[instruction|${commonInstructions.path}] [instruction|${commitMsgInstructions.path}] [context|${diff_file}] Write a commit message`;
},
};

View File

@ -1,11 +1,12 @@
const vscode = require('vscode');
import * as vscode from 'vscode';
const ChatPanel = require('./chatPanel').default;
const sendFileSelectMessage = require('./messageHandler').sendFileSelectMessage;
const sendCodeSelectMessage = require('./messageHandler').sendCodeSelectMessage;
const askAI = require('./messageHandler').askAI;
import ExtensionContextHolder from './extensionContext';
function activate(context: { extensionUri: any; subscriptions: any[]; }) {
function activate(context: vscode.ExtensionContext) {
ExtensionContextHolder.context = context;
let disposable = vscode.commands.registerCommand('devchat.openChatPanel', () => {
if (vscode.workspace.workspaceFolders) {
ChatPanel.createOrShow(context.extensionUri);

15
src/extensionContext.ts Normal file
View File

@ -0,0 +1,15 @@
import * as vscode from 'vscode';
class ExtensionContextHolder {
private static _context: vscode.ExtensionContext | undefined;
static set context(context: vscode.ExtensionContext | undefined) {
this._context = context;
}
static get context(): vscode.ExtensionContext | undefined {
return this._context;
}
}
export default ExtensionContextHolder;

View File

@ -97,7 +97,7 @@ async function handleMessage(
chatOptions.context = parsedMessage.context;
}
if (parsedMessage.instruction.length > 0) {
chatOptions.instruction = parsedMessage.instruction;
chatOptions.header = parsedMessage.instruction;
}
if (parsedMessage.reference.length > 0) {
chatOptions.reference = parsedMessage.reference;