-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
156 lines (141 loc) · 4.62 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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const vscode = require('vscode');
const net = require('net');
const fs = require('fs');
const path = require('path');
function activate(context) {
// Register the command for simulate debugging
context.subscriptions.push(
vscode.debug.registerDebugAdapterDescriptorFactory('darkbasic', {
createDebugAdapterDescriptor: (session) => {
return new vscode.DebugAdapterExecutable('node', [`${context.extensionPath}/dummyDebugAdapter.js`]);
},
})
);
// Register the command for generating configuration files
context.subscriptions.push(
vscode.commands.registerCommand('darkbasic.generateConfigFiles', async () => {
const workspaceFolders = vscode.workspace.workspaceFolders;
if (!workspaceFolders || workspaceFolders.length === 0) {
vscode.window.showErrorMessage('Please open a workspace before generating configuration files.');
return;
}
// DarkBASIC compiler executable
vscode.window.showInformationMessage('Please select the DarkBASIC compiler EXE file.');
const selectedWorkspaceFolder = workspaceFolders[0].uri.fsPath;
const dbCompiler = await vscode.window.showOpenDialog({
title: 'Please select a DarkBASIC compiler executable',
canSelectFiles: true,
canSelectFolders: false,
canSelectMany: false,
filters: {
'DarkBASIC compiler': ['exe'],
},
});
if (!dbCompiler) {
vscode.window.showErrorMessage('DarkBASIC compiler path is required.');
return;
}
const dbCompilerPathUnfixed = dbCompiler[0].fsPath;
const dbCompilerPath = dbCompilerPathUnfixed.replace(/\\/g, '\\\\');
// Default main DBA file to compile
vscode.window.showInformationMessage("Please select the main source file (Press 'cancel' to execute opened file each time).");
const dbaFile = await vscode.window.showOpenDialog({
title: "Please select the main source file",
canSelectFiles: true,
canSelectFolders: false,
canSelectMany: false,
filters: {
'DarkBASIC Main Source File': ['dba'],
},
});
const mainDbaPathUnfixed = dbaFile ? dbaFile[0].fsPath : '${file}';
const mainDbaPath = mainDbaPathUnfixed.replace(/\\/g, '\\\\');
const tasksJsonContent = `{
"version": "2.0.0",
"tasks": [
{
"label": "Compile",
"type": "shell",
"command": "${dbCompilerPath}",
"args": [
"-c",
"${mainDbaPath}"
],
"group": "none",
"presentation": {
"reveal": "always"
},
"problemMatcher": []
},
{
"label": "Display Compiler Log",
"type": "shell",
"command": "type DBCompile.log", // Use "cat DBCompiler.log" on macOS and Linux
"group": "none",
"problemMatcher": []
},
{
"label": "Compile and Display Log",
"dependsOrder": "sequence",
"dependsOn": ["Compile", "Display Compiler Log"],
"group": "build",
"problemMatcher": []
},
{
"label": "Compile and Execute",
"type": "shell",
"command": "${dbCompilerPath}",
"args": [
"-x",
"${mainDbaPath}"
],
"group": "none",
"presentation": {
"reveal": "always"
},
"problemMatcher": []
},
{
"label": "Compile and Execute then Display Log",
"dependsOrder": "sequence",
"dependsOn": ["Compile and Execute", "Display Compiler Log"],
"group": "test",
"problemMatcher": []
}
]
}`;
const launchJsonContent = `{
"version": "0.2.0",
"configurations": [
{
"name": "DarkBASIC execution",
"type": "darkbasic",
"request": "launch",
"preLaunchTask": "Compile and Execute"
}
]
}`;
const vscodeFolderPath = path.join(selectedWorkspaceFolder, '.vscode');
if (!fs.existsSync(vscodeFolderPath)) {
fs.mkdirSync(vscodeFolderPath);
}
fs.writeFileSync(path.join(vscodeFolderPath, 'tasks.json'), tasksJsonContent);
fs.writeFileSync(path.join(vscodeFolderPath, 'launch.json'), launchJsonContent);
vscode.window.showInformationMessage('DarkBASIC configuration files have been generated.');
})
);
// Event listener for when the debug session is terminated
vscode.debug.onDidTerminateDebugSession(async (session) => {
if (session.type === 'darkbasic') {
const debugConfiguration = session.configuration;
if (debugConfiguration.preLaunchTask === 'Compile and Execute then Display Log') {
vscode.commands.executeCommand('workbench.action.debug.stop');
}
}
});
}
function deactivate() {}
module.exports = {
activate,
deactivate,
};