Skip to content

Commit

Permalink
git push origin masterMerge branch 'sapjax-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
vrjuliao committed Oct 9, 2021
2 parents 49d64a3 + 102d6da commit ab504ff
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ by **Darin Morrison** ([`@freebroccolo`](https://github.com/freebroccolo/))
use "foo.sml"
```

- Run current File:\
**This option will restart the REPL environment**
1. Press `Ctrl+Shift+P` (Linux, Windows) or `Cmd+Shift+P` (Mac) open Command Palette.
2. Type `sml`.
3. Select "SML Environment: Execute current file".

## Requirements

- ### SML/NJ
Expand Down
2 changes: 2 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ function activate(context) {

let execShortCode = vscode.commands.registerCommand('sml-environment.execShortCode', () => smlEnviron.execShortCode());
let restartRepl = vscode.commands.registerCommand('sml-environment.restart', () => smlEnviron.restart());
let execCurrentFile = vscode.commands.registerCommand('sml-environment.execCurrentFile', () => smlEnviron.execCurrentFile())

context.subscriptions.push(execShortCode);
context.subscriptions.push(restartRepl);
context.subscriptions.push(execCurrentFile)
}
exports.activate = activate;

Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sml-environment",
"displayName": "SML Environment",
"description": "Standard ML environment execution",
"version": "0.0.2",
"version": "0.0.3",
"publisher": "vrjuliao",
"icon": "demo-media/icon.png",
"license": "Apache-2.0",
Expand All @@ -21,7 +21,8 @@
"Snippets"
],
"activationEvents": [
"onCommand:sml-environment.execShortCode"
"onCommand:sml-environment.execShortCode",
"onCommand:sml-environment.execCurrentFile"
],
"main": "./extension.js",
"contributes": {
Expand All @@ -33,6 +34,10 @@
{
"command": "sml-environment.restart",
"title": "SML Environment: Restart environment"
},
{
"command": "sml-environment.execCurrentFile",
"title": "SML Environment: Execute current file"
}
],
"keybindings": [
Expand Down
50 changes: 34 additions & 16 deletions smlEnvironmentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,48 @@ function start() {
smlOutput.show(false);
}

async function execShortCode() {
async function execCode(code) {
while (!sml && !allowNextCommand) { ; }

if (sml.exitCode === 0 || sml.exitCode)
vscode.window.showErrorMessage("SML process died");
else {
try {
allowNextCommand = false;
sml.stdin.write(code + ";;;;\r\n");
} catch (error) {
smlOutput.append(error.message);
}
}
await vscode.commands.executeCommand(
"workbench.action.terminal.scrollToBottom"
);
}


async function execShortCode() {
const editor = vscode.window.activeTextEditor;

if (editor) {
const document = editor.document;
const selection = editor.selection;

const code = document.getText(selection);
if (sml.exitCode === 0 || sml.exitCode)
vscode.window.showErrorMessage("SML process died");
else {
try {
allowNextCommand = false;
sml.stdin.write(code + ";;;;\r\n");
} catch (error) {
smlOutput.append(error.message);
}
}
await vscode.commands.executeCommand(
"workbench.action.terminal.scrollToBottom"
);
execCode(code);
}
}


async function execCurrentFile() {
restart()

const editor = vscode.window.activeTextEditor;

if (editor) {
const document = editor.document
const code = document.getText()
execCode(code);
}
}

function restart() {
if (sml.exitCode !== 0 && !sml.exitCode) {
sml.stdin.end();
Expand All @@ -88,4 +105,5 @@ module.exports = {
stop,
restart,
execShortCode,
execCurrentFile
};

0 comments on commit ab504ff

Please sign in to comment.