Skip to content

Commit 386f8eb

Browse files
committed
feat: update session management to store launch configuration and target cluster in workspace state
Signed-off-by: Gordon Smith <[email protected]>
1 parent 6ee3583 commit 386f8eb

File tree

6 files changed

+44
-23
lines changed

6 files changed

+44
-23
lines changed

.github/copilot-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ How to apply:
128128
- Before adding a new contribution, confirm an existing pattern in `package.json` (e.g. replicate a command object, adjust `enablement`).
129129
- For a new Tree View / data provider, follow existing HPCC platform tree patterns under `src/hpccplatform/` and reference TreeDataProvider docs.
130130
- For new notebook renderer: add entry in `esbuild.mjs` (browser target) + `notebookRenderer` contribution + MIME type contract.
131-
- For status bar interactions replicate existing approach (search for usages setting `ecl.launchConfiguration` & `ecl.targetCluster`).
131+
- For status bar interactions replicate existing approach (launch configuration and target cluster state is stored in workspace state, not settings).
132132

133133
When unsure of an API surface (e.g. `WorkspaceEdit`, `TextDocumentContentProvider`, etc.) prefer stable APIs listed in the vscode-api reference; avoid proposed APIs unless already adopted in this repo.
134134

.vscode/launch.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@
144144
"<node_internals>/**"
145145
],
146146
"type": "node"
147+
},
148+
{
149+
"name": "localhost",
150+
"type": "ecl",
151+
"request": "launch",
152+
"protocol": "http",
153+
"serverAddress": "localhost",
154+
"port": 8010,
155+
"targetCluster": "thor",
156+
"rejectUnauthorized": true,
157+
"resultLimit": 100,
158+
"timeoutSecs": 60,
159+
"user": "vscode_user",
147160
}
148161
]
149162
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,13 +1625,15 @@
16251625
"type": "string",
16261626
"scope": "resource",
16271627
"default": "",
1628-
"description": "%Default launch configuration%"
1628+
"description": "%Default launch configuration%",
1629+
"deprecationMessage": "%This setting is deprecated. Launch configuration state is now stored in workspace state.%"
16291630
},
16301631
"ecl.targetCluster": {
16311632
"type": "object",
16321633
"scope": "resource",
16331634
"default": {},
1634-
"description": "%Target cluster (per launch configuration)%"
1635+
"description": "%Target cluster (per launch configuration)%",
1636+
"deprecationMessage": "%This setting is deprecated. Target cluster state is now stored in workspace state.%"
16351637
},
16361638
"ecl.pinnedLaunchConfigurations": {
16371639
"type": "object",

package.nls.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
"Database Name": "Database Name",
5353
"Debug level logging (requires restart)": "Debug level logging (requires restart)",
5454
"Default launch configuration": "Default launch configuration",
55+
"This setting is deprecated. Launch configuration state is now stored in workspace state.": "This setting is deprecated. Launch configuration state is now stored in workspace state.",
56+
"This setting is deprecated. Target cluster state is now stored in workspace state.": "This setting is deprecated. Target cluster state is now stored in workspace state.",
5557
"Dismiss": "Dismiss",
5658
"Default timeout (secs)": "Default timeout (secs)",
5759
"Delete Workunit": "Delete Workunit",

src/ecl/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ECLWatchPanelView } from "./eclWatchPanelView";
1212
import { HPCCResources } from "./hpccResources";
1313
import { ECLChat } from "./lm/chat";
1414
import { ECLLMTools } from "./lm/tools";
15-
import { sessionManager } from "../hpccplatform/session";
15+
import { SessionManager } from "../hpccplatform/session";
1616

1717
const eclConfig = vscode.workspace.getConfiguration("ecl");
1818
initLogger(eclConfig.get<boolean>("debugLogging") ? Level.debug : Level.info);
@@ -21,7 +21,7 @@ const logger = scopedLogger("ecl/main.ts");
2121

2222
export function activate(ctx: vscode.ExtensionContext): void {
2323
logger.debug("Activating SessionManager");
24-
sessionManager.initialize();
24+
SessionManager.attach(ctx);
2525
logger.debug("Activating ECLDiagnostic");
2626
ECLDiagnostic.attach(ctx);
2727
logger.debug("Activating ECLCommands");

src/hpccplatform/session.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,11 @@ export interface ICreateWorkunit {
149149
workunit: Workunit
150150
}
151151

152-
class SessionManager {
152+
export let sessionManager: SessionManager;
153153

154+
export class SessionManager {
155+
156+
private _context?: vscode.ExtensionContext;
154157
private _globalSession?: Session;
155158
private _pinnedSession?: Session;
156159

@@ -164,12 +167,10 @@ class SessionManager {
164167
private _statusBarTargetCluster: vscode.StatusBarItem;
165168
private _statusBarPin: vscode.StatusBarItem;
166169

167-
constructor() {
170+
private constructor(context: vscode.ExtensionContext) {
171+
this._context = context;
168172
this._statusBarLaunch = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, Number.MIN_VALUE + 2);
169173
this._statusBarLaunch.command = "hpccPlatform.switch";
170-
}
171-
172-
initialize() {
173174
this._statusBarTargetCluster = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, Number.MIN_VALUE + 1);
174175
this._statusBarTargetCluster.command = "hpccPlatform.switchTargetCluster";
175176

@@ -260,17 +261,14 @@ class SessionManager {
260261
void this.switchTo(this.session.id, this.session.overriddenTargetCluster);
261262
}
262263
}
263-
if (e.affectsConfiguration("ecl.launchConfiguration") || e.affectsConfiguration("ecl.targetCluster")) {
264-
const currentEclConfig = vscode.workspace.getConfiguration("ecl", null);
265-
const launchConfig = currentEclConfig.get<string>("launchConfiguration");
266-
const targetCluster = currentEclConfig.get<object>("targetCluster")[launchConfig];
267-
void this.switchTo(launchConfig, targetCluster);
268-
}
269264
});
270265

271266
const eclConfig = vscode.workspace.getConfiguration("ecl", null);
272-
const launchConfig = eclConfig.get<string>("launchConfiguration");
273-
const targetCluster = eclConfig.get<object>("targetCluster")[launchConfig];
267+
const settingsLaunchConfig = eclConfig.get<string>("launchConfiguration");
268+
const launchConfig = this._context.workspaceState.get<string>("ecl.launchConfiguration") || settingsLaunchConfig;
269+
const targetClusters = this._context.workspaceState.get<Record<string, string>>("ecl.targetCluster") || eclConfig.get<object>("targetCluster");
270+
const targetCluster = targetClusters[launchConfig];
271+
274272
this.switchTo(launchConfig, targetCluster).then(() => {
275273
vscode.commands.executeCommand("setContext", "hpccPlatformActive", true);
276274
}).finally(() => {
@@ -280,6 +278,13 @@ class SessionManager {
280278
});
281279
}
282280

281+
static attach(ctx: vscode.ExtensionContext): SessionManager {
282+
if (!sessionManager) {
283+
sessionManager = new SessionManager(ctx);
284+
}
285+
return sessionManager;
286+
}
287+
283288
private get activeDocument() {
284289
return vscode.window.activeTextEditor?.document;
285290
}
@@ -438,16 +443,16 @@ class SessionManager {
438443
}
439444
}
440445
} else {
441-
const currentLaunchConfig = eclConfig.get<string>("launchConfiguration");
442-
const targetClusters = eclConfig.get<object>("targetCluster");
446+
const currentLaunchConfig = this._context.workspaceState.get<string>("ecl.launchConfiguration");
447+
const targetClusters = this._context.workspaceState.get<Record<string, string>>("ecl.targetCluster") || {};
443448
const currentTargetCluster = targetClusters[this.session.id];
444449

445450
if (currentLaunchConfig !== this.session.id) {
446-
eclConfig.update("launchConfiguration", this.session.id);
451+
void this._context.workspaceState.update("ecl.launchConfiguration", this.session.id);
447452
}
448453
if (currentTargetCluster !== this.session.overriddenTargetCluster) {
449454
targetClusters[this.session.id] = this.session.overriddenTargetCluster;
450-
eclConfig.update("targetCluster", targetClusters);
455+
void this._context.workspaceState.update("ecl.targetCluster", targetClusters);
451456
}
452457
}
453458
}
@@ -611,7 +616,6 @@ class SessionManager {
611616
this.refreshPinStatusBar();
612617
}
613618
}
614-
export const sessionManager: SessionManager = new SessionManager();
615619

616620
export function isPlatformConnected(): boolean {
617621
return !!sessionManager.session;

0 commit comments

Comments
 (0)