-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
94 lines (81 loc) · 3.01 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
let vscode = require("vscode");
let path = require("path");
let os = require("os");
function activate(global) {
console.log('Extension "m68hc11-asm11" activated.');
let disposable = vscode.commands.registerCommand(
"m68hc11-asm11.asm11assemble",
function() {
let optionStr = "";
let configuration = vscode.workspace.getConfiguration("m68hc11-asm11");
if (configuration.get("Listing")) {
optionStr = optionStr + "l ";
}
if (configuration.get("NoListing")) {
optionStr = optionStr + "nol ";
}
if (configuration.get("CrossReference")) {
optionStr = optionStr + "cre ";
}
if (configuration.get("Symbol")) {
optionStr = optionStr + "s ";
}
if (configuration.get("Cycle")) {
optionStr = optionStr + "c ";
}
if (configuration.get("NoCycle")) {
optionStr = optionStr + "noc ";
}
if (optionStr != "") {
optionStr = "-" + optionStr;
}
let applicationPath = configuration.get("Asm11Path");
let commandPath = applicationPath + path.sep + "asm11";
let listingExtension = configuration.get("ListingExtension");
let srcPath = vscode.window.activeTextEditor.document.fileName;
let srcDir = path.dirname(srcPath);
let extName = path.extname(srcPath);
let baseName = path.basename(srcPath, extName);
let listingStr = "> " + baseName + listingExtension;
if (extName.toLowerCase() == ".s" || extName.toLowerCase() == ".asm") {
let platformStr = os.platform();
if(platformStr == "win32"){ // windows10 + WSL + Ubuntu
commandPath = commandPath.replace(/\\/g, "/");
let commandArg = baseName + extName + " " + optionStr + " " + listingStr;
let commandStr = "bash.exe -c '" + commandPath + " " + commandArg +" '";
const { exec } = require("child_process");
let cp = exec(
commandStr,
{ cwd: srcDir }
);
// show cp stderr
cp.stderr.on('data', (data) => {
vscode.window.showErrorMessage(`asm11 stderr: ${data}`);
});
// show command
vscode.window.showInformationMessage("asm11: " + commandStr);
}else{ // darwin / linux
const { spawn } = require("child_process");
let cp = spawn(
commandPath,
[baseName + extName, optionStr, listingStr],
{ cwd: srcDir, shell: true }
);
// show cp stderr
cp.stderr.on('data', (data) => {
vscode.window.showErrorMessage(`asm11 stderr: ${data}`);
});
// show command
vscode.window.showInformationMessage(
"asm11: " + commandPath + " " + baseName + extName + " " + optionStr + " " + listingStr
);
}
}else{
// show 'wrong source extension' error mesg
vscode.window.showErrorMessage("asm11: not a source file");
}
}
);
}
exports.activate = activate;
function deactivate() {}