Skip to content

Commit 3b1ff0f

Browse files
committed
Add a codeql status bar item
Includes the current cli version as well as the canary status (codeQL.canary) in the settings.
1 parent 5079abd commit 3b1ff0f

5 files changed

Lines changed: 68 additions & 5 deletions

File tree

extensions/ql-vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [UNRELEASED]
44

5+
- Add a status bar item for the CodeQL CLI to show the current version. [#741](https://github.com/github/vscode-codeql/pull/741)
56
- Fix version constraint for flagging CLI support of non-destructive updates [#744](https://github.com/github/vscode-codeql/pull/744)
67

78
## 1.4.1 - 29 January 2021
27.4 KB
Loading

extensions/ql-vscode/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@
179179
"type": "boolean",
180180
"default": false,
181181
"scope": "application",
182-
"markdownDescription": "Specifies whether to send CodeQL usage telemetry. This setting AND the global `#telemetry.enableTelemetry#` setting must be checked for telemetry to be sent to GitHub. For more information, see [TELEMETRY.md](https://github.com/github/vscode-codeql/blob/main/extensions/ql-vscode/TELEMETRY.md)",
183-
"description": "Specifies whether to send CodeQL usage telemetry. This setting AND the global `#telemetry.enableTelemetry#` setting must be checked for telemetry to be sent to GitHub."
182+
"markdownDescription": "Specifies whether to send CodeQL usage telemetry. This setting AND the global `#telemetry.enableTelemetry#` setting must be checked for telemetry to be sent to GitHub. For more information, see [TELEMETRY.md](https://github.com/github/vscode-codeql/blob/main/extensions/ql-vscode/TELEMETRY.md)"
184183
},
185184
"codeQL.telemetry.logTelemetry": {
186185
"type": "boolean",
@@ -207,6 +206,10 @@
207206
"command": "codeQL.quickQuery",
208207
"title": "CodeQL: Quick Query"
209208
},
209+
{
210+
"command": "codeQL.openDocumentation",
211+
"title": "CodeQL: Open Documentation"
212+
},
210213
{
211214
"command": "codeQLDatabases.chooseDatabaseFolder",
212215
"title": "Choose Database from Folder",

extensions/ql-vscode/src/extension.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import {
6767
withProgress,
6868
ProgressUpdate
6969
} from './commandRunner';
70+
import { CodeQlStatusBarHandler } from './status-bar';
7071

7172
/**
7273
* extension.ts
@@ -290,14 +291,22 @@ export async function activate(ctx: ExtensionContext): Promise<CodeQLExtensionIn
290291
return result;
291292
}
292293

293-
async function installOrUpdateThenTryActivate(config: DistributionUpdateConfig): Promise<CodeQLExtensionInterface | {}> {
294+
async function installOrUpdateThenTryActivate(
295+
config: DistributionUpdateConfig
296+
): Promise<CodeQLExtensionInterface | {}> {
297+
294298
await installOrUpdateDistribution(config);
295299

296300
// Display the warnings even if the extension has already activated.
297301
const distributionResult = await getDistributionDisplayingDistributionWarnings();
298302
let extensionInterface: CodeQLExtensionInterface | {} = {};
299303
if (!beganMainExtensionActivation && distributionResult.kind !== FindDistributionResultKind.NoDistribution) {
300-
extensionInterface = await activateWithInstalledDistribution(ctx, distributionManager);
304+
extensionInterface = await activateWithInstalledDistribution(
305+
ctx,
306+
distributionManager,
307+
distributionConfigListener
308+
);
309+
301310
} else if (distributionResult.kind === FindDistributionResultKind.NoDistribution) {
302311
registerErrorStubs([checkForUpdatesCommand], command => async () => {
303312
const installActionName = 'Install CodeQL CLI';
@@ -339,7 +348,8 @@ export async function activate(ctx: ExtensionContext): Promise<CodeQLExtensionIn
339348

340349
async function activateWithInstalledDistribution(
341350
ctx: ExtensionContext,
342-
distributionManager: DistributionManager
351+
distributionManager: DistributionManager,
352+
distributionConfigListener: DistributionConfigListener
343353
): Promise<CodeQLExtensionInterface> {
344354
beganMainExtensionActivation = true;
345355
// Remove any error stubs command handlers left over from first part
@@ -360,6 +370,9 @@ async function activateWithInstalledDistribution(
360370
);
361371
ctx.subscriptions.push(cliServer);
362372

373+
const statusBar = new CodeQlStatusBarHandler(cliServer, distributionConfigListener);
374+
ctx.subscriptions.push(statusBar);
375+
363376
logger.log('Initializing query server client.');
364377
const qs = new qsClient.QueryServerClient(
365378
qlConfigurationListener,
@@ -659,6 +672,10 @@ async function activateWithInstalledDistribution(
659672
})
660673
);
661674

675+
ctx.subscriptions.push(
676+
commandRunner('codeQL.openDocumentation', async () =>
677+
env.openExternal(Uri.parse('https://codeql.github.com/docs/'))));
678+
662679
logger.log('Starting language server.');
663680
ctx.subscriptions.push(client.start());
664681

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { ConfigurationChangeEvent, StatusBarAlignment, StatusBarItem, window, workspace } from 'vscode';
2+
import { CodeQLCliServer } from './cli';
3+
import { CANARY_FEATURES, DistributionConfigListener } from './config';
4+
import { DisposableObject } from './vscode-utils/disposable-object';
5+
6+
/**
7+
* Creates and manages a status bar item for codeql. THis item contains
8+
* the current codeQL cli version as well as a notification if you are
9+
* in canary mode
10+
*
11+
*/
12+
export class CodeQlStatusBarHandler extends DisposableObject {
13+
14+
private readonly item: StatusBarItem;
15+
16+
constructor(private cli: CodeQLCliServer, distributionConfigListener: DistributionConfigListener) {
17+
super();
18+
this.item = window.createStatusBarItem(StatusBarAlignment.Right);
19+
this.push(this.item);
20+
this.push(workspace.onDidChangeConfiguration(this.handleDidChangeConfiguration, this));
21+
this.push(distributionConfigListener.onDidChangeConfiguration(() => this.updateStatusItem()));
22+
this.item.command = 'codeQL.openDocumentation';
23+
this.updateStatusItem();
24+
}
25+
26+
private handleDidChangeConfiguration(e: ConfigurationChangeEvent) {
27+
if (e.affectsConfiguration(CANARY_FEATURES.qualifiedName)) {
28+
this.updateStatusItem();
29+
}
30+
}
31+
32+
private async updateStatusItem() {
33+
const canary = CANARY_FEATURES.getValue() ? ' (Canary)' : '';
34+
// since getting the verison may take a few seconds, initialize with some
35+
// meaningful text.
36+
this.item.text = `CodeQL${canary}`;
37+
38+
const version = await this.cli.getVersion();
39+
this.item.text = `CodeQL CLI v${version}${canary}`;
40+
this.item.show();
41+
}
42+
}

0 commit comments

Comments
 (0)