-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextension.js
More file actions
72 lines (62 loc) · 2.45 KB
/
extension.js
File metadata and controls
72 lines (62 loc) · 2.45 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
const vscode = require('vscode');
const parsers = require('./parsers');
const FlowchartPanel = require('./flowchartPanel');
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
console.log('Code to Flowchart extension is now active');
let disposable = vscode.commands.registerCommand('code-to-flowchart.generateFlowchart', async function () {
// Get the active text editor
const editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showInformationMessage('No code file is open');
return;
}
const document = editor.document;
const fileName = document.fileName;
const fileContent = document.getText();
const fileExtension = fileName.split('.').pop().toLowerCase();
// Determine the language based on file extension
let language;
switch (fileExtension) {
case 'py':
language = 'python';
break;
case 'cs':
language = 'csharp';
break;
case 'js':
case 'jsx':
case 'ts':
case 'tsx':
if (fileContent.includes('React') || fileContent.includes('react') ||
fileContent.includes('jsx') || fileExtension === 'jsx' || fileExtension === 'tsx') {
language = 'react';
} else if (fileContent.includes('Angular') || fileContent.includes('angular') ||
fileContent.includes('@Component')) {
language = 'angular';
} else {
language = 'javascript';
}
break;
default:
vscode.window.showInformationMessage('Unsupported file type. Supported languages: Python, C#, React, Angular');
return;
}
try {
// Parse the code according to its language
const flowchartDefinition = parsers.parseCode(fileContent, language);
// Create and show the flowchart panel
FlowchartPanel.createOrShow(context.extensionUri, flowchartDefinition, fileName);
} catch (error) {
vscode.window.showErrorMessage(`Error generating flowchart: ${error.message}`);
}
});
context.subscriptions.push(disposable);
}
function deactivate() {}
module.exports = {
activate,
deactivate
};