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

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
38 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
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
28 changes: 27 additions & 1 deletion extensions/ql-vscode/src/common/interface-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,25 @@ interface SetUserSettingsMsg {
userSettings: UserSettings;
}

export interface VariantAnalysisUserSettings {
/** Whether to display the "View Autofixes" button. */
shouldShowViewAutofixesButton: boolean;
}

export const DEFAULT_VARIANT_ANALYSIS_USER_SETTINGS: VariantAnalysisUserSettings =
{
shouldShowViewAutofixesButton: false,
};

/**
* Message indicating that the user's variant analysis configuration
* settings have changed.
*/
interface SetVariantAnalysisUserSettingsMsg {
t: "setVariantAnalysisUserSettings";
variantAnalysisUserSettings: VariantAnalysisUserSettings;
}

/**
* Message indicating that the results view should display interpreted
* results.
Expand Down Expand Up @@ -527,6 +546,11 @@ interface OpenQueryTextMessage {
t: "openQueryText";
}

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

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

export type FromVariantAnalysisMessage =
| CommonFromViewMessages
| RequestRepositoryResultsMessage
| OpenQueryFileMessage
| OpenQueryTextMessage
| ViewAutofixesMessage
| CopyRepositoryListMessage
| ExportResultsMessage
| OpenLogsMessage
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 @@ -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
Expand Up @@ -27,6 +27,7 @@ import type { App } from "../common/app";
import {
getVariantAnalysisDefaultResultsFilter,
getVariantAnalysisDefaultResultsSort,
isCanary,
} from "../config";

export class VariantAnalysisView
Expand All @@ -53,6 +54,13 @@ export class VariantAnalysisView
panel.reveal(undefined, true);

await this.waitForPanelLoaded();

await this.postMessage({
t: "setVariantAnalysisUserSettings",
variantAnalysisUserSettings: {
shouldShowViewAutofixesButton: isCanary(),
},
});
}

public async updateView(variantAnalysis: VariantAnalysis): Promise<void> {
Expand Down Expand Up @@ -135,6 +143,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