-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
135 lines (109 loc) · 5.58 KB
/
extension.js
File metadata and controls
135 lines (109 loc) · 5.58 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const vscode = require('vscode');
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
function activate(context) {
// Existing command: Create multiple C++ files
let createFilesCommand = vscode.commands.registerCommand('themzway.createFiles', async () => {
const numFilesInput = await vscode.window.showInputBox({
prompt: 'Enter the number of files to create',
value: ''
});
const numFiles = numFilesInput && !isNaN(Number(numFilesInput)) ? Number(numFilesInput) : 1;
const workspaceFolders = vscode.workspace.workspaceFolders;
if (workspaceFolders) {
const rootPath = workspaceFolders[0].uri.fsPath;
for (let i = 1; i <= numFiles; ++i) {
const fileName = path.join(rootPath, `Ques_${i}.java`);
const fileContent = `#include <iostream>\nusing namespace std;\n\nint main() {\n return 0;\n}`;
fs.writeFileSync(fileName, fileContent);
}
vscode.window.showInformationMessage(`${numFiles} file(s) created successfully.`);
} else {
vscode.window.showErrorMessage('No workspace folder is open.');
}
});
// Renamed command: Practice (previously ama)
let practiceCommand = vscode.commands.registerCommand('themzway.practice', async () => {
const levels = ['Beginner', 'Intermediate', 'Expert'];
const selectedLevel = await vscode.window.showQuickPick(levels, {
placeHolder: 'Select the difficulty level'
});
if (!selectedLevel) {
vscode.window.showErrorMessage('Please select a difficulty level.');
return;
}
const numQuestionsInput = await vscode.window.showInputBox({
prompt: `Enter the number of ${selectedLevel} questions to generate`,
value: ''
});
const numQuestions = numQuestionsInput && !isNaN(Number(numQuestionsInput)) ? Number(numQuestionsInput) : 1;
const workspaceFolders = vscode.workspace.workspaceFolders;
if (workspaceFolders) {
const rootPath = workspaceFolders[0].uri.fsPath;
for (let i = 1; i <= numQuestions; ++i) {
const prompt = `Generate ${selectedLevel} level programming question in C++ ${i}`;
const response = execSync(`curl http://localhost:11434/api/generate -d '{"model": "gemma3:4b", "prompt": "${prompt}", "stream": false}'`, { encoding: 'utf8' });
const responseObject = JSON.parse(response);
const question = responseObject.response;
const fileName = path.join(rootPath, `${selectedLevel}_Ques_${i}.cpp`);
const fileContent = `// ${question}\n#include <iostream>\nusing namespace std;\n\nint main() {\n return 0;\n}`;
fs.writeFileSync(fileName, fileContent);
}
vscode.window.showInformationMessage(`${numQuestions} ${selectedLevel} question file(s) created successfully.`);
} else {
vscode.window.showErrorMessage('No workspace folder is open.');
}
});
// New command: Ask Me Anything
let amaCommand = vscode.commands.registerCommand('themzway.ama', async () => {
const prompt = await vscode.window.showInputBox({
prompt: 'Enter your programming question/prompt',
placeHolder: 'e.g., Write a program to find factorial of a number'
});
if (!prompt) {
vscode.window.showErrorMessage('Please provide a prompt.');
return;
}
const workspaceFolders = vscode.workspace.workspaceFolders;
if (workspaceFolders) {
try {
// Get summary for folder name
const summaryPrompt = `Give a 3 word summary of this, separated by underscores: ${prompt}`;
const summaryResponse = execSync(`curl http://localhost:11434/api/generate -d '{"model": "gemma3:4b", "prompt": "${summaryPrompt}", "stream": false}'`, { encoding: 'utf8' });
const summaryObject = JSON.parse(summaryResponse);
const folderName = summaryObject.response.trim().replace(/[^a-zA-Z_]/g, '');
// Get code solution
const codePrompt = `Write a complete code solution for this problem: ${prompt}`;
const codeResponse = execSync(`curl http://localhost:11434/api/generate -d '{"model": "gemma3:4b", "prompt": "${codePrompt}", "stream": false}'`, { encoding: 'utf8' });
const codeObject = JSON.parse(codeResponse);
const code = codeObject.response;
// Create folder and file
const folderPath = path.join(workspaceFolders[0].uri.fsPath, folderName);
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath);
}
const fileName = path.join(folderPath, 'solution.md');
const fileContent = `/*
Problem Statement:
${prompt}
*/
${code}`;
fs.writeFileSync(fileName, fileContent);
vscode.window.showInformationMessage('Solution created successfully!');
} catch (error) {
vscode.window.showErrorMessage(`Error: ${error.message}`);
}
} else {
vscode.window.showErrorMessage('No workspace folder is open.');
}
});
context.subscriptions.push(createFilesCommand);
context.subscriptions.push(practiceCommand);
context.subscriptions.push(amaCommand);
}
function deactivate() {}
module.exports = {
activate,
deactivate
};