add doCommit message
This commit is contained in:
parent
a4e96e1d57
commit
8366a8eea6
51
src/dtm.ts
51
src/dtm.ts
@ -1,11 +1,6 @@
|
||||
// dtm.ts
|
||||
|
||||
import { exec } from "child_process";
|
||||
import { promisify } from "util";
|
||||
import { spawn } from "child_process";
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
interface DtmResponse {
|
||||
status: number;
|
||||
message: string;
|
||||
@ -19,21 +14,45 @@ class DtmWrapper {
|
||||
this.workspaceDir = vscode.workspace.workspaceFolders?.[0].uri.fsPath || '.';
|
||||
}
|
||||
|
||||
async scaffold(directoryTree: string): Promise<DtmResponse> {
|
||||
const { stdout } = await execAsync(`dtm scaffold "${directoryTree}" -o json`, {
|
||||
cwd: this.workspaceDir,
|
||||
private async runCommand(command: string, args: string[]): Promise<DtmResponse> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn(command, args, { cwd: this.workspaceDir });
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
|
||||
child.stdout.on('data', (data) => {
|
||||
stdout += data;
|
||||
});
|
||||
return JSON.parse(stdout.trim());
|
||||
|
||||
child.stderr.on('data', (data) => {
|
||||
stderr += data;
|
||||
});
|
||||
|
||||
child.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
resolve(JSON.parse(stdout.trim()));
|
||||
} else {
|
||||
reject(JSON.parse(stdout.trim()));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async scaffold(directoryTree: string): Promise<DtmResponse> {
|
||||
return await this.runCommand('dtm', ['scaffold', directoryTree, '-o', 'json']);
|
||||
}
|
||||
|
||||
async patch(patchFilePath: string): Promise<DtmResponse> {
|
||||
return await this.runCommand('dtm', ['patch', patchFilePath, '-o', 'json']);
|
||||
}
|
||||
|
||||
async commit(commitMsg: string): Promise<DtmResponse> {
|
||||
try {
|
||||
const { stdout } = await execAsync(`dtm patch ${patchFilePath} -o json`, {
|
||||
cwd: this.workspaceDir,
|
||||
});
|
||||
return JSON.parse(stdout.trim());
|
||||
} catch (e) {
|
||||
return JSON.parse((e as Error & { stdout: string }).stdout.trim());
|
||||
return await this.runCommand('dtm', ['commit', '-m', commitMsg, '-o', 'json']);
|
||||
} catch (error) {
|
||||
// 处理异常
|
||||
console.error('Error in commit:', error);
|
||||
return {'status': -1, 'message': 'exception error', 'log': 'exception error'};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ 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: vscode.ExtensionContext) {
|
||||
|
@ -148,6 +148,14 @@ async function handleMessage(
|
||||
const newText = await CommandManager.getInstance().processText(message.text);
|
||||
panel.webview.postMessage({ command: 'convertCommand', result: newText });
|
||||
return;
|
||||
case 'doCommit':
|
||||
const commitResult = await dtmWrapper.commit(message.content);
|
||||
if (commitResult.status === 0) {
|
||||
vscode.window.showInformationMessage('Commit successfully.');
|
||||
} else {
|
||||
vscode.window.showErrorMessage(`Error commit fail: ${commitResult.message} ${commitResult.log}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user