Skip to content

Commit 52c2bcf

Browse files
committed
✨ add support for custom ASM action
1 parent c94279c commit 52c2bcf

File tree

12 files changed

+170
-166
lines changed

12 files changed

+170
-166
lines changed

package.json

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,48 @@
133133
},
134134
"masmtasm.ASM.actions": {
135135
"type": "object",
136+
"additionalProperties": {
137+
"type": "object",
138+
"properties": {
139+
"baseBundle": {
140+
"type": "string",
141+
"description": "The jsdos bundle of assembler tools"
142+
},
143+
"support": {
144+
"type": "array",
145+
"description": "The supported emulators. By default is `dosbox(-x)` and `jsdos`",
146+
"items": {
147+
"type": "string"
148+
}
149+
},
150+
"before": {
151+
"type": "array",
152+
"description": "The commands to exec in open emulator and before `run` or `debug` the code",
153+
"items": {
154+
"type": "string"
155+
}
156+
},
157+
"run": {
158+
"type": "array",
159+
"description": "The commands to run the code, add a `>` before the command if you need to prevent redirect the command's output",
160+
"items": {
161+
"type": "string"
162+
}
163+
},
164+
"debug": {
165+
"type": "array",
166+
"description": "The commands to debug the code",
167+
"items": {
168+
"type": "string"
169+
}
170+
}
171+
},
172+
"required": [
173+
"baseBundle",
174+
"run",
175+
"debug"
176+
]
177+
},
136178
"default": {
137179
"TASM": {
138180
"baseBundle": "<built-in>/TASM.jsdos",
@@ -142,7 +184,7 @@
142184
"run": [
143185
"TASM ${file}",
144186
"TLINK ${filename}",
145-
"${filename}"
187+
">${filename}"
146188
],
147189
"debug": [
148190
"TASM /zi ${file}",
@@ -180,6 +222,12 @@
180222
"masm ${file};",
181223
"link ${filename}.OBJ;",
182224
">debug ${filename}.exe"
225+
],
226+
"support": [
227+
"jsdos",
228+
"dosbox",
229+
"dosboxX",
230+
"msdos player"
183231
]
184232
}
185233
}

package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"command.cleanalldianose": "MASM/TASM: Clean all diagnose information generated by the extension",
66
"config.mode.singleFile": "copy your file to a seperate space, and do actions there",
77
"config.mode.workspace": "do actions in the current workspace folder\n\n- use `mount` for dosbox and dosbox-x,copy all files in workspace folder for jsdos\n- follow 8.3 filename rule",
8-
"config.assembler.description": "use TASM or MASM to operate your assembly codes",
8+
"config.assembler.description": "use TASM or MASM to operate your assembly codes\n\n should be the key of #masmtasm.ASM.actions#",
99
"config.emulator.description": "DOS environment emulator",
1010
"config.emulator.jsdos": "Use jsdos(wdosbox), run in webview",
1111
"config.emulator.dosbox": "Use DOSBox",

src/ASM/actions.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/ASM/main.ts

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ import { getFiles } from './util';
1212

1313
const fs = vscode.workspace.fs;
1414

15-
type ACTIONS = {
16-
[id: string]: {
17-
baseBundle: string,
18-
before: string[],
19-
run: string[],
20-
debug: string[]
21-
}
22-
};
23-
2415
export interface AsmResult {
2516
message?: string,
2617
error?: number,
@@ -65,20 +56,14 @@ export async function activate(context: vscode.ExtensionContext) {
6556
await emptyFolder(assemblyToolsFolder.fsPath);
6657
await emptyFolder(seperateSpaceFolder.fsPath);
6758

68-
const actions: ACTIONS | undefined = extConfig.get('ASM.actions');
69-
if (actions === undefined) {
70-
throw new Error("configurate `masmtasm.ASM.actions` first");
71-
}
72-
const action = actions[conf.extConf.asmType];
73-
7459
const doc = await vscode.workspace.openTextDocument(_uri);
7560
if (doc.isDirty && extConfig.get('ASM.savefirst')) {
7661
await doc.save();
7762
}
7863

7964
const bundlePath = vscode.Uri.joinPath(
8065
context.extensionUri,
81-
action["baseBundle"].replace('<built-in>/', "resources/")
66+
conf.extConf.action["baseBundle"].replace('<built-in>/', "resources/")
8267
);
8368
const bundle = await fs.readFile(bundlePath);
8469

@@ -95,9 +80,12 @@ export async function activate(context: vscode.ExtensionContext) {
9580
const autoexec = [
9681
`mount c "${assemblyToolsFolder.fsPath}""`,
9782
`mount d "${folder.fsPath}""`,
98-
'd:',
99-
...action.before
83+
'd:'
10084
];
85+
const before = conf.extConf.action.before;
86+
if (before) {
87+
autoexec.push(...before);
88+
}
10189
const logUri = vscode.Uri.joinPath(assemblyToolsFolder, logFilename);
10290
if (nodefs.existsSync(logUri.fsPath)) {
10391
await fs.delete(logUri);
@@ -112,10 +100,10 @@ export async function activate(context: vscode.ExtensionContext) {
112100
return r + " >>C:\\" + logFilename;
113101
}
114102
if (act === conf.actionType.run) {
115-
autoexec.push(...action.run.map(cb));
103+
autoexec.push(...conf.extConf.action.run.map(cb));
116104
}
117105
if (act === conf.actionType.debug) {
118-
autoexec.push(...action.debug.map(cb));
106+
autoexec.push(...conf.extConf.action.debug.map(cb));
119107
}
120108

121109
const box = conf.extConf.emulator === conf.DosEmulatorType.dosboxX ? api.dosboxX : api.dosbox;
@@ -189,9 +177,12 @@ export async function activate(context: vscode.ExtensionContext) {
189177
const autoexec = [
190178
`mount c .`,
191179
`mount d ./code`,
192-
'd:',
193-
...action.before
180+
'd:'
194181
];
182+
const before = conf.extConf.action.before;
183+
if (before) {
184+
autoexec.push(...before);
185+
}
195186
function cb(val: string) {
196187
const r = val
197188
.replace("${file}", fileInfo.base)
@@ -202,10 +193,10 @@ export async function activate(context: vscode.ExtensionContext) {
202193
return r;
203194
}
204195
if (act === conf.actionType.run) {
205-
autoexec.push(...action.run.map(cb));
196+
autoexec.push(...conf.extConf.action.run.map(cb));
206197
}
207198
if (act === conf.actionType.debug) {
208-
autoexec.push(...action.debug.map(cb));
199+
autoexec.push(...conf.extConf.action.debug.map(cb));
209200
}
210201
api.jsdos.updateAutoexec(autoexec);
211202
const webview = await api.jsdos.runInWebview();
@@ -227,11 +218,15 @@ export async function activate(context: vscode.ExtensionContext) {
227218

228219
terminal.show();
229220
api.dosbox.fromBundle(bundle, assemblyToolsFolder);
230-
action.before.forEach(
231-
val => {
232-
(terminal as vscode.Terminal).sendText(val.replace('C:', assemblyToolsFolder.fsPath));
233-
}
234-
);
221+
const { before, run, debug } = conf.extConf.action;
222+
if (before) {
223+
before.forEach(
224+
val => {
225+
(terminal as vscode.Terminal).sendText(val.replace('C:', assemblyToolsFolder.fsPath));
226+
}
227+
);
228+
}
229+
235230
if (act === conf.actionType.open) {
236231
terminal.sendText(`cd "${vscode.Uri.joinPath(_uri, '..').fsPath}"`);
237232
}
@@ -248,10 +243,10 @@ export async function activate(context: vscode.ExtensionContext) {
248243
}
249244
}
250245
if (act === conf.actionType.run) {
251-
action.run.map(cb).forEach(val => (terminal as vscode.Terminal).sendText(val));
246+
run.map(cb).forEach(val => (terminal as vscode.Terminal).sendText(val));
252247
}
253248
if (act === conf.actionType.debug) {
254-
action.debug.map(cb).forEach(val => (terminal as vscode.Terminal).sendText(val));
249+
debug.map(cb).forEach(val => (terminal as vscode.Terminal).sendText(val));
255250
}
256251
const logUri = vscode.Uri.joinPath(folder, logFilename);
257252
const [hook, promise] = messageCollector();
@@ -298,11 +293,7 @@ export async function activate(context: vscode.ExtensionContext) {
298293

299294
emptyFolder(assemblyToolsFolder.fsPath);
300295

301-
const actions: ACTIONS | undefined = extConfig.get('ASM.actions');
302-
if (actions === undefined) {
303-
throw new Error("configurate `masmtasm.ASM.actions` first");
304-
}
305-
const action = actions[conf.extConf.asmType];
296+
const action = conf.extConf.action;
306297

307298
const doc = await vscode.workspace.openTextDocument(_uri);
308299
if (doc.isDirty && extConfig.get('ASM.savefirst')) {
@@ -335,9 +326,11 @@ export async function activate(context: vscode.ExtensionContext) {
335326
`mount c "${assemblyToolsFolder.fsPath}""`,
336327
`mount d "${workspaceFolder.uri.fsPath}""`,
337328
'd:',
338-
`cd ${fileInfo.dir}`,
339-
...action.before
329+
`cd ${fileInfo.dir}`
340330
];
331+
if (action.before) {
332+
autoexec.push(...action.before);
333+
}
341334
const logUri = vscode.Uri.joinPath(assemblyToolsFolder, logFilename);
342335
if (nodefs.existsSync(logUri.fsPath)) {
343336
await fs.delete(logUri);
@@ -435,9 +428,11 @@ export async function activate(context: vscode.ExtensionContext) {
435428
`mount c .`,
436429
`mount d ./code`,
437430
'd:',
438-
`cd ${fileInfo.dir}`,
439-
...action.before
431+
`cd ${fileInfo.dir}`
440432
];
433+
if (action.before) {
434+
autoexec.push(...action.before);
435+
}
441436
function cb(val: string) {
442437
const r = val
443438
.replace("${file}", fileInfo.base)
@@ -473,7 +468,7 @@ export async function activate(context: vscode.ExtensionContext) {
473468

474469
terminal.show();
475470
api.dosbox.fromBundle(bundle, assemblyToolsFolder);
476-
action.before.forEach(
471+
action.before?.forEach(
477472
val => {
478473
(terminal as vscode.Terminal).sendText(val.replace('C:', assemblyToolsFolder.fsPath));
479474
}

src/ASM/statusBar.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,30 @@ const emu = [
1010
conf.DosEmulatorType.msdos
1111
];
1212

13-
const asm = [
14-
conf.Assembler['MASM-v5.00'],
15-
conf.Assembler['MASM-v6.11'],
16-
conf.Assembler.TASM
17-
];
18-
1913
const iterms: string[] = [];
20-
for (const e of emu) {
21-
for (const a of asm) {
22-
if (e === conf.DosEmulatorType.msdos) {
23-
if (a === conf.Assembler.TASM || a === conf.Assembler['MASM-v6.11'])
24-
continue;
25-
}
14+
for (const a of Object.keys(conf.extConf.actions)) {
15+
for (const e of emu) {
16+
//if running in browser only use jsdos
2617
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2718
if ((process as any).browser && e !== conf.DosEmulatorType.jsdos) {
2819
continue;
2920
}
21+
22+
//ignore msdos player by default
23+
if (conf.extConf.actions[a].support === undefined && e === conf.DosEmulatorType.msdos) {
24+
continue;
25+
}
26+
27+
//hide msdos player in nonwin system
28+
if (process.platform !== "win32" && e === conf.DosEmulatorType.msdos) {
29+
continue;
30+
}
31+
32+
if (conf.extConf.actions[a].support) {
33+
if (!conf.extConf.actions[a].support?.includes(e))
34+
continue;
35+
}
36+
3037
iterms.push(e + '\t' + a);
3138
}
3239
}
@@ -40,10 +47,6 @@ function showStatus() {
4047
async function statusBarCommand() {
4148
const _conf = vscode.workspace.getConfiguration('masmtasm.ASM');
4249

43-
if (process.platform === 'win32') {
44-
emu.push(conf.DosEmulatorType.msdos);
45-
}
46-
4750
const placeHolder = 'choose DOS environment emulator and assembler';
4851
const Selected = await vscode.window.showQuickPick(iterms, { placeHolder });
4952
if (Selected) {

0 commit comments

Comments
 (0)