Skip to content

Commit 4479639

Browse files
Copilotfelickz
andcommitted
Implement CodeQL discovery and auto-install feature
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
1 parent 73c7c68 commit 4479639

File tree

3 files changed

+434
-17
lines changed

3 files changed

+434
-17
lines changed

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@
7474
"title": "CodeQL: Show CLI Information",
7575
"category": "CodeQL Scanner"
7676
},
77+
{
78+
"command": "codeql-scanner.installCodeQL",
79+
"title": "CodeQL: Install/Update CLI",
80+
"category": "CodeQL Scanner"
81+
},
7782
{
7883
"command": "codeql-scanner.copyFlowPath",
7984
"title": "CodeQL: Copy Flow Path",
@@ -158,6 +163,12 @@
158163
"description": "Automatically detect and use CodeQL CLI from GitHub.vscode-codeql extension if available",
159164
"scope": "application"
160165
},
166+
"codeql-scanner.autoInstallCodeQL": {
167+
"type": "boolean",
168+
"default": true,
169+
"description": "Automatically download and install CodeQL CLI from GitHub if not found",
170+
"scope": "application"
171+
},
161172
"codeql-scanner.useLocalScan": {
162173
"type": "boolean",
163174
"default": true,

src/extension.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,43 @@ export async function activate(context: vscode.ExtensionContext) {
6969
resultsProvider.clearResults();
7070
vscode.window.showInformationMessage('CodeQL diagnostics cleared.');
7171
}),
72+
vscode.commands.registerCommand('codeql-scanner.showCodeQLInfo', async () => {
73+
try {
74+
const version = await codeqlService.getVersion();
75+
const config = vscode.workspace.getConfiguration("codeql-scanner");
76+
const codeqlPath = config.get<string>("codeqlPath", "codeql");
77+
78+
vscode.window.showInformationMessage(
79+
`CodeQL CLI Info:\nVersion: ${version}\nPath: ${codeqlPath}`,
80+
{ modal: true }
81+
);
82+
} catch (error) {
83+
const errorMessage = error instanceof Error ? error.message : String(error);
84+
vscode.window.showErrorMessage(`CodeQL CLI Info: ${errorMessage}`);
85+
}
86+
}),
87+
vscode.commands.registerCommand('codeql-scanner.installCodeQL', async () => {
88+
try {
89+
await vscode.window.withProgress({
90+
location: vscode.ProgressLocation.Notification,
91+
title: "Installing CodeQL CLI",
92+
cancellable: true
93+
}, async (progress, token) => {
94+
// Force installation
95+
const releaseInfo = await codeqlService.getLatestCodeQLRelease();
96+
const installedPath = await codeqlService.downloadAndInstallCodeQL(releaseInfo, progress, token);
97+
98+
if (installedPath) {
99+
const config = vscode.workspace.getConfiguration("codeql-scanner");
100+
await config.update("codeqlPath", installedPath, vscode.ConfigurationTarget.Global);
101+
vscode.window.showInformationMessage(`CodeQL CLI installed successfully at: ${installedPath}`);
102+
}
103+
});
104+
} catch (error) {
105+
const errorMessage = error instanceof Error ? error.message : String(error);
106+
vscode.window.showErrorMessage(`Failed to install CodeQL CLI: ${errorMessage}`);
107+
}
108+
}),
72109
vscode.commands.registerCommand('codeql-scanner.copyFlowPath', async (item) => {
73110
if (item && item.result && item.result.flowSteps) {
74111
const flowPath = item.result.flowSteps.map((step: any, index: number) => {

0 commit comments

Comments
 (0)