-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
76 lines (55 loc) · 1.84 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
67
68
69
70
71
72
73
74
75
76
const vscode = require('vscode');
const jsdoc = require('jsdoc-api');
function activate(context) {
let disposable = vscode.commands.registerCommand('docguide.generateDocs', function () {
// command registered
const editor = vscode.window.activeTextEditor;
if (editor) {
const document = editor.document;
const text = document.getText();
jsdoc.explain({ source: text }).then(docs => {
const markdown = generateMarkdown(docs);
const docPanel = vscode.window.createWebviewPanel(
'documentation',
'Generated Documentation',
vscode.ViewColumn.One,
{}
);
docPanel.webview.html = getWebviewContent(markdown);
}).catch(error => {
vscode.window.showErrorMessage('Error generating documentation: ' + error.message);
});
} else {
vscode.window.showInformationMessage('No active editor found! okay gudu');
}
});
context.subscriptions.push(disposable);
}
vscode.commands.getCommands().then(commands => {
console.log(commands);
});
function generateMarkdown(docs) {
let markdown = '# Documentation\n\n';
docs.forEach(doc => {
markdown += `## ${doc.longname}\n${doc.description}\n\n`;
});
return markdown;
}
function getWebviewContent(markdown) {
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Generated Documentation</title>
</head>
<body>
${markdown}
</body>
</html>`;
}
function deactivate() {}
module.exports = {
activate,
deactivate
};