Skip to content

Commit 2da7e0c

Browse files
authored
Merge pull request #15 from joehachemx/feature/settingsPage
Feature/settings page
2 parents 1174595 + 0ca98a0 commit 2da7e0c

File tree

6 files changed

+79
-58
lines changed

6 files changed

+79
-58
lines changed

.env

Lines changed: 0 additions & 1 deletion
This file was deleted.

Assets/projectLogo.png

23.5 KB
Loading

Controllers/gptController.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
const { Configuration, OpenAIApi } = require("openai");
2-
require("dotenv").config()
2+
const vscode = require('vscode');
3+
4+
const config = vscode.workspace.getConfiguration('documentation-generator-pii');
5+
const apiKey = config.get('apiKey');
36

47
const configuration = new Configuration({
5-
apiKey: "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",
8+
apiKey: apiKey,
69
});
10+
711
const openai = new OpenAIApi(configuration);
812

9-
async function runCompletion (prompt) {
13+
async function runCompletion(prompt) {
1014
const completion = await openai.createCompletion({
1115
model: "text-davinci-003",
1216
prompt: `
@@ -22,7 +26,6 @@ async function runCompletion (prompt) {
2226
max_tokens: 1000,
2327
})
2428

25-
2629
return completion.data.choices[0].text
2730
}
2831

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Logo](./Assets/piiLogo.png)
1+
![Logo](./Assets/projectLogo.png)
22

33
Source code for the documentation-generator-pii extension on VSCode.
44

@@ -39,22 +39,31 @@ Insert gif or link to demo
3939

4040
Search for it in the extension marketplace or click here. *link here*
4141

42+
### Smart Comments Integration
43+
Open the settings view, search for the extension and paste your own API token. You might need to relaunch the extension afterwards.
44+
4245
<br>
4346

4447
## 🐛 Known Issues
4548

46-
kifik
49+
- Formatting bug on some functions
50+
- Parser bugs if the language comment symbol is used in a code snippet
51+
- Comment ID generation might lag
4752

4853
<br>
4954

5055
## 🙅‍♂️ Limitations
5156

52-
ecrire wen c pas bien
57+
- Code becomes unreadable if a toddlers uses the extension
58+
- Syntax of custom comments hard not admirable
59+
- We need custom comments
5360

5461
<br>
5562

5663
## 📝 TODO
5764
- Support HTML and PDF
65+
- More designs
66+
- Bug fixes
5867

5968
<br>
6069

extension.js

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ const folderMD = require('./Controllers/convertToMdFolder');
1212
*/
1313
function activate(context) {
1414
console.log('Extension is now active!');
15-
15+
1616
let disposable = vscode.commands.registerCommand("extension.showTextField", function () {
1717
let editor = vscode.window.activeTextEditor;
1818
vscode.window.showInputBox({
19-
prompt: "Enter your text"
20-
}).then(function (inputText) {
19+
prompt: "Enter your text"
20+
}).then(function (inputText) {
2121
editor.edit(editBuilder => {
2222
if (inputText != undefined) {
2323

@@ -29,22 +29,22 @@ function activate(context) {
2929

3030

3131
if (editor.selection.start.line === editor.selection.end.line) {
32-
inputText = " " + checkLanguage() + " @/w" + `${id}` + " " + inputText
32+
inputText = " " + checkLanguage() + " @/w" + `${id}` + " " + inputText
3333
} else {
3434
inputText = checkLanguage() + " @<r" + `${id}` + " " + inputText
3535
}
3636

3737

3838
closingText = checkLanguage() + " @r>" + `${id}`
39-
39+
4040
let newText;
41-
41+
4242
if (editor.selection.start.line === editor.selection.end.line) {
43-
newText = `${editor.document.getText(editor.selection)}` + `${inputText}`
43+
newText = `${editor.document.getText(editor.selection)}` + `${inputText}`
4444
} else {
4545
newText = `${inputText}` + '\n' + `${editor.document.getText(editor.selection)}` + '\n' + `${closingText}`
4646
}
47-
47+
4848

4949
const selections = editor.selections; // to handle mutliple selection
5050
for (const selection of selections) {
@@ -54,7 +54,7 @@ function activate(context) {
5454
});
5555
});
5656
});
57-
57+
5858
let callParserNConverter = vscode.commands.registerCommand("extension.callParserNConverter", async function () {
5959
console.log("calling parser n converter")
6060

@@ -67,7 +67,7 @@ function activate(context) {
6767

6868
let files = await vscode.workspace.findFiles('**/*.*', '**/node_modules/**');
6969
files = files.sort()
70-
fs.writeFileSync(`${writePath}/markdownfile.md`,"")
70+
fs.writeFileSync(`${writePath}/markdownfile.md`, "")
7171

7272
// folder info if available
7373
async function processFolder() {
@@ -80,24 +80,24 @@ function activate(context) {
8080
console.log(e)
8181
}
8282
}
83-
83+
8484
processFolder()
8585

8686
async function processFiles() {
8787
for (let i = 0; i < files.length; i++) {
88-
let file = files[i].fsPath;
89-
try {
90-
const arrayOfItemCode = await fileParser.fileParser(file, writePath, getFileName(file));
91-
if (arrayOfItemCode != undefined) {
92-
await fileToMD.convertToMDFile(arrayOfItemCode, writePath, getFileName(file));
88+
let file = files[i].fsPath;
89+
try {
90+
const arrayOfItemCode = await fileParser.fileParser(file, writePath, getFileName(file));
91+
if (arrayOfItemCode != undefined) {
92+
await fileToMD.convertToMDFile(arrayOfItemCode, writePath, getFileName(file));
93+
}
94+
} catch (e) {
95+
console.log(e);
9396
}
94-
} catch (e) {
95-
console.log(e);
96-
}
9797
}
98-
}
99-
100-
processFiles();
98+
}
99+
100+
processFiles();
101101
})
102102

103103
let gptAPI = vscode.commands.registerCommand("extension.gptAPI", async function () {
@@ -107,80 +107,80 @@ function activate(context) {
107107

108108
await vscode.window.withProgress({
109109
location: vscode.ProgressLocation.Notification,
110-
title: "Smart Comments ",
110+
title: "Smart Comments",
111111
cancellable: false
112-
}, async (progress) => {
112+
}, async (progress) => {
113113
// simulate a long-running task
114114
progress.report({ message: "Running GPT..." });
115115
await new Promise(resolve => setTimeout(resolve, 100));
116-
116+
117117
if (editor.document.getText(editor.selection).trim() == "") {
118118
progress.report({ increment: 100, message: "Error. Please select something." });
119119
await new Promise(resolve => setTimeout(resolve, 100));
120120
return
121-
}
121+
}
122122

123123
let codeExplication = await gptController.runCompletion(editor.document.getText(editor.selection))
124124

125125
codeExplication = codeExplication.trim()
126-
126+
127127
// update the progress indicator
128128
progress.report({ increment: 50, message: "Processing results..." });
129129
await new Promise(resolve => setTimeout(resolve, 100));
130-
130+
131131
editor.edit(editBuilder => {
132-
132+
133133
let id = Math.floor(Math.random() * (100 - 0 + 1)) + 0
134134
while (id in everyIDGenerated) {
135135
id = Math.floor(Math.random() * (100 - 0 + 1)) + 0
136136
}
137137
everyIDGenerated.push(id)
138-
139-
138+
139+
140140
if (editor.selection.start.line === editor.selection.end.line) {
141-
codeExplication = " " + checkLanguage() + " @/w" + `${id}` + " " + codeExplication
141+
codeExplication = " " + checkLanguage() + " @/w" + `${id}` + " " + codeExplication
142142
} else {
143143
codeExplication = checkLanguage() + " @<r" + `${id}` + " " + codeExplication
144144
}
145145

146146
closingText = checkLanguage() + " @r>" + `${id}`
147-
147+
148148
let newText;
149149

150150
if (editor.selection.start.line === editor.selection.end.line) {
151-
newText = `${editor.document.getText(editor.selection)}` + `${codeExplication}`
151+
newText = `${editor.document.getText(editor.selection)}` + `${codeExplication}`
152152
} else {
153153
newText = `${codeExplication}` + '\n' + `${editor.document.getText(editor.selection)}` + '\n' + `${closingText}`
154154
}
155-
155+
156156
const selections = editor.selections; // to handle mutliple selection
157157
for (const selection of selections) {
158158
editBuilder.replace(selection, newText);
159159
}
160-
160+
161161
})
162-
162+
163163
// update the progress indicator
164164
progress.report({ increment: 50, message: "Done!" });
165165
await new Promise(resolve => setTimeout(resolve, 1000));
166-
})
166+
})
167167
})
168168

169169
let createProjectInfoFile = vscode.commands.registerCommand("extension.createProjectInfoFile", async function () {
170170
console.log("creating project info file")
171171

172172
fs.writeFileSync(`${vscode.workspace.workspaceFolders[0].uri.fsPath}/info.pii`, infoPiiText)
173173
})
174-
174+
175175
// Register the command to the keyboard shortcut
176176
context.subscriptions.push(disposable);
177177
context.subscriptions.push(callParserNConverter);
178178
context.subscriptions.push(gptAPI);
179179
context.subscriptions.push(createProjectInfoFile);
180-
}
180+
}
181181

182182

183-
function deactivate() {}
183+
function deactivate() { }
184184

185185
module.exports = {
186186
activate,
@@ -191,11 +191,11 @@ function checkLanguage() {
191191
// si preferable law zabatit built in mais ca marchait pas pr aucune raison
192192
// a revoir
193193

194-
const editor = vscode.window.activeTextEditor;
194+
const editor = vscode.window.activeTextEditor;
195195
const document = editor.document;
196196
const language = document.languageId
197197

198-
switch(language) {
198+
switch (language) {
199199
case "python":
200200
return "#"
201201
case "ruby":
@@ -219,5 +219,5 @@ function checkLanguage() {
219219

220220
let everyIDGenerated = []
221221

222-
let infoPiiText =
223-
"@title=\"title\"\n\n@version=\"v 1.1.1\"\n@date=\"12/12/12\"\n\n@authors=\"x, y, ghada\"\n@mail=\"x@mail.com, y@mail.com, ghada@mail.com\"\n\n@description=\"this is a description\"\n\n@requirements=\"ios16, windows11\"\n\n@paragraph=\"this is a paragraph\""
222+
let infoPiiText =
223+
"@title=\"title\"\n\n@version=\"v 1.1.1\"\n@date=\"12/12/12\"\n\n@authors=\"x, y, ghada\"\n@mail=\"x@mail.com, y@mail.com, ghada@mail.com\"\n\n@description=\"this is a description\"\n\n@requirements=\"ios16, windows11\"\n\n@paragraph=\"this is a paragraph\""

package.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "pii-documentation-generator",
3-
"displayName": "pii-documentation-generator",
4-
"description": "",
5-
"version": "0.0.1",
2+
"name": "documentation-generator-pii",
3+
"displayName": "Documentation Generator PII",
4+
"description": "Generates a documentation from comments + GPT integration for smart comments",
5+
"version": "1.0.0",
66
"engines": {
77
"vscode": "^1.75.0"
88
},
@@ -48,7 +48,17 @@
4848
"mac": "cmd+shift+i",
4949
"linux": "ctrl+shift+i"
5050
}
51-
]
51+
],
52+
"configuration": {
53+
"title": "Documentation Generator PII",
54+
"properties": {
55+
"documentation-generator-pii.apiKey": {
56+
"type": "string",
57+
"default": "",
58+
"description": "API key"
59+
}
60+
}
61+
}
5262
},
5363
"scripts": {
5464
"lint": "eslint .",

0 commit comments

Comments
 (0)