1
1
import * as vscode from "vscode" ;
2
2
3
3
import { BaseNode } from "../basenode" ;
4
- import { Test , Tests } from "../../types" ;
4
+ import { Test , Tests , pseudoAllTarget } from "../../types" ;
5
5
import { extensionRelative } from "../../utils" ;
6
+ import { IRunnableNode } from "./base" ;
6
7
7
- export class TestRootNode extends BaseNode {
8
+ function getTestCommand ( isBenchmark : boolean ) : string {
9
+ return isBenchmark ? "benchmark" : "test" ;
10
+ }
11
+
12
+ export class TestRootNode extends BaseNode implements IRunnableNode {
8
13
constructor (
9
14
parentId : string ,
10
15
private readonly tests : Tests ,
11
16
private readonly isBenchmark : boolean ,
12
17
) {
13
- super ( `${ parentId } -${ isBenchmark ? "benchmarks" : "tests" } ` ) ;
18
+ super ( `${ parentId } -${ getTestCommand ( isBenchmark ) } ` ) ;
14
19
}
15
20
16
21
override getTreeItem ( ) {
@@ -21,39 +26,58 @@ export class TestRootNode extends BaseNode {
21
26
item . collapsibleState =
22
27
this . tests . length === 0 ? vscode . TreeItemCollapsibleState . None : vscode . TreeItemCollapsibleState . Collapsed ;
23
28
29
+ // To key in to "when": "view == meson-project && viewItem == meson-test-root" in package.json.
30
+ item . contextValue = "meson-test-root" ;
31
+
24
32
return item ;
25
33
}
26
34
27
35
override getChildren ( ) {
28
36
return this . tests . map ( ( test ) => new TestNode ( this . id , test , this . isBenchmark ) ) ;
29
37
}
38
+
39
+ run ( ) {
40
+ return vscode . commands . executeCommand ( `mesonbuild.${ getTestCommand ( this . isBenchmark ) } ` , pseudoAllTarget ) ;
41
+ }
30
42
}
31
43
32
- class TestNode extends BaseNode {
44
+ class TestNode extends BaseNode implements IRunnableNode {
45
+ private readonly taskName : string ;
46
+ private readonly command : string ;
47
+
33
48
constructor (
34
49
parentId : string ,
35
50
private readonly test : Test ,
36
51
private readonly isBenchmark : boolean ,
37
52
) {
38
53
super ( `${ parentId } -${ test . suite [ 0 ] } -${ test . name } ` ) ;
54
+
55
+ this . command = getTestCommand ( this . isBenchmark ) ;
56
+ const project = this . test . suite [ 0 ] . split ( ":" ) [ 0 ] ;
57
+ this . taskName = `${ project } :${ this . test . name } ` ;
39
58
}
40
59
41
60
override getTreeItem ( ) {
42
61
const item = super . getTreeItem ( ) as vscode . TreeItem ;
43
- const project = this . test . suite [ 0 ] . split ( ":" ) [ 0 ] ;
44
- const name = `${ project } :${ this . test . name } ` ;
45
62
46
63
item . label = this . test . name ;
47
64
item . iconPath = extensionRelative ( "res/meson_32.svg" ) ;
48
65
item . command = {
49
- title : `Run ${ this . isBenchmark ? "benchmark" : "test" } ` ,
50
- command : `mesonbuild.${ this . isBenchmark ? "benchmark" : "test" } ` ,
51
- arguments : [ name ] ,
66
+ title : `Run ${ this . command } ` ,
67
+ command : `mesonbuild.${ this . command } ` ,
68
+ arguments : [ this . taskName ] ,
52
69
} ;
53
70
54
71
// No children currently, so don't display toggle.
55
72
item . collapsibleState = vscode . TreeItemCollapsibleState . None ;
56
73
74
+ // To key in to "when": "view == meson-project && viewItem == meson-test" in package.json.
75
+ item . contextValue = "meson-test" ;
76
+
57
77
return item ;
58
78
}
79
+
80
+ run ( ) {
81
+ return vscode . commands . executeCommand ( `mesonbuild.${ this . command } ` , this . taskName ) ;
82
+ }
59
83
}
0 commit comments