Skip to content

Commit c0facfe

Browse files
committed
[feature] dynamically choose tool for ghci
1 parent 120eb12 commit c0facfe

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to the *Haskell Runner 2* will be documented in this file.
77
- support for custom ghci path
88
- support for sending selected code to ghci
99
- add keybindings for `Send to GHCi` (shortcut: `ctrl+alt+right`)
10+
- allow dynamically choose tool for `ghci`
1011

1112
## [0.1.3]
1213

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The following configurations are available:
2020

2121
- `runner2.ghciPath`: path for GHCi (default `ghci`)
2222
- `runner2.stackPath`: path for stack executable (default `stack`)
23-
- `runner2.stackRepl`: use `stack repl` instead of `ghci`, you may like to turn it on in stack projects (default `false`)
23+
- `runner2.stackRepl`: by `default`, it uses `ghci` in single file and use `stack repl` in stack project, can be overridden by choosing other options (`ghci` for ghci only, and `stack` for stack repl only)
2424
- `runner2.stackRun`: show "Stack Run" button, *reload required* (default `false`)
2525

2626
## Release Notes

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,14 @@
6666
"description": "Path to stack executable"
6767
},
6868
"runner2.stackRepl": {
69-
"type": "boolean",
70-
"default": false,
71-
"description": "Use stack repl instead of GHCi"
69+
"type": "string",
70+
"enum": [
71+
"default",
72+
"ghci",
73+
"stack"
74+
],
75+
"default": "default",
76+
"description": "Decide when to use stack repl instead of GHCi"
7277
},
7378
"runner2.stackRun": {
7479
"type": "boolean",

src/config.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
import * as vscode from 'vscode';
22

3+
export type Mode = "default" | "ghci" | "stack";
4+
35
export type Config = {
6+
mode: Mode,
7+
ghciPath: string,
48
stackPath: string,
5-
ghciTool: string,
9+
ghciTool: (proj: boolean) => string,
610
enableStackRun: boolean,
711
};
812

913
export function getConfig(): Config {
1014
const config = vscode.workspace.getConfiguration();
11-
let ghci = config.get("runner2.ghciPath", "ghci");
12-
let stack = config.get("runner2.stackPath", "stack");
13-
let repl = config.get("runner2.stackRepl", false);
15+
const ghci = config.get("runner2.ghciPath", "ghci");
16+
const stack = config.get("runner2.stackPath", "stack");
17+
const mode = config.get<Mode>("runner2.stackRepl", "default");
18+
let tool = (proj: boolean) => {
19+
let repl = stack + " repl";
20+
switch (mode) {
21+
case "default": return proj ? repl : ghci;
22+
case "ghci": return ghci;
23+
case "stack": return repl;
24+
}
25+
};
1426
return {
27+
mode: mode,
28+
ghciPath: ghci,
1529
stackPath: stack,
16-
ghciTool: repl ? (stack + " repl") : ghci,
30+
ghciTool: tool,
1731
enableStackRun: config.get("runner2.stackRun", false)
1832
};
1933
}

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function activate(context: vscode.ExtensionContext) {
3030
filename.map(f => terminal.unwrap().sendText(stackproj ? ":r" : (":l " + f)));
3131
} else {
3232
let term = vscode.window.createTerminal("GHCi");
33-
term.sendText(config.ghciTool + " " + (stackproj ? "" : filename.orelse("")));
33+
term.sendText(config.ghciTool(stackproj) + " " + (stackproj ? "" : filename.orelse("")));
3434
term.show();
3535
}
3636
});
@@ -48,7 +48,7 @@ export async function activate(context: vscode.ExtensionContext) {
4848
terminal.unwrap().sendText(s);
4949
} else {
5050
let term = vscode.window.createTerminal("GHCi");
51-
term.sendText(config.ghciTool); // we're not loading the file here
51+
term.sendText(config.ghciTool(stackproj)); // we're not loading the file here
5252
term.sendText(s);
5353
term.show();
5454
}

0 commit comments

Comments
 (0)