Skip to content

Commit 446b10e

Browse files
committed
prepare 0.3.0
1 parent 6b45a25 commit 446b10e

File tree

6 files changed

+56
-42
lines changed

6 files changed

+56
-42
lines changed

CHANGELOG.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ All notable changes to the *Haskell Runner 2* will be documented in this file.
44

55
## [Unreleased]
66

7-
- TODO: support `cabal build` and `cabal test`
7+
## [0.3.0]
88

9-
## [0.2.2]
10-
11-
- added `cabal repl` support in cabal project
12-
- extension starts on a `cabal` file
13-
- able to reuse terminal
9+
- **!! config and command name changes !!**
10+
- reuse terminals by default
11+
- added `cabal repl/build/test` support in cabal projects
12+
- extension now starts on a `*.cabal` file
1413

1514
## [0.2.1]
1615

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Successor of the original `Haskell Runner`.
77
A simple extension to run Haskell:
88

99
- Load Haskell file/project to repl (GHCi)
10-
- Run `stack build/test/run` inside a stack project
10+
- *Build*, *Test* or *Run* inside a stack or cabal project
1111
- Send selected Haskell code to GHCi (`ctrl+alt+right`)
1212

1313
## Requirements
@@ -22,7 +22,7 @@ The following configurations are available:
2222
- `runner2.stackPath`: path for stack executable (default `stack`)
2323
- `runner2.cabalPath`: path for cabal executable (default `cabal`)
2424
- `runner2.replTool`: by `default`, it use `ghci` in single file and use `stack repl` (or `cabal repl`) in stack project. This can be overridden by choosing other options (`ghci` for ghci only, and `stack` (or `cabal`) for stack/cabal repl only)
25-
- `runner2.stackRun`: show "Stack Run" button, *reload required* (default `false`)
25+
- `runner2.showRunButton`: show "Stack/Cabal Run" button, *reload required* (default `false`)
2626

2727
## Release Notes
2828

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Haskell Runner 2",
44
"description": "Shortcut for GHCi and Stack",
55
"publisher": "Meowcolm024",
6-
"version": "0.2.2",
6+
"version": "0.3.0",
77
"license": "BSD3",
88
"icon": "images/hr2.png",
99
"engines": {
@@ -22,7 +22,7 @@
2222
"onLanguage:literate haskell",
2323
"onLanguage:cabal",
2424
"workspaceContains:stack.yaml",
25-
"onCommand:runner2.ghci"
25+
"workspaceContains:*.cabal"
2626
],
2727
"main": "./out/extension.js",
2828
"contributes": {
@@ -33,18 +33,18 @@
3333
"category": "Haskell Runner 2"
3434
},
3535
{
36-
"command": "runner2.stacktest",
37-
"title": "Stack Test",
36+
"command": "runner2.hstest",
37+
"title": "Haskell Run Tests",
3838
"category": "Haskell Runner 2"
3939
},
4040
{
41-
"command": "runner2.stackbuild",
42-
"title": "Stack Build",
41+
"command": "runner2.hsbuild",
42+
"title": "Haskell Build Project",
4343
"category": "Haskell Runner 2"
4444
},
4545
{
46-
"command": "runner2.stackrun",
47-
"title": "Stack Run",
46+
"command": "runner2.hsrun",
47+
"title": "Haskell Run Executable",
4848
"category": "Haskell Runner 2"
4949
},
5050
{
@@ -82,10 +82,10 @@
8282
"default": "default",
8383
"description": "Decide when to use stack/cabal repl instead of GHCi"
8484
},
85-
"runner2.stackRun": {
85+
"runner2.showRunButton": {
8686
"type": "boolean",
8787
"default": false,
88-
"description": "Show stack run button"
88+
"description": "Show stack/cabal run button"
8989
}
9090
}
9191
},
@@ -109,6 +109,7 @@
109109
"command": "runner2.sendGhci",
110110
"key": "ctrl+alt+right",
111111
"mac": "ctrl+alt+right",
112+
"linux": "ctrl+alt+right",
112113
"when": "resourceLangId == haskell"
113114
}
114115
]

src/config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import * as vscode from 'vscode';
22

3-
export type Mode = "default" | "ghci" | "stack" | "cabal";
3+
// only used by config
4+
type Mode = "default" | "ghci" | "stack" | "cabal";
5+
// type of current project
46
export type ProjectTy = "none" | "stack" | "cabal";
57

68
export type Config = {
79
mode: Mode,
810
ghciPath: string,
911
stackPath: string,
12+
cabalPath: string,
1013
ghciTool: (proj: ProjectTy) => string,
11-
enableStackRun: boolean,
14+
showRun: boolean,
1215
};
1316

1417
export function getConfig(): Config {
@@ -34,7 +37,8 @@ export function getConfig(): Config {
3437
mode: mode,
3538
ghciPath: ghci,
3639
stackPath: stack,
40+
cabalPath: cabal,
3741
ghciTool: tool,
38-
enableStackRun: config.get("runner2.stackRun", false)
42+
showRun: config.get("runner2.showRunButton", false)
3943
};
4044
}

src/extension.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ export async function activate(context: vscode.ExtensionContext) {
2222
let inproject = project !== "none";
2323

2424
// GHCi command
25-
let ghci = vscode.commands.registerCommand("runner2.ghci", () => {
25+
const ghci = vscode.commands.registerCommand("runner2.ghci", () => {
26+
// get current file name
2627
let filename = option.option(vscode.window.activeTextEditor)
2728
.map(e => e.document)
2829
.flatmap(option.filterOption(util.isHaskell))
2930
.map(s => `\"${s.fileName}\"`);
3031
// currently at GHCi
3132
const term = terminal.flatmap(option.filterOption(t => t.name === "GHCi"))
32-
.or(util.getTermOption("GHCi")).map((term) => () => {
33+
.or(util.getTermOption("GHCi")).map(term => () => {
3334
filename
3435
.map(f => f.split("\\").join("\\\\")) // windows path may contain backslash
3536
.map(f => term.sendText(inproject ? ":r" : (":l " + f)));
@@ -44,7 +45,7 @@ export async function activate(context: vscode.ExtensionContext) {
4445
context.subscriptions.push(ghci);
4546

4647
// send selected code to GHCi
47-
let sendGhci = vscode.commands.registerCommand("runner2.sendGhci", () =>
48+
const sendGhci = vscode.commands.registerCommand("runner2.sendGhci", () =>
4849
option.option(vscode.window.activeTextEditor)
4950
.map(e => e.document.getText(
5051
new vscode.Range(e.selection.start, e.selection.end)))
@@ -53,7 +54,7 @@ export async function activate(context: vscode.ExtensionContext) {
5354
.map(s => {
5455
const term = terminal.flatmap(option.filterOption(t => t.name === "GHCi"))
5556
.or(util.getTermOption("GHCi")).map(term => () => term).orelse(() => {
56-
let term = util.getTermOption("GHCi").orelse(vscode.window.createTerminal("GHCi"));
57+
let term = vscode.window.createTerminal("GHCi");
5758
term.sendText(config.ghciTool(project)); // we're not loading the file here
5859
return term;
5960
})();
@@ -65,25 +66,32 @@ export async function activate(context: vscode.ExtensionContext) {
6566

6667
// button for ghci
6768
util.resgisterStatButton(context, "Load GHCi", "runner2.ghci");
68-
// button for stack project
69+
70+
const setupProject = (project: string, path: string) => {
71+
// setup commands
72+
util.registerSimplTerm(context, "runner2.hstest", project + " Test", path + " test");
73+
util.registerSimplTerm(context, "runner2.hsbuild", project + " Build", path + " build");
74+
util.registerSimplTerm(context, "runner2.hsrun", project + " Run", path + " run");
75+
// setup buttons
76+
util.resgisterStatButton(context, project + " Build", "runner2.hsbuild");
77+
util.resgisterStatButton(context, project + " Test", "runner2.hstest");
78+
if (config.showRun) {
79+
util.resgisterStatButton(context, project + " Run", "runner2.hsrun");
80+
}
81+
};
82+
6983
switch (project) {
7084
case "stack":
71-
// setup commands
72-
util.registerSimplTerm(context, "runner2.stacktest", "Stack Test", config.stackPath + " test");
73-
util.registerSimplTerm(context, "runner2.stackbuild", "Stack Build", config.stackPath + " build");
74-
util.registerSimplTerm(context, "runner2.stackrun", "Stack Run", config.stackPath + " run");
75-
// setup buttons
76-
util.resgisterStatButton(context, "Stack Build", "runner2.stackbuild");
77-
util.resgisterStatButton(context, "Stack Test", "runner2.stacktest");
78-
if (config.enableStackRun) {
79-
util.resgisterStatButton(context, "Stack Run", "runner2.stackrun");
80-
}
85+
setupProject("Stack", config.stackPath);
86+
break;
87+
case "cabal":
88+
setupProject("Cabal", config.cabalPath);
89+
break;
90+
case "none": // default behavior
91+
util.registerPrompt(context, "runner2.hstest", "Not in a stack/cabal project!");
92+
util.registerPrompt(context, "runner2.hsbuild", "Not in a stack/cabal project!");
93+
util.registerPrompt(context, "runner2.hsrun", "Not in a stack/cabal project!");
8194
break;
82-
default:
83-
// default behavior
84-
util.registerPrompt(context, "runner2.stacktest", "Not in a stack project!");
85-
util.registerPrompt(context, "runner2.stackbuild", "Not in a stack project!");
86-
util.registerPrompt(context, "runner2.stackrun", "Not in a stack project!");
8795
}
8896

8997
}

src/util.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export function registerSimplTerm(
3434
cmd: string
3535
) {
3636
context.subscriptions.push(vscode.commands.registerCommand(command, () => {
37-
let term = getTermOption(name).orelse(vscode.window.createTerminal(name));
37+
let term = getTermOption(name)
38+
.map(t => () => t) // new terminal need to be created lazily
39+
.orelse(() => vscode.window.createTerminal(name))();
3840
term.sendText(cmd);
3941
term.show();
4042
}));

0 commit comments

Comments
 (0)