Skip to content

Commit 8095989

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

File tree

12 files changed

+96
-19
lines changed

12 files changed

+96
-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 compare 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: 38 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 {
@@ -27,6 +28,7 @@ import type { App } from "../common/app";
2728
import {
2829
getVariantAnalysisDefaultResultsFilter,
2930
getVariantAnalysisDefaultResultsSort,
31+
isCanary,
3032
} from "../config";
3133

3234
export class VariantAnalysisView
@@ -46,6 +48,39 @@ export class VariantAnalysisView
4648
manager.registerView(this);
4749

4850
this.dataFlowPathsView = new DataFlowPathsView(app);
51+
52+
// Set up configuration change listener
53+
this.push(
54+
workspace.onDidChangeConfiguration(
55+
this.onConfigurationChanged.bind(this),
56+
),
57+
);
58+
}
59+
60+
/**
61+
* Handler for configuration changes
62+
*/
63+
private onConfigurationChanged(e: ConfigurationChangeEvent): void {
64+
// Check if the canary setting has changed
65+
if (e.affectsConfiguration("codeQL.canary")) {
66+
void this.updateCanaryStatus();
67+
}
68+
}
69+
70+
private async updateCanaryStatus(): Promise<void> {
71+
if (!this.isShowingPanel) {
72+
return;
73+
}
74+
75+
await this.postMessage({
76+
t: "setUserSettings",
77+
userSettings: {
78+
// Provenance is not supported in variant analysis view
79+
shouldShowProvenance: false,
80+
// Only show "View Autofixes" button in canary mode.
81+
shouldShowViewAutofixesBtn: isCanary(),
82+
},
83+
});
4984
}
5085

5186
public async openView() {
@@ -221,6 +256,8 @@ export class VariantAnalysisView
221256
t: "setRepoStates",
222257
repoStates,
223258
});
259+
260+
await this.updateCanaryStatus();
224261
}
225262

226263
private getTitle(variantAnalysis: VariantAnalysis | undefined): string {

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: 11 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;
@@ -77,6 +81,9 @@ export function VariantAnalysis({
7781
useTelemetryOnChange(filterSortState, "variant-analysis-filter-sort-state", {
7882
debounceTimeoutMillis: 1000,
7983
});
84+
const [userSettings, setUserSettings] = useState<UserSettings>(
85+
DEFAULT_USER_SETTINGS,
86+
);
8087

8188
useMessageFromExtension<ToVariantAnalysisMessage>((msg) => {
8289
if (msg.t === "setVariantAnalysis") {
@@ -102,6 +109,8 @@ export function VariantAnalysis({
102109
...msg.repoStates,
103110
];
104111
});
112+
} else if (msg.t === "setUserSettings") {
113+
setUserSettings(msg.userSettings);
105114
}
106115
}, []);
107116

@@ -161,6 +170,7 @@ export function VariantAnalysis({
161170
onStopQueryClick={stopQuery}
162171
onViewAutofixesClick={viewAutofixes}
163172
onCopyRepositoryListClick={copyRepositoryList}
173+
userSettings={userSettings}
164174
onExportResultsClick={exportResults}
165175
onViewLogsClick={onViewLogsClick}
166176
/>

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

Lines changed: 19 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,27 @@ 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+
{userSettings.shouldShowViewAutofixesBtn && (
78+
<Button
79+
secondary
80+
onClick={onViewAutofixesClick}
81+
disabled={viewAutofixesDisabled}
82+
>
83+
{chooseText({
84+
hasSelectedRepositories,
85+
hasFilteredRepositories,
86+
normalText: "View Autofixes",
87+
selectedText: "View Autofixes for selected results",
88+
filteredText: "View Autofixes for filtered results",
89+
})}
90+
</Button>
91+
)}
8692
<Button
8793
secondary
8894
onClick={onCopyRepositoryListClick}

0 commit comments

Comments
 (0)