Skip to content

Commit ce57b06

Browse files
committed
small adjustment
1 parent 446b10e commit ce57b06

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ All notable changes to the *Haskell Runner 2* will be documented in this file.
77
## [0.3.0]
88

99
- **!! config and command name changes !!**
10-
- reuse terminals by default
11-
- added `cabal repl/build/test` support in cabal projects
10+
- reuse terminal by default
11+
- added `cabal repl/build/test` support in cabal project
1212
- extension now starts on a `*.cabal` file
1313

1414
## [0.2.1]
1515

16-
- fix potential path issue in Windows
16+
- fix potential path issue on Windows
1717

1818
## [0.2.0]
1919

src/extension.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function activate(context: vscode.ExtensionContext) {
1717
// update config
1818
vscode.workspace.onDidChangeConfiguration(e => { config = conf.getConfig(); });
1919
// check stack/cabal project
20-
let hasConf = async (f: string) => (await vscode.workspace.findFiles(f)).length > 0;
20+
const hasConf = async (f: string) => (await vscode.workspace.findFiles(f)).length > 0;
2121
let project: conf.ProjectTy = (await hasConf("stack.yaml")) ? "stack" : (await hasConf("*.cabal") ? "cabal" : "none");
2222
let inproject = project !== "none";
2323

@@ -31,9 +31,15 @@ export async function activate(context: vscode.ExtensionContext) {
3131
// currently at GHCi
3232
const term = terminal.flatmap(option.filterOption(t => t.name === "GHCi"))
3333
.or(util.getTermOption("GHCi")).map(term => () => {
34-
filename
35-
.map(f => f.split("\\").join("\\\\")) // windows path may contain backslash
36-
.map(f => term.sendText(inproject ? ":r" : (":l " + f)));
34+
if (inproject) {
35+
term.sendText(":r"); // reload modules in project
36+
} else {
37+
filename
38+
.map(f => f.split("\\").join("\\\\")) // windows path may contain backslash
39+
.map(f => () => term.sendText(":l " + f))
40+
.orelse(() => vscode.window.showInformationMessage(
41+
"Cannot load a non-Haskell file to GHCi"))();
42+
}
3743
return term;
3844
}).orelse(() => {
3945
let term = vscode.window.createTerminal("GHCi");
@@ -53,7 +59,9 @@ export async function activate(context: vscode.ExtensionContext) {
5359
.map(s => ":{\n" + s + "\n:}\n") // in case of multi-line selection
5460
.map(s => {
5561
const term = terminal.flatmap(option.filterOption(t => t.name === "GHCi"))
56-
.or(util.getTermOption("GHCi")).map(term => () => term).orelse(() => {
62+
.or(util.getTermOption("GHCi"))
63+
.map(term => () => term)
64+
.orelse(() => {
5765
let term = vscode.window.createTerminal("GHCi");
5866
term.sendText(config.ghciTool(project)); // we're not loading the file here
5967
return term;
@@ -88,9 +96,9 @@ export async function activate(context: vscode.ExtensionContext) {
8896
setupProject("Cabal", config.cabalPath);
8997
break;
9098
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!");
99+
util.registerPrompt(context, "runner2.hstest", "Not in a stack or cabal project!");
100+
util.registerPrompt(context, "runner2.hsbuild", "Not in a stack or cabal project!");
101+
util.registerPrompt(context, "runner2.hsrun", "Not in a stack or cabal project!");
94102
break;
95103
}
96104

src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from 'vscode';
22
import * as option from './option';
33

4-
// get/new terminal
4+
// get terminal
55
export function getTermOption(name: string): option.Option<vscode.Terminal> {
66
let idx = vscode.window.terminals.findIndex((term) => term.name === name);
77
if (idx === -1) {

0 commit comments

Comments
 (0)