@@ -6,60 +6,52 @@ import * as conf from './config';
6
6
import * as util from './util' ;
7
7
8
8
// configuration
9
- const config = conf . getConfig ( ) ;
10
-
9
+ var config : conf . Config = conf . getConfig ( ) ;
10
+ // current terminal
11
11
var terminal : option . Option < vscode . Terminal > = option . none ( ) ;
12
12
13
- // this method is called when your extension is activated
14
- // your extension is activated the very first time the command is executed
13
+ // I'm not sure if we can do `async` here
15
14
export async function activate ( context : vscode . ExtensionContext ) {
16
15
// setup terminal
17
16
vscode . window . onDidChangeActiveTerminal ( e => { terminal = option . option ( e ) ; } ) ;
17
+ // update config
18
+ vscode . workspace . onDidChangeConfiguration ( e => { config = conf . getConfig ( ) ; } ) ;
18
19
19
20
// check stack project
20
21
let stackproj = ( await vscode . workspace . findFiles ( "stack.yaml" ) ) . length > 0 ;
21
22
22
23
// GHCi command
23
24
let ghci = vscode . commands . registerCommand ( "runner2.ghci" , ( ) => {
24
- let doc = option . option ( vscode . window . activeTextEditor ) . map ( e => e . document ) ;
25
- let filename = doc
26
- . flatmap ( d => util . isHaskell ( d ) ? option . some ( d ) : option . none < vscode . TextDocument > ( ) )
25
+ let filename = option . option ( vscode . window . activeTextEditor )
26
+ . map ( e => e . document )
27
+ . flatmap ( d => option . filterOption ( util . isHaskell , d ) )
27
28
. map ( s => `\"${ s . fileName } \"` ) ;
28
29
// currently at GHCi
29
30
if ( terminal . map ( t => t . name ) . contains ( "GHCi" ) ) {
30
31
filename . map ( f => terminal . unwrap ( ) . sendText ( stackproj ? ":r" : ( ":l " + f ) ) ) ;
31
32
} else {
32
- filename . map ( f => {
33
- let t = vscode . window . createTerminal ( "GHCi" ) ;
34
- t . sendText ( config . ghciTool + " " + ( stackproj ? "" : f ) ) ;
35
- t . show ( ) ;
36
- } ) ;
33
+ let term = vscode . window . createTerminal ( "GHCi" ) ;
34
+ term . sendText ( config . ghciTool + " " + ( stackproj ? "" : filename . orelse ( "" ) ) ) ;
35
+ term . show ( ) ;
37
36
}
38
37
} ) ;
39
38
context . subscriptions . push ( ghci ) ;
40
39
41
40
// stack project commands
42
- context . subscriptions . push ( vscode . commands . registerCommand (
43
- "runner2.stacktest" , util . simplTerm ( "Stack Test" , config . stackPath + " test" ) ) ) ;
44
- context . subscriptions . push ( vscode . commands . registerCommand (
45
- "runner2.stackbuild" , util . simplTerm ( "Stack Build" , config . stackPath + " build" ) ) ) ;
46
- context . subscriptions . push ( vscode . commands . registerCommand (
47
- "runner2.stackrun" , util . simplTerm ( "Stack Run" , config . stackPath + " run" ) ) ) ;
41
+ util . registerSimplTerm ( context , "runner2.stacktest" , "Stack Test" , config . stackPath + " test" ) ;
42
+ util . registerSimplTerm ( context , "runner2.stackbuild" , "Stack Build" , config . stackPath + " build" ) ;
43
+ util . registerSimplTerm ( context , "runner2.stackrun" , "Stack Run" , config . stackPath + " run" ) ;
48
44
49
45
// button setup
50
- context . subscriptions . push ( util . statButton ( "Load GHCi" , "runner2.ghci" ) ) ;
46
+ util . resgisterStatButton ( context , "Load GHCi" , "runner2.ghci" ) ;
51
47
// button for stack project
52
48
if ( stackproj ) {
53
- context . subscriptions . push (
54
- util . statButton ( "Stack Build" , "runner2.stackbuild" ) ,
55
- util . statButton ( "Stack Test" , "runner2.stacktest" )
56
- ) ;
49
+ util . resgisterStatButton ( context , "Stack Build" , "runner2.stackbuild" ) ;
50
+ util . resgisterStatButton ( context , "Stack Test" , "runner2.stacktest" ) ;
57
51
if ( config . enableStackRun ) {
58
- context . subscriptions . push (
59
- util . statButton ( "Stack Run" , "runner2.stackrun" ) ) ;
52
+ util . resgisterStatButton ( context , "Stack Run" , "runner2.stackrun" ) ;
60
53
}
61
54
}
62
-
63
55
}
64
56
65
57
// this method is called when your extension is deactivated
0 commit comments