@@ -6,6 +6,10 @@ import { TargetKind, NodeKind, type TestLikeNodeKind, type TestLocation } from "
6
6
7
7
/**
8
8
* A wrapper of `ra.Runnable` to provide typed/cached information rather than string.
9
+ *
10
+ * An important asumption is the format of `label` is
11
+ * - if test, "test test::path". Because test always has name, so the later part could not be empty.
12
+ * - if test module, "test-mod test::path". Attention, the later part could be empty if it's the root module of a target.
9
13
*/
10
14
export class RunnableFacde {
11
15
public readonly origin : ra . Runnable ;
@@ -30,16 +34,20 @@ export class RunnableFacde {
30
34
31
35
get workspaceRoot ( ) : string {
32
36
if ( this . _workspaceRoot ) return this . _workspaceRoot ;
37
+
33
38
const workspaceRoot = this . origin . args . workspaceRoot ;
39
+
34
40
assert ( ! ! workspaceRoot ) ;
41
+
35
42
return this . _workspaceRoot = workspaceRoot ;
36
43
}
37
44
38
45
private _testKind ?: TestLikeNodeKind ;
39
46
40
47
get testKind ( ) : TestLikeNodeKind {
41
- if ( this . _testKind ) { return this . _testKind ; }
48
+ if ( this . _testKind ) return this . _testKind ;
42
49
const testKindString = this . origin . label . split ( ' ' ) [ 0 ] ;
50
+
43
51
switch ( testKindString ) {
44
52
case 'test' :
45
53
return this . _testKind = NodeKind . Test ;
@@ -81,7 +89,8 @@ export class RunnableFacde {
81
89
private _targetKind ?: TargetKind ;
82
90
83
91
get targetKind ( ) : TargetKind {
84
- if ( this . _targetKind ) { return this . _targetKind ; }
92
+ if ( this . _targetKind ) return this . _targetKind ;
93
+
85
94
switch ( true ) {
86
95
case this . origin . args . cargoArgs . includes ( "--lib" ) :
87
96
return this . _targetKind = TargetKind . Library ;
@@ -97,11 +106,15 @@ export class RunnableFacde {
97
106
private _packageName ?: string ;
98
107
99
108
get packageName ( ) : string {
100
- if ( this . _packageName ) { return this . _packageName ; }
109
+ if ( this . _packageName ) return this . _packageName ;
110
+
101
111
const packageQualifiedNameIndex = this . origin . args . cargoArgs . findIndex ( arg => arg === "--package" ) + 1 ;
112
+
102
113
// The format of `packageQualifiedName` is `name:version`, like `hello:1.2.3`
103
114
const packageQualifiedName = this . origin . args . cargoArgs [ packageQualifiedNameIndex ] ;
115
+
104
116
assert ( ! ! packageQualifiedName , "There should be a value for '--package' in runnable" ) ;
117
+
105
118
return this . _packageName = packageQualifiedName . split ( ':' ) [ 0 ] ! ;
106
119
}
107
120
@@ -111,14 +124,18 @@ export class RunnableFacde {
111
124
* Only have value if `targetKind` is `TargetKind.IntegrationTest`
112
125
*/
113
126
get integrationTestFileName ( ) : string | null {
114
- if ( this . _integrationTestFileName !== undefined ) { return this . _integrationTestFileName ; }
127
+
128
+ if ( this . _integrationTestFileName !== undefined ) return this . _integrationTestFileName ;
129
+
115
130
const integrationTestFileNameIndex = this . origin . args . cargoArgs . findIndex ( arg => arg === "--test" ) + 1 ;
131
+
116
132
if ( integrationTestFileNameIndex === 0 ) {
117
133
this . _integrationTestFileName = null ;
118
134
} else {
119
135
this . _integrationTestFileName = this . origin . args . cargoArgs [ integrationTestFileNameIndex ] ;
120
136
assert ( typeof this . _integrationTestFileName === "string" , "There should be a value for '--test' in runnable" ) ;
121
137
}
138
+
122
139
return this . _integrationTestFileName ;
123
140
}
124
141
@@ -128,22 +145,27 @@ export class RunnableFacde {
128
145
* Only have value if `targetKind` is `TargetKind.Binary`
129
146
*/
130
147
get binaryTestFileName ( ) : string | null {
131
- if ( this . _binaryTestFileName !== undefined ) { return this . _binaryTestFileName ; }
148
+ if ( this . _binaryTestFileName !== undefined ) return this . _binaryTestFileName ;
149
+
132
150
const integrationTestFileNameIndex = this . origin . args . cargoArgs . findIndex ( arg => arg === "--bin" ) + 1 ;
151
+
133
152
if ( integrationTestFileNameIndex === 0 ) {
134
153
this . _binaryTestFileName = null ;
135
154
} else {
136
155
this . _binaryTestFileName = this . origin . args . cargoArgs [ integrationTestFileNameIndex ] ;
137
156
assert ( typeof this . _binaryTestFileName === "string" , "There should be a value for '--bin' in runnable" ) ;
138
157
}
158
+
139
159
return this . _binaryTestFileName ;
140
160
}
141
161
142
162
private _uri ?: vscode . Uri ;
143
163
144
164
get uri ( ) : vscode . Uri {
145
- if ( this . _uri ) { return this . _uri ; }
165
+ if ( this . _uri ) return this . _uri ;
166
+
146
167
assert ( ! ! this . origin . location ?. targetUri , "Need to investigate why targetUri is undefined" ) ;
168
+
147
169
return this . _uri = vscode . Uri . parse ( this . origin . location . targetUri ) ;
148
170
}
149
171
@@ -156,6 +178,7 @@ export class RunnableFacde {
156
178
*/
157
179
get isTestModuleDeclarationRunnable ( ) {
158
180
assert ( this . testKind === NodeKind . TestModule , "Only compare definition for test module." ) ;
181
+
159
182
return ! this . isTestModuleFileDefinitionRunnable
160
183
// filter out module with items
161
184
// Not accurate. But who will write `mode xxx { ... }` in one line?
@@ -167,6 +190,7 @@ export class RunnableFacde {
167
190
*/
168
191
get isTestModuleWithItemsRunnable ( ) {
169
192
assert ( this . testKind === NodeKind . TestModule , "Only compare definition for test module." ) ;
193
+
170
194
return ! this . isTestModuleFileDefinitionRunnable
171
195
&& ! this . isTestModuleDeclarationRunnable ;
172
196
}
@@ -176,8 +200,11 @@ export class RunnableFacde {
176
200
*/
177
201
get isTestModuleFileDefinitionRunnable ( ) {
178
202
const runnable = this . origin ;
203
+
179
204
assert ( this . testKind === NodeKind . TestModule , "Only compare definition for test module." ) ;
205
+
180
206
assert ( ! ! runnable . location , "Should always have location" ) ;
207
+
181
208
return isRangeValueEqual (
182
209
runnable . location . targetRange ,
183
210
runnable . location . targetSelectionRange ,
0 commit comments