Skip to content

Commit 5b719fc

Browse files
committed
Don't wait for 2nd janet.eval event to eval code.
1 parent c6c06de commit 5b719fc

File tree

5 files changed

+79
-91
lines changed

5 files changed

+79
-91
lines changed

Diff for: .gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Index ./out for easy local install
2-
#out
32
node_modules
43
.vscode-test/
54
*.vsix

Diff for: janet.configuration.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@
1010
"autoClosingPairs": [
1111
["[", "]"],
1212
["(", ")"],
13-
["{", "}"]
13+
["{", "}"],
14+
{ "open": "\"", "close": "\"", "notIn": ["string"] },
15+
{ "open": "`", "close": "`", "notIn": ["string", "comment"] },
16+
{ "open": "/**", "close": " */", "notIn": ["string"] }
1417
],
1518
"surroundingPairs": [
1619
["[", "]"],
1720
["(", ")"],
1821
["{", "}"]
19-
]
22+
],
23+
"wordPattern": "[A-Za-z0-9\\!\\$\\%\\&\\*\\+\\-\\.\\/\\:\\<\\?\\=\\>\\@\\^\\_\\|\\x80-\\xFF]+",
24+
"indentationRules": {
25+
"increaseIndentPattern": "^((?!.*?\\/\\*).*\\*\/)?\\s*[\\}\\]].*$",
26+
"decreaseIndentPattern": "^((?!\\/\\/).)*(\\{[^}\"'`]*|\\([^)\"'`]*|\\[[^\\]\"'`]*)$"
27+
}
2028
}

Diff for: out/extension.js

+33-42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: out/extension.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/extension.ts

+35-45
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,49 @@
1-
import * as os from 'os';
21
import * as fs from 'fs';
2+
import * as os from 'os';
33
import * as path from 'path';
44
import * as vscode from 'vscode';
55

66
const windows: boolean = os.platform() == 'win32';
7-
const linux: boolean = os.platform() == 'linux';
8-
const pathSeparator: string = windows ? ';' : ':';
97

10-
const janetCommand: string = windows ? 'janet.exe' : 'janet -s';
8+
const janetBinary: string = windows ? 'janet.exe' : 'janet';
119
const terminalName: string = 'Janet REPL';
1210

13-
1411
function janetExists(): boolean {
15-
return process.env['PATH'].split(pathSeparator)
16-
.some((x) => fs.existsSync(path.resolve(x, janetCommand)));
12+
return process.env['PATH'].split(path.delimiter)
13+
.some((x) => fs.existsSync(path.resolve(x, janetBinary)));
1714
}
1815

19-
function newREPL(): vscode.Terminal {
20-
let terminal = vscode.window.createTerminal(terminalName);
21-
terminal.sendText(janetCommand, true);
22-
23-
vscode.window.withProgress({
16+
function newREPL(): Thenable<vscode.Terminal> {
17+
const terminal = vscode.window.createTerminal(terminalName);
18+
terminal.sendText(janetBinary + ' -s', true);
19+
return vscode.window.withProgress({
2420
location: vscode.ProgressLocation.Notification,
2521
title: "Running Janet REPL...",
2622
cancellable: false
2723
}, (progress, token) => {
28-
var p = new Promise(resolve => {
24+
return new Promise<vscode.Terminal>(resolve => {
2925
setTimeout(() => {
3026
terminal.show();
3127
thenFocusTextEditor();
32-
resolve();
28+
resolve(terminal);
3329
}, 2000);
3430
});
35-
36-
return p;
3731
});
38-
39-
return terminal;
4032
}
4133

42-
function getREPL(show: boolean): vscode.Terminal {
34+
function getREPL(show: boolean): Thenable<vscode.Terminal> {
4335
let terminal: vscode.Terminal = (<any>vscode.window).terminals.find(x => x._name === terminalName);
36+
let terminalP = (terminal) ? Promise.resolve(terminal) : newREPL();
37+
return terminalP.then(t => {
38+
if (show) {
39+
t.show();
40+
}
41+
return t;
42+
});
43+
}
4444

45-
if (terminal == null) {
46-
newREPL();
47-
return null;
48-
}
49-
50-
if (show) terminal.show();
51-
52-
return terminal;
45+
function sendSource(terminal: vscode.Terminal, text: string) {
46+
terminal.sendText(text, true);
5347
}
5448

5549
function thenFocusTextEditor() {
@@ -77,18 +71,16 @@ export function activate(context: vscode.ExtensionContext) {
7771
() => {
7872
let editor = vscode.window.activeTextEditor;
7973
if (editor == null) return;
80-
81-
let terminal = getREPL(true);
82-
if (terminal == null) return;
83-
84-
function send(terminal: vscode.Terminal) {
85-
terminal.sendText(editor.document.getText(editor.selection), true);
86-
thenFocusTextEditor();
87-
}
88-
if (editor.selection.isEmpty)
89-
vscode.commands.executeCommand('editor.action.selectToBracket').then(() => send(terminal));
90-
else
91-
send(terminal);
74+
getREPL(true).then(terminal => {
75+
function send(terminal: vscode.Terminal) {
76+
sendSource(terminal, editor.document.getText(editor.selection));
77+
thenFocusTextEditor();
78+
}
79+
if (editor.selection.isEmpty)
80+
vscode.commands.executeCommand('editor.action.selectToBracket').then(() => send(terminal));
81+
else
82+
send(terminal);
83+
});
9284
}
9385
));
9486

@@ -97,12 +89,10 @@ export function activate(context: vscode.ExtensionContext) {
9789
() => {
9890
let editor = vscode.window.activeTextEditor;
9991
if (editor == null) return;
100-
101-
let terminal = getREPL(true);
102-
if (terminal == null) return;
103-
104-
terminal.sendText(editor.document.getText(), true);
105-
thenFocusTextEditor();
92+
getREPL(true).then(terminal => {
93+
sendSource(terminal, editor.document.getText());
94+
thenFocusTextEditor();
95+
});
10696
}
10797
));
10898
}

0 commit comments

Comments
 (0)