@@ -161,6 +161,7 @@ class ScopeTreeItem extends TreeItem {
161
161
constructor (
162
162
provider : TreeDataProvider ,
163
163
readonly scope : Scope ,
164
+ readonly hasSiblings : boolean ,
164
165
) {
165
166
super ( provider ) ;
166
167
}
@@ -183,19 +184,23 @@ class ScopeTreeItem extends TreeItem {
183
184
}
184
185
treeItem . command = this . scope . location . asOpenCommand ( ) ;
185
186
}
186
- if ( ( await this . scope . scopes ) . length > 0 || ( await this . scope . variables ) . length > 0 ) {
187
- treeItem . collapsibleState = vscode . TreeItemCollapsibleState . Collapsed ;
187
+ const [ subScopes , variables ] = await Promise . all ( [ this . scope . scopes , this . scope . variables ] ) ;
188
+ if ( subScopes . length > 0 || variables . length > 0 ) {
189
+ treeItem . collapsibleState = this . hasSiblings ?
190
+ vscode . TreeItemCollapsibleState . Collapsed :
191
+ vscode . TreeItemCollapsibleState . Expanded ;
188
192
}
189
193
return treeItem ;
190
194
}
191
195
}
192
196
193
197
override async getChildren ( ) : Promise < TreeItem [ ] > {
198
+ const [ subScopes , variables ] = await Promise . all ( [ this . scope . scopes , this . scope . variables ] ) ;
194
199
const children = [ ] ;
195
- for ( const scope of await this . scope . scopes ) {
196
- children . push ( new ScopeTreeItem ( this . provider , scope ) ) ;
200
+ for ( const scope of subScopes ) {
201
+ children . push ( new ScopeTreeItem ( this . provider , scope , subScopes . length > 1 ) ) ;
197
202
}
198
- for ( const variable of await this . scope . variables ) {
203
+ for ( const variable of variables ) {
199
204
if ( variable instanceof ScalarVariable ) {
200
205
children . push ( new ScalarTreeItem ( this . provider , variable . designation ( ) ,
201
206
variable . width > 1 ? 'canWatch|canSetRadix' : 'canWatch' ) ) ;
@@ -281,7 +286,7 @@ export class TreeDataProvider implements vscode.TreeDataProvider<TreeItem> {
281
286
if ( session !== null ) {
282
287
this . observer = new Observer ( session , 'sidebar' ) ;
283
288
this . watchTreeItem = new WatchTreeItem ( this ) ;
284
- this . scopeTreeItem = new ScopeTreeItem ( this , await session . getRootScope ( ) ) ;
289
+ this . scopeTreeItem = new ScopeTreeItem ( this , await session . getRootScope ( ) , false ) ;
285
290
} else {
286
291
this . observer ?. dispose ( ) ;
287
292
this . observer = null ;
0 commit comments