@@ -9,6 +9,8 @@ import * as Utils from "../models/utils";
99import { IConnectionGroup , IConnectionProfile } from "../models/interfaces" ;
1010import { IConnectionConfig } from "./iconnectionconfig" ;
1111import VscodeWrapper , { ConfigurationTarget } from "../controllers/vscodeWrapper" ;
12+
13+ export { ConfigurationTarget } ;
1214import { ConnectionProfile } from "../models/connectionProfile" ;
1315import { getConnectionDisplayName } from "../models/connectionInfo" ;
1416import { Deferred } from "../protocol" ;
@@ -291,8 +293,11 @@ export class ConnectionConfig implements IConnectionConfig {
291293 * @returns The connection group with the specified ID, or `undefined` if not found.
292294 */
293295 public getGroupById ( id : string ) : IConnectionGroup | undefined {
294- const connGroups = this . getGroupsFromSettings ( ConfigurationTarget . Global ) ;
295- return connGroups . find ( ( g ) => g . id === id ) ;
296+ // Search both user and workspace groups for the given ID
297+ const userGroups = this . getGroupsFromSettings ( ConfigurationTarget . Global ) ;
298+ const workspaceGroups = this . getGroupsFromSettings ( ConfigurationTarget . Workspace ) ;
299+ const allGroups = [ ...userGroups , ...workspaceGroups ] ;
300+ return allGroups . find ( ( g ) => g . id === id ) ;
296301 }
297302
298303 public addGroup ( group : IConnectionGroup ) : Promise < void > {
@@ -501,82 +506,101 @@ export class ConnectionConfig implements IConnectionConfig {
501506
502507 private async assignConnectionGroupMissingIds ( ) : Promise < void > {
503508 let madeChanges = false ;
504- const groups : IConnectionGroup [ ] = this . getGroupsFromSettings ( ) ;
505- let connections : IConnectionProfile [ ] = this . getConnectionsFromSettings ( ) ;
509+ // User groups and connections
510+ const userGroups : IConnectionGroup [ ] = this . getGroupsFromSettings (
511+ ConfigurationTarget . Global ,
512+ ) ;
513+ let userConnections : IConnectionProfile [ ] = this . getConnectionsFromSettings (
514+ ConfigurationTarget . Global ,
515+ ) ;
516+ // Workspace groups and connections
517+ const workspaceGroups : IConnectionGroup [ ] = this . getGroupsFromSettings (
518+ ConfigurationTarget . Workspace ,
519+ ) ;
520+ let workspaceConnections : IConnectionProfile [ ] = this . getConnectionsFromSettings (
521+ ConfigurationTarget . Workspace ,
522+ ) ;
506523
507- // ensure ROOT group exists
508- let rootGroup = await this . getRootGroup ( ) ;
524+ // ensure ROOT group exists in user settings
525+ let rootGroup = userGroups . find ( ( g ) => g . name === ConnectionConfig . RootGroupName ) ;
509526 if ( ! rootGroup ) {
510527 rootGroup = {
511528 name : ConnectionConfig . RootGroupName ,
512529 id : Utils . generateGuid ( ) ,
513530 } ;
514- this . _logger . logDebug ( `Adding missing ROOT group to connection groups` ) ;
531+ userGroups . push ( rootGroup ) ;
515532 madeChanges = true ;
516- groups . push ( rootGroup ) ;
533+ this . _logger . logDebug ( `Adding missing ROOT group to user connection groups` ) ;
517534 }
518535
519- // Check for User Connections and Workspace Connections under ROOT
520- let userConnectionsGroup = groups . find (
536+ // Ensure User Connections group exists in user settings
537+ let userConnectionsGroup = userGroups . find (
521538 ( g ) => g . name === "User Connections" && g . parentId === rootGroup . id ,
522539 ) ;
523- let workspaceConnectionsGroup = groups . find (
524- ( g ) => g . name === "Workspace Connections" && g . parentId === rootGroup . id ,
525- ) ;
526-
527540 if ( ! userConnectionsGroup ) {
528541 userConnectionsGroup = {
529542 name : "User Connections" ,
530543 id : Utils . generateGuid ( ) ,
531544 parentId : rootGroup . id ,
532545 } ;
533- groups . push ( userConnectionsGroup ) ;
546+ userGroups . push ( userConnectionsGroup ) ;
534547 madeChanges = true ;
535548 this . _logger . logDebug ( `Created 'User Connections' group under ROOT` ) ;
536549 }
550+
551+ // Ensure Workspace Connections group exists in workspace settings, parented to ROOT (user)
552+ let workspaceConnectionsGroup = workspaceGroups . find (
553+ ( g ) => g . name === "Workspace Connections" && g . parentId === rootGroup . id ,
554+ ) ;
537555 if ( ! workspaceConnectionsGroup ) {
538556 workspaceConnectionsGroup = {
539557 name : "Workspace Connections" ,
540558 id : Utils . generateGuid ( ) ,
541559 parentId : rootGroup . id ,
542560 } ;
543- groups . push ( workspaceConnectionsGroup ) ;
561+ workspaceGroups . push ( workspaceConnectionsGroup ) ;
544562 madeChanges = true ;
545- this . _logger . logDebug ( `Created 'Workspace Connections' group under ROOT` ) ;
563+ this . _logger . logDebug ( `Created 'Workspace Connections' group under ROOT (user) ` ) ;
546564 }
547565
548- // Reparent all groups directly under ROOT (except the two new groups) to User Connections
549- for ( const group of groups ) {
550- if (
551- group . parentId === rootGroup . id &&
552- group . id !== userConnectionsGroup . id &&
553- group . id !== workspaceConnectionsGroup . id
554- ) {
555- group . parentId = userConnectionsGroup . id ;
566+ // Reparent all workspace groups directly under ROOT to Workspace Connections group
567+ for ( const group of workspaceGroups ) {
568+ if ( group . parentId === rootGroup . id && group . id !== workspaceConnectionsGroup . id ) {
569+ group . parentId = workspaceConnectionsGroup . id ;
556570 madeChanges = true ;
557- this . _logger . logDebug ( `Reparented group '${ group . name } ' to 'User Connections'` ) ;
571+ this . _logger . logDebug (
572+ `Reparented workspace group '${ group . name } ' to 'Workspace Connections'` ,
573+ ) ;
558574 }
559575 }
560576
561- // Reparent all connections directly under ROOT to User Connections
562- for ( const conn of connections ) {
563- // If connection is under ROOT or has no group, move to User Connections
577+ // Reparent all workspace connections directly under ROOT to Workspace Connections group
578+ for ( const conn of workspaceConnections ) {
564579 if ( ! conn . groupId || conn . groupId === rootGroup . id ) {
565- conn . groupId = userConnectionsGroup . id ;
580+ conn . groupId = workspaceConnectionsGroup . id ;
566581 madeChanges = true ;
567582 this . _logger . logDebug (
568- `Reparented connection '${ getConnectionDisplayName ( conn ) } ' to 'User Connections'` ,
583+ `Reparented workspace connection '${ getConnectionDisplayName ( conn ) } ' to 'Workspace Connections'` ,
569584 ) ;
570585 }
571586 }
572587
573- // Save the changes to settings
588+ // Save changes to settings
574589 if ( madeChanges ) {
590+ this . _logger . logDebug ( `Writing updated user groups and connections to user settings.` ) ;
591+ await this . writeConnectionGroupsToSettings ( userGroups ) ;
592+ await this . writeConnectionsToSettings ( userConnections ) ;
575593 this . _logger . logDebug (
576- `Updates made to connection groups. Writing all ${ groups . length } group(s) to settings.` ,
594+ `Writing updated workspace groups and connections to workspace settings.` ,
595+ ) ;
596+ await this . writeConnectionGroupsToSettingsWithTarget (
597+ workspaceGroups ,
598+ ConfigurationTarget . Workspace ,
599+ ) ;
600+ await this . writeConnectionsToSettings (
601+ workspaceConnections ,
602+ ConfigurationTarget . Workspace ,
577603 ) ;
578- await this . writeConnectionGroupsToSettings ( groups ) ;
579- await this . writeConnectionsToSettings ( connections ) ;
580604 }
581605 }
582606
0 commit comments