Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bbj-vscode/images/bbj-compile-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions bbj-vscode/images/bbj-compile-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions bbj-vscode/images/bbj-decompile-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions bbj-vscode/images/bbj-decompile-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions bbj-vscode/images/bbj-denumber-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions bbj-vscode/images/bbj-denumber-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,788 changes: 2,786 additions & 2 deletions bbj-vscode/package-lock.json

Large diffs are not rendered by default.

81 changes: 80 additions & 1 deletion bbj-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,35 @@
"dark": "./images/run-dwc-dark.svg"
},
"key": "alt+d"
},
{
"category": "BBj",
"command": "bbj.decompile",
"title": "Decompile BBj Program",
"icon": {
"light": "./images/bbj-decompile-light.svg",
"dark": "./images/bbj-decompile-dark.svg"
},
"key": "alt+x"
},
{
"category": "BBj",
"command": "bbj.compile",
"title": "Compile BBj Program",
"icon": {
"light": "./images/bbj-compile-light.svg",
"dark": "./images/bbj-compile-dark.svg"
},
"key": "alt+c"
},
{
"command": "bbj.denumber",
"title": "Denumber BBj Program",
"icon": {
"light": "./images/bbj-denumber-light.svg",
"dark": "./images/bbj-denumber-dark.svg"
},
"key": "alt+n"
}
],
"keybindings": [
Expand All @@ -129,6 +158,14 @@
{
"command": "bbj.runDWC",
"key": "alt+d"
},
{
"command": "bbj.compile",
"key": "alt+c"
},
{
"command": "bbj.denumber",
"key": "alt+n"
}
],
"menus": {
Expand All @@ -147,6 +184,18 @@
"when": "resourceLangId == bbj",
"command": "bbj.runDWC",
"group": "BBj@3"
},
{
"command": "bbj.compile",
"group": "BBj@4"
},
{
"command": "bbj.decompile",
"group": "BBj@5"
},
{
"command": "bbj.denumber",
"group": "BBj@4"
}
],
"editor/title": [
Expand All @@ -164,6 +213,18 @@
"when": "resourceLangId == bbj",
"command": "bbj.runDWC",
"group": "navigation"
},
{
"command": "bbj.compile",
"group": "navigation@2"
},
{
"command": "bbj.decompile",
"group": "navigation@2"
},
{
"command": "bbj.denumber",
"group": "navigation@2"
}
],
"explorer/context": [
Expand All @@ -181,6 +242,20 @@
"when": "resourceLangId == bbj",
"command": "bbj.runDWC",
"group": "BBj32"
},
{
"when": "resourceLangId == bbj",
"command": "bbj.compile",
"group": "BBj@4"
},
{
"when": "resourceLangId == bbj",
"command": "bbj.decompile",
"group": "BBj@5"
},
{
"command": "bbj.denumber",
"group": "BBj@6"
}
]
},
Expand Down Expand Up @@ -271,7 +346,10 @@
"onCommand:bbj.run",
"onCommand:bbj.runBUI",
"onCommand:bbj.runDWC",
"onCommand:bbj.autoComment"
"onCommand:bbj.autoComment",
"onCommand:bbj.compile",
"onCommand:bbj.decompile",
"onCommand:bbj.denumber"
],
"main": "./out/extension.cjs",
"scripts": {
Expand All @@ -290,6 +368,7 @@
"langium:watch": "langium generate --watch"
},
"dependencies": {
"bbj-lang": "file:",
"chevrotain": "^11.0.3",
"langium": "~3.2.0",
"properties-file": "~3.2.5",
Expand Down
122 changes: 101 additions & 21 deletions bbj-vscode/src/Commands/Commands.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require("path");
const { exec } = require("child_process");
const os = require("os");
const PropertiesReader = require("properties-reader");
const fs = require("fs");

const getBBjHome = () => {
const home = vscode.workspace.getConfiguration("bbj").home;
Expand Down Expand Up @@ -48,37 +49,90 @@ const runWeb = (params, client) => {
});
};

const decompile = (params, options = {}) => {
const home = getBBjHome();
if (!home) return;
const active = vscode.window.activeTextEditor;
const fileName = active ? active.document.fileName : params.fsPath;
const resolvedFileName = path.resolve(fileName);
const resolvedLstFileName = resolvedFileName.endsWith('.lst')
? resolvedFileName
: resolvedFileName + '.lst';

const newFileName = options.denumber ? resolvedFileName : resolvedFileName.replace(/\.lst$/, '');

console.log(resolvedFileName.endsWith('.lst'));
const flags = options.denumber ? `-l ${resolvedFileName.endsWith('.lst') && '-xlst'}` : '';

const cmd = `"${home}/bin/bbjlst${
os.platform() === 'win32' ? '.exe' : ''
}" ${flags} "${resolvedFileName}"`;

exec(cmd, (err, stdout, stderr) => {
if (err) {
vscode.window.showErrorMessage(`Failed to decompile "${fileName}"`);
return;
}

if (!options.denumber) {
fs.unlink(resolvedFileName, (unlinkErr) => {
if (unlinkErr) {
vscode.window.showErrorMessage(
`Failed to remove original file "${fileName}": ${unlinkErr.message}`
);
return;
}
});
}

fs.rename(resolvedLstFileName, newFileName, (renameErr) => {
if (renameErr) {
vscode.window.showErrorMessage(
`Failed to rename file "${resolvedLstFileName}": ${renameErr.message}`
);
return;
}
});

const uri = vscode.Uri.file(newFileName);
vscode.workspace.openTextDocument(uri).then((doc) => {
vscode.window.showTextDocument(doc, { preview: false });
});
});
};

const Commands = {
openConfigFile: function () {
const home = getBBjHome();

if (home) {
return vscode.workspace
.openTextDocument(`${home}/cfg/config.bbx`)
.then(doc => {
vscode.window.showTextDocument(doc);
});
return vscode.workspace.openTextDocument(`${home}/cfg/config.bbx`).then((doc) => {
vscode.window.showTextDocument(doc);
});
}
},

openPropertiesFile: function () {
const home = getBBjHome();

if (home) {
return vscode.workspace
.openTextDocument(`${home}/cfg/BBj.properties`)
.then(doc => {
vscode.window.showTextDocument(doc);
});
return vscode.workspace.openTextDocument(`${home}/cfg/BBj.properties`).then((doc) => {
vscode.window.showTextDocument(doc);
});
}
},

openEnterpriseManager() {
const home = getBBjHome();
if (home) {
const properties = PropertiesReader(`${home}/cfg/BBj.properties`);
const url = `${"http://" + properties.get('com.basis.jetty.host') + ":" + properties.get('com.basis.jetty.port') + "/bbjem/em"}`;
const url = `${
'http://' +
properties.get('com.basis.jetty.host') +
':' +
properties.get('com.basis.jetty.port') +
'/bbjem/em'
}`;
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
}
},
Expand All @@ -87,18 +141,18 @@ const Commands = {
const home = getBBjHome();
if (!home) return;

const webConfig = vscode.workspace.getConfiguration("bbj.web");
var sscp = vscode.workspace.getConfiguration("bbj").classpath;
const bbj = `${home}/bin/bbj${os.platform() === "win32" ? ".exe" : ""}`;
const webConfig = vscode.workspace.getConfiguration('bbj.web');
var sscp = vscode.workspace.getConfiguration('bbj').classpath;

const bbj = `${home}/bin/bbj${os.platform() === 'win32' ? '.exe' : ''}`;
const active = vscode.window.activeTextEditor;
const fileName = active ? active.document.fileName : params.fsPath;
const workingDir = path.dirname(fileName);

if (sscp != null && sscp>"") {
sscp = "-CP"+sscp;
if (sscp != null && sscp > '') {
sscp = '-CP' + sscp;
} else {
sscp = "";
sscp = '';
}

const cmd = `${bbj} -q ${sscp} -WD${workingDir} ${fileName}`;
Expand All @@ -119,12 +173,38 @@ const Commands = {
},

runBUI: function (params) {
runWeb(params, "BUI");
runWeb(params, 'BUI');
},

runDWC: function (params) {
runWeb(params, "DWC");
}
runWeb(params, 'DWC');
},

compile: function (params) {
const home = getBBjHome();
if (!home) return;
const cmd = `"${home}/bin/bbjcpl${os.platform() === 'win32' ? '.exe' : ''}" "${
vscode.window.activeTextEditor.document.fileName
}"`;

const active = vscode.window.activeTextEditor;

const fileName = active ? active.document.fileName : params.fsPath;
exec(cmd, (err, stdout, stderr) => {
if (err) {
vscode.window.showErrorMessage(`Failed to compile "${fileName}"`);
return;
}
});
vscode.window.showInformationMessage(`Successfully compiled "${fileName}"`);
},
decompile: function (params) {
decompile(params);
},

denumber: function (params) {
decompile(params, { denumber: true });
},
};

module.exports = Commands;
3 changes: 3 additions & 0 deletions bbj-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export function activate(context: vscode.ExtensionContext): void {
vscode.commands.registerCommand("bbj.run", Commands.run);
vscode.commands.registerCommand("bbj.runBUI", Commands.runBUI);
vscode.commands.registerCommand("bbj.runDWC", Commands.runDWC);
vscode.commands.registerCommand("bbj.decompile", Commands.decompile);
vscode.commands.registerCommand("bbj.compile", Commands.compile);
vscode.commands.registerCommand("bbj.denumber", Commands.denumber);

vscode.languages.registerDocumentFormattingEditProvider(
"bbj",
Expand Down
Loading