Skip to content

Commit 5328aa2

Browse files
authored
Merge pull request #4065 from jcogs33/jcogs33/view-autofixes
Add "View Autofixes" feature for variant analysis results
2 parents 383405c + 1f5cc90 commit 5328aa2

16 files changed

+1097
-5
lines changed

extensions/ql-vscode/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,10 @@
958958
"command": "codeQLQueryHistory.copyRepoList",
959959
"title": "Copy Repository List"
960960
},
961+
{
962+
"command": "codeQLQueryHistory.viewAutofixes",
963+
"title": "View Autofixes"
964+
},
961965
{
962966
"command": "codeQLQueryResults.down",
963967
"title": "CodeQL: Navigate Down in Local Result Viewer"
@@ -1296,6 +1300,11 @@
12961300
"group": "1_queryHistory@1",
12971301
"when": "viewItem == remoteResultsItem"
12981302
},
1303+
{
1304+
"command": "codeQLQueryHistory.viewAutofixes",
1305+
"group": "1_queryHistory@2",
1306+
"when": "viewItem == remoteResultsItem && config.codeQL.canary"
1307+
},
12991308
{
13001309
"command": "codeQLQueries.runLocalQueryFromQueriesPanel",
13011310
"group": "inline",
@@ -1706,6 +1715,10 @@
17061715
"command": "codeQLQueryHistory.copyRepoList",
17071716
"when": "false"
17081717
},
1718+
{
1719+
"command": "codeQLQueryHistory.viewAutofixes",
1720+
"when": "false"
1721+
},
17091722
{
17101723
"command": "codeQLQueryHistory.showQueryText",
17111724
"when": "false"

extensions/ql-vscode/src/common/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ export type QueryHistoryCommands = {
197197
"codeQLQueryHistory.itemClicked": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
198198
"codeQLQueryHistory.openOnGithub": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
199199
"codeQLQueryHistory.copyRepoList": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
200+
"codeQLQueryHistory.viewAutofixes": TreeViewContextMultiSelectionCommandFunction<QueryHistoryInfo>;
200201

201202
// Commands in the command palette
202203
"codeQL.exportSelectedVariantAnalysisResults": () => Promise<void>;

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,25 @@ interface SetUserSettingsMsg {
163163
userSettings: UserSettings;
164164
}
165165

166+
export interface VariantAnalysisUserSettings {
167+
/** Whether to display the "View Autofixes" button. */
168+
shouldShowViewAutofixesButton: boolean;
169+
}
170+
171+
export const DEFAULT_VARIANT_ANALYSIS_USER_SETTINGS: VariantAnalysisUserSettings =
172+
{
173+
shouldShowViewAutofixesButton: false,
174+
};
175+
176+
/**
177+
* Message indicating that the user's variant analysis configuration
178+
* settings have changed.
179+
*/
180+
interface SetVariantAnalysisUserSettingsMsg {
181+
t: "setVariantAnalysisUserSettings";
182+
variantAnalysisUserSettings: VariantAnalysisUserSettings;
183+
}
184+
166185
/**
167186
* Message indicating that the results view should display interpreted
168187
* results.
@@ -527,6 +546,11 @@ interface OpenQueryTextMessage {
527546
t: "openQueryText";
528547
}
529548

549+
interface ViewAutofixesMessage {
550+
t: "viewAutofixes";
551+
filterSort?: RepositoriesFilterSortStateWithIds;
552+
}
553+
530554
interface CopyRepositoryListMessage {
531555
t: "copyRepositoryList";
532556
filterSort?: RepositoriesFilterSortStateWithIds;
@@ -554,13 +578,15 @@ export type ToVariantAnalysisMessage =
554578
| SetVariantAnalysisMessage
555579
| SetFilterSortStateMessage
556580
| SetRepoResultsMessage
557-
| SetRepoStatesMessage;
581+
| SetRepoStatesMessage
582+
| SetVariantAnalysisUserSettingsMsg;
558583

559584
export type FromVariantAnalysisMessage =
560585
| CommonFromViewMessages
561586
| RequestRepositoryResultsMessage
562587
| OpenQueryFileMessage
563588
| OpenQueryTextMessage
589+
| ViewAutofixesMessage
564590
| CopyRepositoryListMessage
565591
| ExportResultsMessage
566592
| OpenLogsMessage

extensions/ql-vscode/src/config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,3 +954,17 @@ export class GitHubDatabaseConfigListener
954954
await GITHUB_DATABASE_UPDATE.updateValue(value, target);
955955
}
956956
}
957+
958+
const AUTOFIX_SETTING = new Setting("autofix", ROOT_SETTING);
959+
960+
export const AUTOFIX_PATH = new Setting("path", AUTOFIX_SETTING);
961+
962+
export function getAutofixPath(): string | undefined {
963+
return AUTOFIX_PATH.getValue<string>() || undefined;
964+
}
965+
966+
export const AUTOFIX_MODEL = new Setting("model", AUTOFIX_SETTING);
967+
968+
export function getAutofixModel(): string | undefined {
969+
return AUTOFIX_MODEL.getValue<string>() || undefined;
970+
}

extensions/ql-vscode/src/query-history/query-history-manager.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ export class QueryHistoryManager extends DisposableObject {
338338
this.handleOpenOnGithub.bind(this),
339339
"query",
340340
),
341+
"codeQLQueryHistory.viewAutofixes": createSingleSelectionCommand(
342+
this.app.logger,
343+
this.handleViewAutofixes.bind(this),
344+
"query",
345+
),
341346
"codeQLQueryHistory.copyRepoList": createSingleSelectionCommand(
342347
this.app.logger,
343348
this.handleCopyRepoList.bind(this),
@@ -1052,6 +1057,14 @@ export class QueryHistoryManager extends DisposableObject {
10521057
);
10531058
}
10541059

1060+
async handleViewAutofixes(item: QueryHistoryInfo) {
1061+
if (item.t !== "variant-analysis") {
1062+
return;
1063+
}
1064+
1065+
await this.variantAnalysisManager.viewAutofixes(item.variantAnalysis.id);
1066+
}
1067+
10551068
async handleCopyRepoList(item: QueryHistoryInfo) {
10561069
if (item.t !== "variant-analysis") {
10571070
return;

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import type {
7373
VariantAnalysisCommands,
7474
} from "../common/commands";
7575
import { exportVariantAnalysisResults } from "./export-results";
76+
import { viewAutofixesForVariantAnalysisResults } from "./view-autofixes";
7677
import {
7778
readRepoStates,
7879
REPO_STATES_FILENAME,
@@ -967,6 +968,21 @@ export class VariantAnalysisManager
967968
);
968969
}
969970

971+
public async viewAutofixes(
972+
variantAnalysisId: number,
973+
filterSort: RepositoriesFilterSortStateWithIds = defaultFilterSortState,
974+
) {
975+
await viewAutofixesForVariantAnalysisResults(
976+
this,
977+
this.variantAnalysisResultsManager,
978+
variantAnalysisId,
979+
filterSort,
980+
this.app.credentials,
981+
this.app,
982+
this.cliServer,
983+
);
984+
}
985+
970986
public async copyRepoListToClipboard(
971987
variantAnalysisId: number,
972988
filterSort: RepositoriesFilterSortStateWithIds = defaultFilterSortState,

extensions/ql-vscode/src/variant-analysis/variant-analysis-results-manager.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export type LoadResultsOptions = {
4444

4545
export class VariantAnalysisResultsManager extends DisposableObject {
4646
private static readonly RESULTS_DIRECTORY = "results";
47+
private static readonly RESULTS_SARIF_FILENAME = "results.sarif";
4748

4849
private readonly cachedResults: Map<
4950
CacheKey,
@@ -212,7 +213,10 @@ export class VariantAnalysisResultsManager extends DisposableObject {
212213
storageDirectory,
213214
VariantAnalysisResultsManager.RESULTS_DIRECTORY,
214215
);
215-
const sarifPath = join(resultsDirectory, "results.sarif");
216+
const sarifPath = join(
217+
resultsDirectory,
218+
VariantAnalysisResultsManager.RESULTS_SARIF_FILENAME,
219+
);
216220
const bqrsPath = join(resultsDirectory, "results.bqrs");
217221

218222
let interpretedResults: AnalysisAlert[] | undefined;
@@ -294,6 +298,17 @@ export class VariantAnalysisResultsManager extends DisposableObject {
294298
return join(variantAnalysisStoragePath, fullName);
295299
}
296300

301+
public getRepoResultsSarifStoragePath(
302+
variantAnalysisStoragePath: string,
303+
fullName: string,
304+
): string {
305+
return join(
306+
this.getRepoStorageDirectory(variantAnalysisStoragePath, fullName),
307+
VariantAnalysisResultsManager.RESULTS_DIRECTORY,
308+
VariantAnalysisResultsManager.RESULTS_SARIF_FILENAME,
309+
);
310+
}
311+
297312
private createGitHubFileLinkPrefix(fullName: string, sha: string): string {
298313
return new URL(
299314
`/${fullName}/blob/${sha}`,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ export interface VariantAnalysisViewManager<
3434
variantAnalysisId: number,
3535
filterSort?: RepositoriesFilterSortStateWithIds,
3636
): Promise<void>;
37+
viewAutofixes(
38+
variantAnalysisId: number,
39+
filterSort?: RepositoriesFilterSortStateWithIds,
40+
): Promise<void>;
3741
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import type { App } from "../common/app";
2727
import {
2828
getVariantAnalysisDefaultResultsFilter,
2929
getVariantAnalysisDefaultResultsSort,
30+
isCanary,
3031
} from "../config";
3132

3233
export class VariantAnalysisView
@@ -53,6 +54,13 @@ export class VariantAnalysisView
5354
panel.reveal(undefined, true);
5455

5556
await this.waitForPanelLoaded();
57+
58+
await this.postMessage({
59+
t: "setVariantAnalysisUserSettings",
60+
variantAnalysisUserSettings: {
61+
shouldShowViewAutofixesButton: isCanary(),
62+
},
63+
});
5664
}
5765

5866
public async updateView(variantAnalysis: VariantAnalysis): Promise<void> {
@@ -135,6 +143,12 @@ export class VariantAnalysisView
135143
case "openQueryText":
136144
await this.manager.openQueryText(this.variantAnalysisId);
137145
break;
146+
case "viewAutofixes":
147+
await this.manager.viewAutofixes(
148+
this.variantAnalysisId,
149+
msg.filterSort,
150+
);
151+
break;
138152
case "copyRepositoryList":
139153
await this.manager.copyRepoListToClipboard(
140154
this.variantAnalysisId,

0 commit comments

Comments
 (0)