Skip to content

Commit 403bd13

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Add canary
1 parent 6b47932 commit 403bd13

File tree

12 files changed

+103
-19
lines changed

12 files changed

+103
-19
lines changed

extensions/ql-vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@
13031303
{
13041304
"command": "codeQLQueryHistory.viewAutofixes",
13051305
"group": "1_queryHistory@2",
1306-
"when": "viewItem == remoteResultsItem"
1306+
"when": "viewItem == remoteResultsItem && config.codeQL.canary"
13071307
},
13081308
{
13091309
"command": "codeQLQueries.runLocalQueryFromQueriesPanel",

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,13 @@ interface SetStateMsg {
151151
export interface UserSettings {
152152
/** Whether to display links to the dataflow models that generated particular nodes in a flow path. */
153153
shouldShowProvenance: boolean;
154+
/** Whether to display the "View Autofixes" button. */
155+
shouldShowViewAutofixesBtn: boolean;
154156
}
155157

156158
export const DEFAULT_USER_SETTINGS: UserSettings = {
157159
shouldShowProvenance: false,
160+
shouldShowViewAutofixesBtn: false,
158161
};
159162

160163
/** Message indicating that the user's configuration settings have changed. */
@@ -559,7 +562,8 @@ export type ToVariantAnalysisMessage =
559562
| SetVariantAnalysisMessage
560563
| SetFilterSortStateMessage
561564
| SetRepoResultsMessage
562-
| SetRepoStatesMessage;
565+
| SetRepoStatesMessage
566+
| SetUserSettingsMsg;
563567

564568
export type FromVariantAnalysisMessage =
565569
| CommonFromViewMessages

extensions/ql-vscode/src/compare/compare-view.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ export class CompareView extends AbstractWebview<
119119
t: "setUserSettings",
120120
userSettings: {
121121
shouldShowProvenance: isCanary(),
122+
// "View Autofixes" button is not supported in results view
123+
shouldShowViewAutofixesBtn: false,
122124
},
123125
});
124126

extensions/ql-vscode/src/local-queries/results-view.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ export class ResultsView extends AbstractWebview<
550550
userSettings: {
551551
// Only show provenance info in canary mode for now.
552552
shouldShowProvenance: isCanary(),
553+
// "View Autofixes" button is not supported in results view
554+
shouldShowViewAutofixesBtn: false,
553555
},
554556
});
555557

extensions/ql-vscode/src/stories/results/AlertTable.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,5 +433,6 @@ WithCodeFlows.args = {
433433
),
434434
userSettings: {
435435
shouldShowProvenance: true,
436+
shouldShowViewAutofixesBtn: false, // Not supported in AlertTable
436437
},
437438
};

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

Lines changed: 42 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,45 @@ 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: "setUserSettings",
82+
userSettings: {
83+
// Provenance is not supported in variant analysis view
84+
shouldShowProvenance: false,
85+
// Only show "View Autofixes" button in canary mode.
86+
shouldShowViewAutofixesBtn: isCanary(),
87+
},
88+
});
4989
}
5090

5191
public async openView() {
@@ -110,6 +150,7 @@ export class VariantAnalysisView
110150
}
111151

112152
protected onPanelDispose(): void {
153+
// All listeners registered with this.push will be cleaned up automatically
113154
this.manager.unregisterView(this);
114155
}
115156

extensions/ql-vscode/src/view/results/__tests__/AlertTablePathRow.spec.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ describe(AlertTablePathRow.name, () => {
2222
currentPathExpanded={true}
2323
databaseUri={"dbUri"}
2424
sourceLocationPrefix="src"
25-
userSettings={{ shouldShowProvenance: false }}
25+
userSettings={{
26+
shouldShowProvenance: false,
27+
shouldShowViewAutofixesBtn: false,
28+
}}
2629
updateSelectionCallback={jest.fn()}
2730
toggleExpanded={jest.fn()}
2831
{...props}

extensions/ql-vscode/src/view/results/__tests__/AlertTableResultRow.spec.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ describe(AlertTableResultRow.name, () => {
1717
selectedItemRef={mockRef}
1818
databaseUri={"dbUri"}
1919
sourceLocationPrefix="src"
20-
userSettings={{ shouldShowProvenance: false }}
20+
userSettings={{
21+
shouldShowProvenance: false,
22+
shouldShowViewAutofixesBtn: false,
23+
}}
2124
updateSelectionCallback={jest.fn()}
2225
toggleExpanded={jest.fn()}
2326
{...props}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ import { VariantAnalysisStatus } from "../../variant-analysis/shared/variant-ana
99
import { VariantAnalysisHeader } from "./VariantAnalysisHeader";
1010
import { VariantAnalysisOutcomePanels } from "./VariantAnalysisOutcomePanels";
1111
import { VariantAnalysisLoading } from "./VariantAnalysisLoading";
12-
import type { ToVariantAnalysisMessage } from "../../common/interface-types";
12+
import type {
13+
ToVariantAnalysisMessage,
14+
UserSettings,
15+
} from "../../common/interface-types";
1316
import { vscode } from "../vscode-api";
1417
import { defaultFilterSortState } from "../../variant-analysis/shared/variant-analysis-filter-sort";
1518
import { sendTelemetry, useTelemetryOnChange } from "../common/telemetry";
1619
import { useMessageFromExtension } from "../common/useMessageFromExtension";
20+
import { DEFAULT_USER_SETTINGS } from "../../common/interface-types";
1721

1822
export type VariantAnalysisProps = {
1923
variantAnalysis?: VariantAnalysisDomainModel;
@@ -78,12 +82,19 @@ export function VariantAnalysis({
7882
debounceTimeoutMillis: 1000,
7983
});
8084

85+
// Track user settings
86+
const [userSettings, setUserSettings] = useState<UserSettings>(
87+
DEFAULT_USER_SETTINGS,
88+
);
89+
8190
useMessageFromExtension<ToVariantAnalysisMessage>((msg) => {
8291
if (msg.t === "setVariantAnalysis") {
8392
setVariantAnalysis(msg.variantAnalysis);
8493
vscode.setState({
8594
variantAnalysisId: msg.variantAnalysis.id,
8695
});
96+
} else if (msg.t === "setUserSettings") {
97+
setUserSettings(msg.userSettings);
8798
} else if (msg.t === "setFilterSortState") {
8899
setFilterSortState(msg.filterSortState);
89100
} else if (msg.t === "setRepoResults") {
@@ -161,6 +172,7 @@ export function VariantAnalysis({
161172
onStopQueryClick={stopQuery}
162173
onViewAutofixesClick={viewAutofixes}
163174
onCopyRepositoryListClick={copyRepositoryList}
175+
userSettings={userSettings}
164176
onExportResultsClick={exportResults}
165177
onViewLogsClick={onViewLogsClick}
166178
/>

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { styled } from "styled-components";
22
import { VariantAnalysisStatus } from "../../variant-analysis/shared/variant-analysis";
33
import { VscodeButton } from "@vscode-elements/react-elements";
4+
import type { UserSettings } from "../../common/interface-types";
45

56
export type VariantAnalysisActionsProps = {
67
variantAnalysisStatus: VariantAnalysisStatus;
@@ -18,6 +19,8 @@ export type VariantAnalysisActionsProps = {
1819

1920
hasSelectedRepositories?: boolean;
2021
hasFilteredRepositories?: boolean;
22+
23+
userSettings: UserSettings;
2124
};
2225

2326
const Container = styled.div`
@@ -65,24 +68,28 @@ export const VariantAnalysisActions = ({
6568
exportResultsDisabled,
6669
hasSelectedRepositories,
6770
hasFilteredRepositories,
71+
userSettings,
6872
}: VariantAnalysisActionsProps) => {
6973
return (
7074
<Container>
7175
{showResultActions && (
7276
<>
73-
<Button
74-
secondary
75-
onClick={onViewAutofixesClick}
76-
disabled={viewAutofixesDisabled}
77-
>
78-
{chooseText({
79-
hasSelectedRepositories,
80-
hasFilteredRepositories,
81-
normalText: "View Autofixes",
82-
selectedText: "View Autofixes for selected results",
83-
filteredText: "View Autofixes for filtered results",
84-
})}
85-
</Button>
77+
{/* Only show the View Autofixes button in canary builds */}
78+
{userSettings?.shouldShowViewAutofixesBtn && (
79+
<Button
80+
secondary
81+
onClick={onViewAutofixesClick}
82+
disabled={viewAutofixesDisabled}
83+
>
84+
{chooseText({
85+
hasSelectedRepositories,
86+
hasFilteredRepositories,
87+
normalText: "View Autofixes",
88+
selectedText: "View Autofixes for selected results",
89+
filteredText: "View Autofixes for filtered results",
90+
})}
91+
</Button>
92+
)}
8693
<Button
8794
secondary
8895
onClick={onCopyRepositoryListClick}

0 commit comments

Comments
 (0)