@@ -161,6 +161,7 @@ class ScopeTreeItem extends TreeItem {
161161 constructor (
162162 provider : TreeDataProvider ,
163163 readonly scope : Scope ,
164+ readonly hasSiblings : boolean ,
164165 ) {
165166 super ( provider ) ;
166167 }
@@ -183,19 +184,23 @@ class ScopeTreeItem extends TreeItem {
183184 }
184185 treeItem . command = this . scope . location . asOpenCommand ( ) ;
185186 }
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 ;
188192 }
189193 return treeItem ;
190194 }
191195 }
192196
193197 override async getChildren ( ) : Promise < TreeItem [ ] > {
198+ const [ subScopes , variables ] = await Promise . all ( [ this . scope . scopes , this . scope . variables ] ) ;
194199 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 ) ) ;
197202 }
198- for ( const variable of await this . scope . variables ) {
203+ for ( const variable of variables ) {
199204 if ( variable instanceof ScalarVariable ) {
200205 children . push ( new ScalarTreeItem ( this . provider , variable . designation ( ) ,
201206 variable . width > 1 ? 'canWatch|canSetRadix' : 'canWatch' ) ) ;
@@ -281,7 +286,7 @@ export class TreeDataProvider implements vscode.TreeDataProvider<TreeItem> {
281286 if ( session !== null ) {
282287 this . observer = new Observer ( session , 'sidebar' ) ;
283288 this . watchTreeItem = new WatchTreeItem ( this ) ;
284- this . scopeTreeItem = new ScopeTreeItem ( this , await session . getRootScope ( ) ) ;
289+ this . scopeTreeItem = new ScopeTreeItem ( this , await session . getRootScope ( ) , false ) ;
285290 } else {
286291 this . observer ?. dispose ( ) ;
287292 this . observer = null ;
0 commit comments