1
1
import * as vscode from 'vscode' ;
2
2
import * as path from 'path' ;
3
- import { func } from 'vscode-languageclient/lib/utils/is' ;
3
+ import { array , func } from 'vscode-languageclient/lib/utils/is' ;
4
4
import { strict } from 'assert' ;
5
5
import { Func } from 'mocha' ;
6
6
@@ -11,20 +11,36 @@ function getIconUri(iconName: string, theme: string): vscode.Uri {
11
11
return vscode . Uri . file ( path . join ( iconsRootPath , theme , `${ iconName } .svg` ) ) ;
12
12
}
13
13
14
+ /// Runnable.
15
+
16
+ type Node = Workspace | Crate | Module | Function ;
17
+
18
+ enum NodeKind {
19
+ Workspace ,
20
+ Crate ,
21
+ Module ,
22
+ Function ,
23
+ }
24
+
25
+ type Session = Iterable < Workspace > ;
26
+
14
27
interface Workspace {
28
+ kind : NodeKind . Workspace ,
15
29
id : string ,
16
30
crates : Crate [ ] ,
17
31
location : string ,
18
32
}
19
33
20
34
interface Crate {
35
+ kind : NodeKind . Crate ,
21
36
id : string ,
22
37
name : string ,
23
38
modules : Module [ ] ,
24
39
location : string ,
25
40
}
26
41
27
42
interface Module {
43
+ kind : NodeKind . Module ,
28
44
id : string ,
29
45
name : string ,
30
46
modules ?: Module [ ] ,
@@ -38,16 +54,50 @@ enum TestKind {
38
54
}
39
55
40
56
interface Function {
57
+ kind : NodeKind . Function ,
41
58
id : string ,
42
59
name : string ,
43
60
location : string ,
44
- kind : TestKind ,
61
+ testKind : TestKind ,
62
+ }
63
+
64
+ /// The view synchronized with RA data by `DeltaUpdate`'s. The update is an array
65
+ /// of elementary actions called a `Patch`. After applying an update to the tree
66
+ /// it will become synchronized.
67
+
68
+ type DeltaUpdate = Iterable < Patch > ;
69
+
70
+ type Patch = Delete | Update | Create ;
71
+
72
+ enum PatchKind {
73
+ Delete = "DELETE" ,
74
+ Update = "UPDATE" ,
75
+ Create = "CREATE"
76
+ }
77
+
78
+ interface Delete {
79
+ kind : PatchKind . Delete ,
80
+ targetId : string ,
81
+ }
82
+
83
+ interface Update {
84
+ kind : PatchKind . Update ,
85
+ targetId : string ,
86
+ payload : {
87
+ name ?: string ,
88
+ location ?: string ,
89
+ testKind ?: TestKind ,
90
+ } ,
91
+ }
92
+
93
+ interface Create {
94
+ kind : PatchKind . Create ,
95
+ targetId : string ,
96
+ payload : Node ,
45
97
}
46
98
47
99
class Workspace extends vscode . TreeItem {
48
- get description ( ) : string {
49
- return this . location ;
50
- }
100
+ description = this . location ;
51
101
52
102
iconPath = {
53
103
light : getIconUri ( 'squares' , 'dark' ) ,
@@ -69,11 +119,10 @@ class Crate extends vscode.TreeItem {
69
119
super ( name , vscode . TreeItemCollapsibleState . Collapsed ) ;
70
120
this . location = location ;
71
121
this . id = id ;
122
+ this . modules = modules ;
72
123
}
73
124
74
- get description ( ) : string {
75
- return this . location ;
76
- }
125
+ description = this . location ;
77
126
78
127
iconPath = {
79
128
light : getIconUri ( 'squares' , 'dark' ) ,
@@ -98,9 +147,7 @@ class Module extends vscode.TreeItem {
98
147
this . id = id ;
99
148
}
100
149
101
- get description ( ) : string {
102
- return this . location ;
103
- }
150
+ description = this . location ;
104
151
105
152
iconPath = {
106
153
light : getIconUri ( 'squares' , 'dark' ) ,
@@ -148,18 +195,14 @@ class Function extends vscode.TreeItem {
148
195
}
149
196
}
150
197
151
- get description ( ) : string {
152
- return this . location ;
153
- }
198
+ description = this . location ;
154
199
155
200
getChildren ( ) : null {
156
201
return null ;
157
202
}
158
203
}
159
204
160
- type Node = Workspace | Crate | Module | Function ;
161
-
162
- function bfs ( root : Node , process : ( node : Node ) => void ) {
205
+ function bfs ( root : Node , process : ( parentField : Node [ ] , node : Node ) => void ) {
163
206
let queue : Array < Node > = [ root ] ;
164
207
while ( queue . length != 0 ) {
165
208
let current = queue . pop ( ) ;
@@ -189,59 +232,109 @@ export class RunnableDataProvider implements vscode.TreeDataProvider<Node> {
189
232
190
233
export class RunnableView {
191
234
private dataProvider : RunnableDataProvider ;
192
- private data : Node ;
235
+ private tree : Node ;
193
236
194
237
constructor ( context : vscode . ExtensionContext ) {
195
238
this . dataProvider = new RunnableDataProvider ( )
196
239
}
197
-
198
- public applyUpdate ( deltaUpdate : Patch [ ] ) {
199
- deltaUpdate . map ( ( patch ) => {
200
- switch ( patch . kind ) {
201
- case PatchKind . Create :
202
- find ( patch . targetId ) ;
203
- break ;
204
- case PatchKind . Delete :
205
- find ( ) ;
206
- break ;
207
- case PatchKind . Update :
208
- find ( ) ;
209
- break ;
240
+
241
+ handleCreate ( node : Node , patch : Create ) {
242
+ switch ( node . kind ) {
243
+ case NodeKind . Workspace : {
244
+ if ( patch . payload . kind != NodeKind . Crate ) {
245
+ throw Error ( `${ patch . payload . kind } cant't be payload for ${ NodeKind . Workspace } target` ) ;
246
+ }
247
+ node . crates . push ( patch . payload ) ;
248
+ }
249
+ break ;
250
+ case NodeKind . Crate : {
251
+ if ( patch . payload . kind != NodeKind . Module ) {
252
+ throw Error ( `${ patch . payload . kind } cant't be payload for ${ NodeKind . Crate } target` ) ;
253
+ }
254
+ node . modules . push ( patch . payload ) ;
210
255
}
211
- } ) ;
256
+ break ;
257
+ case NodeKind . Module : {
258
+ if ( patch . payload . kind == NodeKind . Module ) {
259
+ if ( node . modules == undefined ) {
260
+ node . modules = [ ] ;
261
+ }
262
+ node . modules ! . push ( patch . payload ) ;
263
+ } else if ( patch . payload . kind == NodeKind . Function ) {
264
+ if ( node . modules == undefined ) {
265
+ node . modules = [ ] ;
266
+ }
267
+ node . targets ! . push ( patch . payload ) ;
268
+ } else {
269
+ throw Error ( `${ patch . payload . kind } cant't be payload for ${ NodeKind . Module } target` ) ;
270
+ }
271
+ }
272
+ break ;
273
+ case NodeKind . Function : {
274
+ throw Error ( "Function can't be a target for Create's patch" ) ;
275
+ }
276
+ }
212
277
}
213
- }
214
-
215
- /// The view synchronized with RA data by delta updates. The update is an array
216
- /// of elementary actions called a `Patch`. After applying an update to the tree
217
- /// it will become synchronized.
218
-
219
- type Patch = Delete | Update | Create ;
220
278
221
- enum PatchKind {
222
- Delete = "DELETE" ,
223
- Update = "UPDATE" ,
224
- Create = "CREATE"
225
- }
279
+ handleDelete ( node : Node , parentField : Array < Node > ) {
280
+ const index = parentField . indexOf ( node ) ;
281
+ parentField . splice ( index , 1 ) ;
282
+ }
226
283
227
- interface Delete {
228
- kind : PatchKind . Delete ,
229
- id : string ,
230
- }
284
+ handleUpdate ( node : Node , patch : Update ) {
285
+ switch ( node . kind ) {
286
+ case NodeKind . Workspace : {
287
+ node . location = patch . payload . location ! ;
288
+ }
289
+ break ;
290
+ case NodeKind . Crate : {
291
+ node . location = patch . payload . location ! ;
292
+ node . name = patch . payload . name ! ;
293
+ }
294
+ break ;
295
+ case NodeKind . Module : {
296
+ node . name = patch . payload . name ! ;
297
+ node . location = patch . payload . location ! ;
298
+ }
299
+ break ;
300
+ case NodeKind . Function : {
301
+ node . name = patch . payload . name ! ;
302
+ node . location = patch . payload . location ! ;
303
+ node . testKind = patch . payload . testKind ! ;
304
+ }
305
+ break ;
306
+ }
307
+ }
231
308
232
- interface Update {
233
- kind : PatchKind . Update ,
234
- payload : {
235
- name ?: string ,
236
- location ?: string ,
237
- kind ?: TestKind ,
238
- } ,
309
+ public applyUpdate ( update : DeltaUpdate ) {
310
+ for ( let patch of update ) {
311
+ bfs ( this . tree , ( parentField , node ) => {
312
+ if ( node . id == patch . targetId ) {
313
+ switch ( patch . kind ) {
314
+ case PatchKind . Create : {
315
+ this . handleCreate ( node , patch ) ;
316
+ }
317
+ break ;
318
+ case PatchKind . Delete : {
319
+ this . handleDelete ( node , parentField )
320
+ }
321
+ break ;
322
+ case PatchKind . Update : {
323
+ this . handleUpdate ( node , patch )
324
+ }
325
+ break ;
326
+ }
327
+ }
328
+ } )
329
+ }
330
+ }
239
331
}
240
332
241
- interface Create {
242
- kind : PatchKind . Create ,
243
- targetId : string ,
244
- payload : Node ,
333
+ export class TestView {
334
+
335
+ constructor ( ) {
336
+ let controller = vscode . tests . createTestController ( ) ;
337
+ }
245
338
}
246
339
247
340
// function runExecutable() {
0 commit comments