11import * as vscode from 'vscode' ;
22import { ServerTreeProviderBase } from './ServerTreeProviderBase' ;
33import { CONNECTION_TREE_ITEM_CONTEXT , ICON_ID } from '../common' ;
4- import type {
5- IDhcService ,
6- ConnectionState ,
7- ConsoleType ,
8- ServerConnectionNode ,
9- } from '../types' ;
4+ import type { ConsoleType , ServerConnectionNode } from '../types' ;
105import {
6+ getConnectionServerTreeItem ,
7+ getConnectionTreeRootNodes ,
118 getConsoleTypeIconId ,
129 isInstanceOf ,
10+ isServerStateNode ,
1311 sortByStringProp ,
1412} from '../util' ;
1513import { DhcService } from '../services' ;
@@ -20,29 +18,31 @@ import { getServerMatchPortIfLocalHost } from '../mcp/utils';
2018 */
2119export class ServerConnectionTreeProvider extends ServerTreeProviderBase < ServerConnectionNode > {
2220 getTreeItem = async (
23- connectionOrUri : ServerConnectionNode
21+ node : ServerConnectionNode
2422 ) : Promise < vscode . TreeItem > => {
2523 // Uri node associated with a parent connection node
26- if ( connectionOrUri instanceof vscode . Uri ) {
24+ if ( node instanceof vscode . Uri ) {
2725 return {
28- description : connectionOrUri . path ,
26+ description : node . path ,
2927 contextValue : CONNECTION_TREE_ITEM_CONTEXT . isUri ,
3028 command : {
3129 command : 'vscode.open' ,
3230 title : 'Open Uri' ,
33- arguments : [ connectionOrUri ] ,
31+ arguments : [ node ] ,
3432 } ,
35- resourceUri : connectionOrUri ,
33+ resourceUri : node ,
3634 } ;
3735 }
3836
37+ // DHE server node grouping its worker connections.
38+ if ( isServerStateNode ( node ) ) {
39+ return getConnectionServerTreeItem ( node ) ;
40+ }
41+
3942 // Console type (language) drives the node icon rather than the description.
4043 let consoleType : ConsoleType | undefined ;
41- if (
42- isInstanceOf ( connectionOrUri , DhcService ) &&
43- connectionOrUri . isInitialized
44- ) {
45- [ consoleType ] = await connectionOrUri . getConsoleTypes ( ) ;
44+ if ( isInstanceOf ( node , DhcService ) && node . isInitialized ) {
45+ [ consoleType ] = await node . getConsoleTypes ( ) ;
4646 }
4747
4848 // Prefer the persistent query name (what the DHE Query Monitor shows) over
@@ -51,25 +51,33 @@ export class ServerConnectionTreeProvider extends ServerTreeProviderBase<ServerC
5151 // diverge from their query name; the PQ name is the stable identifier in
5252 // both cases. Falls back to tagId for plain DHC connections, which have no
5353 // associated WorkerInfo.
54- const workerInfo = await this . serverManager . getWorkerInfo (
55- connectionOrUri . serverUrl
56- ) ;
57- const description = workerInfo ?. name ?? connectionOrUri . tagId ?? '' ;
54+ const workerInfo = await this . serverManager . getWorkerInfo ( node . serverUrl ) ;
55+ const workerName = workerInfo ?. name ?? node . tagId ?? '' ;
56+
57+ const hasUris = this . serverManager . hasConnectionUris ( node ) ;
5858
59- const hasUris = this . serverManager . hasConnectionUris ( connectionOrUri ) ;
59+ // DHE worker nodes are nested under their server node, so the worker name
60+ // becomes the node label and the server label lives on the parent. Flat DHC
61+ // connections keep the server label as the node label and show the worker
62+ // name as the description.
63+ const isWorkerChild = this . serverManager . getServerForConnection ( node ) != null ;
6064
6165 const serverLabel = getServerMatchPortIfLocalHost (
6266 this . serverManager ,
63- connectionOrUri . serverUrl
67+ node . serverUrl
6468 ) ?. label ;
6569
66- const label = serverLabel ?? connectionOrUri . serverUrl . host ;
70+ const label = isWorkerChild
71+ ? workerName
72+ : ( serverLabel ?? node . serverUrl . host ) ;
73+
74+ const description = isWorkerChild ? undefined : workerName ;
6775
6876 // Connection node
6977 return {
7078 label,
7179 description,
72- contextValue : connectionOrUri . isConnected
80+ contextValue : node . isConnected
7381 ? CONNECTION_TREE_ITEM_CONTEXT . isConnectionConnected
7482 : CONNECTION_TREE_ITEM_CONTEXT . isConnectionConnecting ,
7583 collapsibleState : hasUris
@@ -78,22 +86,34 @@ export class ServerConnectionTreeProvider extends ServerTreeProviderBase<ServerC
7886 // Show the language (Python/Groovy) icon when idle/connected; show the
7987 // spinner while busy (connecting or running code).
8088 iconPath : new vscode . ThemeIcon (
81- connectionOrUri . isRunningCode || ! connectionOrUri . isConnected
89+ node . isRunningCode || ! node . isConnected
8290 ? ICON_ID . connecting
8391 : getConsoleTypeIconId ( consoleType )
8492 ) ,
8593 } ;
8694 } ;
8795
8896 getChildren = (
89- elementOrRoot ?: IDhcService
97+ elementOrRoot ?: ServerConnectionNode
9098 ) : vscode . ProviderResult < ServerConnectionNode [ ] > => {
99+ // Root: DHE server nodes + flat DHC connection nodes.
91100 if ( elementOrRoot == null ) {
101+ return getConnectionTreeRootNodes ( this . serverManager ) ;
102+ }
103+
104+ // Uri leaf nodes have no children.
105+ if ( elementOrRoot instanceof vscode . Uri ) {
106+ return [ ] ;
107+ }
108+
109+ // DHE server node -> its worker connections.
110+ if ( isServerStateNode ( elementOrRoot ) ) {
92111 return this . serverManager
93- . getConnections ( )
112+ . getConnections ( elementOrRoot . url )
94113 . sort ( sortByStringProp ( 'serverUrl' ) ) ;
95114 }
96115
116+ // Connection node -> its editor uris.
97117 return this . serverManager . getConnectionUris ( elementOrRoot ) ;
98118 } ;
99119
@@ -102,11 +122,16 @@ export class ServerConnectionTreeProvider extends ServerTreeProviderBase<ServerC
102122 * for `TreeView.reveal` method to work.
103123 * @param element
104124 */
105- getParent = ( element : ServerConnectionNode ) : ConnectionState | null => {
125+ getParent = ( element : ServerConnectionNode ) : ServerConnectionNode | null => {
106126 if ( element instanceof vscode . Uri ) {
107127 return this . serverManager . getUriConnection ( element ) ;
108128 }
109129
110- return null ;
130+ if ( isServerStateNode ( element ) ) {
131+ return null ;
132+ }
133+
134+ // Connection node -> its parent DHE server (or null for flat DHC).
135+ return this . serverManager . getServerForConnection ( element ) ?? null ;
111136 } ;
112137}
0 commit comments