Skip to content

Commit b22bb9f

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Update canary setting to allow for immediate toggle of button when variant analysis panel is open instead of needing to open/close for the setting change to take affect. (copilot)
1 parent 2eb9ac1 commit b22bb9f

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

extensions/ql-vscode/src/common/interface-types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,11 @@ interface SetVariantAnalysisMessage {
496496
isCanary?: boolean;
497497
}
498498

499+
interface SetCanaryStatusMessage {
500+
t: "setCanaryStatus";
501+
isCanary: boolean;
502+
}
503+
499504
interface SetFilterSortStateMessage {
500505
t: "setFilterSortState";
501506
filterSortState: RepositoriesFilterSortState;
@@ -560,7 +565,8 @@ export type ToVariantAnalysisMessage =
560565
| SetVariantAnalysisMessage
561566
| SetFilterSortStateMessage
562567
| SetRepoResultsMessage
563-
| SetRepoStatesMessage;
568+
| SetRepoStatesMessage
569+
| SetCanaryStatusMessage;
564570

565571
export type FromVariantAnalysisMessage =
566572
| CommonFromViewMessages

extensions/ql-vscode/src/variant-analysis/variant-analysis-view.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ViewColumn } from "vscode";
1+
import type { ConfigurationChangeEvent } from "vscode";
2+
import { ViewColumn, workspace } from "vscode";
23
import type { WebviewPanelConfig } from "../common/vscode/abstract-webview";
34
import { AbstractWebview } from "../common/vscode/abstract-webview";
45
import {
@@ -46,6 +47,40 @@ export class VariantAnalysisView
4647
manager.registerView(this);
4748

4849
this.dataFlowPathsView = new DataFlowPathsView(app);
50+
51+
// Set up configuration change listener
52+
this.push(
53+
workspace.onDidChangeConfiguration(
54+
this.onConfigurationChanged.bind(this),
55+
),
56+
);
57+
}
58+
59+
/**
60+
* Handler for configuration changes
61+
*/
62+
private onConfigurationChanged(e: ConfigurationChangeEvent): void {
63+
// Check if the canary setting has changed
64+
if (e.affectsConfiguration("codeQL.canary")) {
65+
void this.updateCanaryStatus();
66+
}
67+
}
68+
69+
/**
70+
* Updates the canary status in the webview
71+
*/
72+
private async updateCanaryStatus(): Promise<void> {
73+
if (!this.isShowingPanel) {
74+
return;
75+
}
76+
77+
// Import isCanary dynamically to ensure we get the latest value
78+
const { isCanary } = await import("../config");
79+
80+
await this.postMessage({
81+
t: "setCanaryStatus",
82+
isCanary: isCanary(),
83+
});
4984
}
5085

5186
public async openView() {
@@ -110,6 +145,7 @@ export class VariantAnalysisView
110145
}
111146

112147
protected onPanelDispose(): void {
148+
// All listeners registered with this.push will be cleaned up automatically
113149
this.manager.unregisterView(this);
114150
}
115151

@@ -211,6 +247,10 @@ export class VariantAnalysisView
211247
isCanary: isCanary(),
212248
});
213249

250+
// Send the current canary status immediately so it's handled separately from
251+
// variant analysis data
252+
await this.updateCanaryStatus();
253+
214254
await this.postMessage({
215255
t: "setFilterSortState",
216256
filterSortState,

extensions/ql-vscode/src/view/variant-analysis/VariantAnalysis.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export function VariantAnalysis({
9191
vscode.setState({
9292
variantAnalysisId: msg.variantAnalysis.id,
9393
});
94+
} else if (msg.t === "setCanaryStatus") {
95+
// Update the isCanary state when the setting changes
96+
setIsCanary(msg.isCanary);
9497
} else if (msg.t === "setFilterSortState") {
9598
setFilterSortState(msg.filterSortState);
9699
} else if (msg.t === "setRepoResults") {

0 commit comments

Comments
 (0)