-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
66 lines (52 loc) · 1.83 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const axios = require('axios');
const vscode = require('vscode');
const simpleGit = require('simple-git');
const fs = require('fs');
const path = require('path');
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
const disposable = vscode.commands.registerCommand('gen-com.generateCommit', async function () {
// vscode.window.showInformationMessage('Hello World from gen-com!');
try {
const workspaceFolder = vscode.workspace.workspaceFolders;
console.log('Workspace Folder:', workspaceFolder);
if (!workspaceFolder || workspaceFolder.length === 0) {
vscode.window.showErrorMessage('No workspace folder found');
return;
}
const workspacePath = workspaceFolder[0].uri.fsPath;
const normalizedWorkspacePath = path.normalize(workspacePath);
process.chdir(normalizedWorkspacePath);
const git = simpleGit(normalizedWorkspacePath);
const diff = await git.diff()
const commitMessage = await queryModel(diff);
// Display the generated commit message
vscode.window.showInformationMessage('Generated Commit Message:\n' + commitMessage);
// Copy the commit message to the clipboard
await vscode.env.clipboard.writeText(commitMessage);
vscode.window.showInformationMessage('Commit message copied to clipboard!');
} catch (error) {
vscode.window.showErrorMessage('Error getting diff: ' + error.message);
}
});
context.subscriptions.push(disposable);
}
const queryModel = async (diff) => {
try {
const response = await axios.post('http://localhost:3030/api/generate', {
diff: diff,
})
return response.data;
} catch (error) {
console.error('Error generating commit message:', error);
return 'Error generating commit message';
}
}
// This method is called when your extension is deactivated
function deactivate() {}
module.exports = {
activate,
deactivate
}