Skip to content

Commit 657debe

Browse files
Create branch for Code Lens feature
1 parent c590e2f commit 657debe

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

extensions/ql-vscode/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@
128128
"type": "object",
129129
"title": "CodeQL",
130130
"properties": {
131+
"codelens-sample.enableCodeLens": {
132+
"type": "boolean",
133+
"default": true
134+
},
131135
"codeQL.cli.executablePath": {
132136
"scope": "window",
133137
"type": "string",
@@ -267,6 +271,16 @@
267271
}
268272
},
269273
"commands": [
274+
{
275+
"title": "Enable CodeLens",
276+
"command": "codelens-sample.enableCodeLens",
277+
"category": "CodeLens Sample"
278+
},
279+
{
280+
"title": "Disable Codelens",
281+
"command": "codelens-sample.disableCodeLens",
282+
"category": "CodeLens Sample"
283+
},
270284
{
271285
"command": "codeQL.authenticateToGitHub",
272286
"title": "CodeQL: Authenticate to GitHub"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {
2+
CodeLensProvider,
3+
TextDocument,
4+
CodeLens,
5+
Range,
6+
Command
7+
} from 'vscode';
8+
9+
class MyCodeLensProvider implements CodeLensProvider {
10+
// Each provider requires a provideCodeLenses function which will give the various documents
11+
// the code lenses
12+
async provideCodeLenses(_document: TextDocument): Promise<CodeLens[]> {
13+
// Define where the CodeLens will exist
14+
const topOfDocument = new Range(0, 0, 0, 0);
15+
16+
// Define what command we want to trigger when activating the CodeLens
17+
const command: Command = {
18+
command: 'codeQL.quickEval',
19+
title: 'CodeQL: Quick Evaluation'
20+
};
21+
22+
const codeLens = new CodeLens(topOfDocument, command);
23+
24+
return [codeLens];
25+
}
26+
}
27+
28+
export default MyCodeLensProvider;

extensions/ql-vscode/src/extension.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ProgressLocation,
99
ProgressOptions,
1010
Uri,
11+
// workspace,
1112
window as Window,
1213
env,
1314
window,
@@ -20,6 +21,7 @@ import { testExplorerExtensionId, TestHub } from 'vscode-test-adapter-api';
2021

2122
import { AstViewer } from './astViewer';
2223
import * as archiveFilesystemProvider from './archive-filesystem-provider';
24+
import MyCodeLensProvider from './CodelensProvider';
2325
import { CodeQLCliServer, CliVersionConstraint } from './cli';
2426
import {
2527
CliConfigListener,
@@ -154,6 +156,23 @@ export interface CodeQLExtensionInterface {
154156
* @returns CodeQLExtensionInterface
155157
*/
156158
export async function activate(ctx: ExtensionContext): Promise<CodeQLExtensionInterface | Record<string, never>> {
159+
160+
const codelensProvider = new MyCodeLensProvider();
161+
162+
languages.registerCodeLensProvider('*', codelensProvider);
163+
164+
// commands.registerCommand('codelens-sample.enableCodeLens', () => {
165+
// void workspace.getConfiguration('codelens-sample').update('enableCodeLens', true, true);
166+
// });
167+
168+
// commands.registerCommand('codelens-sample.disableCodeLens', () => {
169+
// void workspace.getConfiguration('codelens-sample').update('enableCodeLens', false, true);
170+
// });
171+
172+
// commands.registerCommand('codelens-sample.codelensAction', (args: any) => {
173+
// void window.showInformationMessage(`CodeLens action clicked with args=${args}`);
174+
// });
175+
157176
void logger.log(`Starting ${extensionId} extension`);
158177
if (extension === undefined) {
159178
throw new Error(`Can't find extension ${extensionId}`);
@@ -461,6 +480,7 @@ async function activateWithInstalledDistribution(
461480
forceReveal: WebviewReveal
462481
): Promise<void> {
463482
await intm.showResults(query, forceReveal, false);
483+
console.log(query.query.quickEvalPosition);
464484
}
465485

466486
async function compileAndRunQuery(

0 commit comments

Comments
 (0)