Skip to content

Add "View Autofixes" feature for variant analysis results #4065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 49 commits into from
Jul 8, 2025
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
8dfcf8b
Add 'View Autofixes' button to variant analysis view
Jun 27, 2025
1103437
Add 'View Autofixes' query history command for variant analysis items
Jun 27, 2025
5f5a20f
Add 'view-autofixes.ts' file for main implementation
Jun 27, 2025
fb39455
Check for local autofix
Jun 27, 2025
27bdc31
Override query help
Jun 27, 2025
9a8bd79
Get full names (owner/repo) of the selected repositories
Jun 27, 2025
66d9526
Get storage paths for autofix output
Jun 27, 2025
9c4d7a7
Add function to process the selected repositories
Jun 27, 2025
2afd2ee
Get SARIF for variant analysis repo
Jun 27, 2025
2bcf42e
Read 'repo_task.json' file
Jun 27, 2025
b0b8b62
Download source root
Jun 28, 2025
05c398f
Add function for running autofix on a given repo
Jun 28, 2025
4d5437f
Get storage paths for repository-specific autofix output
Jun 28, 2025
5dfaf3f
Set up to run autofix on repo results
Jun 28, 2025
03585af
Add function for setting variable autofix args
Jun 28, 2025
19400a9
Add function for executing autofix
Jun 28, 2025
3c7d9ca
Add function for running autofix on a given SARIF
Jun 28, 2025
74e8277
Run autofix for case when the repo result count does not exceed the f…
Jun 28, 2025
e7076f9
Add function that appends a suffix to a given file path
Jun 28, 2025
e04eb62
Run autofix for case when the repo result count exceeds the fix limit
Jun 29, 2025
2c12d71
Add markdown formatting to autofix output
Jun 29, 2025
6b47932
Combine and output final autofix results
Jun 29, 2025
3ff5d64
Add canary
Jun 29, 2025
4e089e7
Remove config listener for canary setting
Jul 2, 2025
04a858a
canary: use separate message for the user settings for the variant an…
Jul 2, 2025
7d3e403
Remove progress updates that don't display
Jul 2, 2025
161c5de
Fix missing await
Jul 2, 2025
e23699f
Use parse.dir instead of dirname
Jul 2, 2025
22d6429
Remove createVarAutofixArgs function
Jul 2, 2025
3030f6c
Update 'autofix not found' error message
jcogs33 Jul 2, 2025
ab5ef91
Fix prettier formatting
Jul 3, 2025
1d203a4
Use VariantAnalysisManager and VariantAnalysisResultsManager for stor…
Jul 3, 2025
561cbc4
Add config settings for 'codeQL.autofix.path' and 'codeQL.autofix.model'
Jul 3, 2025
bbc7413
Remove args check in 'execAutofix'
Jul 3, 2025
d887ca5
Use 'getErrorMessage' and remove uses of 'console.error'
Jul 3, 2025
41a3612
Switch fs/promises imports to fs-extra
Jul 4, 2025
b7f84fc
Replace three backticks in file content
Jul 4, 2025
492b805
Use 'extLogger' instead of 'NotificationLogger'
Jul 4, 2025
21a466a
Update doc
Jul 4, 2025
561cd6c
downloadPublicCommitSource: use 'fetch' API and 'tmp-promise'
Jul 6, 2025
8ed9e6a
Log autofix stdout/stderr to the extension logs
Jul 6, 2025
cb4bfbc
Fix path to extracted source root directory
Jul 7, 2025
6333c9e
Remove checkoutDir if source root download fails
Jul 7, 2025
0e6aa81
Remove unneeded 'progressCallback' undefined conditional
Jul 7, 2025
2c04019
Simplify source root downloading with 'pipe'
Jul 7, 2025
7f9d7ae
Call 'cliServer.resolveMetadata' instead of 'tryGetQueryMetadata'
Jul 7, 2025
4e76a0d
showWarningMessage when number of repos is limited
Jul 7, 2025
bf6d8e7
Add names of config settings to error messages
Jul 7, 2025
1f5cc90
Fix timeout error caused by oversimplification of 'onData'
Jul 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions extensions/ql-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,10 @@
"command": "codeQLQueryHistory.copyRepoList",
"title": "Copy Repository List"
},
{
"command": "codeQLQueryHistory.viewAutofixes",
"title": "View Autofixes"
},
{
"command": "codeQLQueryResults.down",
"title": "CodeQL: Navigate Down in Local Result Viewer"
Expand Down Expand Up @@ -1296,6 +1300,11 @@
"group": "1_queryHistory@1",
"when": "viewItem == remoteResultsItem"
},
{
"command": "codeQLQueryHistory.viewAutofixes",
"group": "1_queryHistory@2",
"when": "viewItem == remoteResultsItem && config.codeQL.canary"
},
{
"command": "codeQLQueries.runLocalQueryFromQueriesPanel",
"group": "inline",
Expand Down Expand Up @@ -1706,6 +1715,10 @@
"command": "codeQLQueryHistory.copyRepoList",
"when": "false"
},
{
"command": "codeQLQueryHistory.viewAutofixes",
"when": "false"
},
{
"command": "codeQLQueryHistory.showQueryText",
"when": "false"
Expand Down
1 change: 1 addition & 0 deletions extensions/ql-vscode/src/common/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export type QueryHistoryCommands = {
"codeQLQueryHistory.itemClicked": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.openOnGithub": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.copyRepoList": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
"codeQLQueryHistory.viewAutofixes": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;

// Commands in the command palette
"codeQL.exportSelectedVariantAnalysisResults": () => Promise<void>;
Expand Down
12 changes: 11 additions & 1 deletion extensions/ql-vscode/src/common/interface-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,13 @@ interface SetStateMsg {
export interface UserSettings {
/** Whether to display links to the dataflow models that generated particular nodes in a flow path. */
shouldShowProvenance: boolean;
/** Whether to display the "View Autofixes" button. */
shouldShowViewAutofixesBtn: boolean;
}

export const DEFAULT_USER_SETTINGS: UserSettings = {
shouldShowProvenance: false,
shouldShowViewAutofixesBtn: false,
};

/** Message indicating that the user's configuration settings have changed. */
Expand Down Expand Up @@ -527,6 +530,11 @@ interface OpenQueryTextMessage {
t: "openQueryText";
}

interface ViewAutofixesMessage {
t: "viewAutofixes";
filterSort?: RepositoriesFilterSortStateWithIds;
}

interface CopyRepositoryListMessage {
t: "copyRepositoryList";
filterSort?: RepositoriesFilterSortStateWithIds;
Expand Down Expand Up @@ -554,13 +562,15 @@ export type ToVariantAnalysisMessage =
| SetVariantAnalysisMessage
| SetFilterSortStateMessage
| SetRepoResultsMessage
| SetRepoStatesMessage;
| SetRepoStatesMessage
| SetUserSettingsMsg;

export type FromVariantAnalysisMessage =
| CommonFromViewMessages
| RequestRepositoryResultsMessage
| OpenQueryFileMessage
| OpenQueryTextMessage
| ViewAutofixesMessage
| CopyRepositoryListMessage
| ExportResultsMessage
| OpenLogsMessage
Expand Down
2 changes: 2 additions & 0 deletions extensions/ql-vscode/src/compare/compare-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export class CompareView extends AbstractWebview<
t: "setUserSettings",
userSettings: {
shouldShowProvenance: isCanary(),
// "View Autofixes" button is not supported in compare view
shouldShowViewAutofixesBtn: false,
},
});

Expand Down
2 changes: 2 additions & 0 deletions extensions/ql-vscode/src/local-queries/results-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ export class ResultsView extends AbstractWebview<
userSettings: {
// Only show provenance info in canary mode for now.
shouldShowProvenance: isCanary(),
// "View Autofixes" button is not supported in results view
shouldShowViewAutofixesBtn: false,
},
});

Expand Down
13 changes: 13 additions & 0 deletions extensions/ql-vscode/src/query-history/query-history-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ export class QueryHistoryManager extends DisposableObject {
this.handleOpenOnGithub.bind(this),
"query",
),
"codeQLQueryHistory.viewAutofixes": createSingleSelectionCommand(
this.app.logger,
this.handleViewAutofixes.bind(this),
"query",
),
"codeQLQueryHistory.copyRepoList": createSingleSelectionCommand(
this.app.logger,
this.handleCopyRepoList.bind(this),
Expand Down Expand Up @@ -1052,6 +1057,14 @@ export class QueryHistoryManager extends DisposableObject {
);
}

async handleViewAutofixes(item: QueryHistoryInfo) {
if (item.t !== "variant-analysis") {
return;
}

await this.variantAnalysisManager.viewAutofixes(item.variantAnalysis.id);
}

async handleCopyRepoList(item: QueryHistoryInfo) {
if (item.t !== "variant-analysis") {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,5 +433,6 @@ WithCodeFlows.args = {
),
userSettings: {
shouldShowProvenance: true,
shouldShowViewAutofixesBtn: false, // Not supported in AlertTable
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import type {
VariantAnalysisCommands,
} from "../common/commands";
import { exportVariantAnalysisResults } from "./export-results";
import { viewAutofixesForVariantAnalysisResults } from "./view-autofixes";
import {
readRepoStates,
REPO_STATES_FILENAME,
Expand Down Expand Up @@ -967,6 +968,22 @@ export class VariantAnalysisManager
);
}

public async viewAutofixes(
variantAnalysisId: number,
filterSort: RepositoriesFilterSortStateWithIds = defaultFilterSortState,
) {
await viewAutofixesForVariantAnalysisResults(
variantAnalysisId,
filterSort,
this.variantAnalyses,
this.app.credentials,
this.app.logger,
this.storagePath,
this.app,
this.cliServer,
);
}

public async copyRepoListToClipboard(
variantAnalysisId: number,
filterSort: RepositoriesFilterSortStateWithIds = defaultFilterSortState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ export interface VariantAnalysisViewManager<
variantAnalysisId: number,
filterSort?: RepositoriesFilterSortStateWithIds,
): Promise<void>;
viewAutofixes(
variantAnalysisId: number,
filterSort?: RepositoriesFilterSortStateWithIds,
): Promise<void>;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ViewColumn } from "vscode";
import type { ConfigurationChangeEvent } from "vscode";
import { ViewColumn, workspace } from "vscode";
import type { WebviewPanelConfig } from "../common/vscode/abstract-webview";
import { AbstractWebview } from "../common/vscode/abstract-webview";
import {
Expand Down Expand Up @@ -27,6 +28,7 @@ import type { App } from "../common/app";
import {
getVariantAnalysisDefaultResultsFilter,
getVariantAnalysisDefaultResultsSort,
isCanary,
} from "../config";

export class VariantAnalysisView
Expand All @@ -46,13 +48,48 @@ export class VariantAnalysisView
manager.registerView(this);

this.dataFlowPathsView = new DataFlowPathsView(app);

// Set up configuration change listener
this.push(
workspace.onDidChangeConfiguration(
this.onConfigurationChanged.bind(this),
),
);
}

/**
* Handler for configuration changes
*/
private onConfigurationChanged(e: ConfigurationChangeEvent): void {
// Check if the canary setting has changed
if (e.affectsConfiguration("codeQL.canary")) {
void this.updateUserSettings();
}
}

private async updateUserSettings(): Promise<void> {
if (!this.isShowingPanel) {
return;
}

await this.postMessage({
t: "setUserSettings",
userSettings: {
// Provenance is not supported in variant analysis view
shouldShowProvenance: false,
// Only show "View Autofixes" button in canary mode.
shouldShowViewAutofixesBtn: isCanary(),
},
});
}

public async openView() {
const panel = await this.getPanel();
panel.reveal(undefined, true);

await this.waitForPanelLoaded();

await this.updateUserSettings();
}

public async updateView(variantAnalysis: VariantAnalysis): Promise<void> {
Expand Down Expand Up @@ -135,6 +172,12 @@ export class VariantAnalysisView
case "openQueryText":
await this.manager.openQueryText(this.variantAnalysisId);
break;
case "viewAutofixes":
await this.manager.viewAutofixes(
this.variantAnalysisId,
msg.filterSort,
);
break;
case "copyRepositoryList":
await this.manager.copyRepoListToClipboard(
this.variantAnalysisId,
Expand Down
Loading
Loading