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

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 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
c5f0e5e
Add canary
Jun 29, 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,6 +48,39 @@ 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() {
Expand Down Expand Up @@ -135,6 +170,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 Expand Up @@ -215,6 +256,8 @@ export class VariantAnalysisView
t: "setRepoStates",
repoStates,
});

await this.updateUserSettings();
}

private getTitle(variantAnalysis: VariantAnalysis | undefined): string {
Expand Down
Loading
Loading