Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [UNRELEASED]

- Add a code lens to make the `CodeQL: Open Referenced File` command more discoverable. Click the "Open referenced file" prompt in a `.qlref` file to jump to the referenced `.ql` file. [#2704](https://github.com/github/vscode-codeql/pull/2704)

## 1.8.9 - 3 August 2023

- Remove "last updated" information and sorting from variant analysis results view. [#2637](https://github.com/github/vscode-codeql/pull/2637)
Expand Down
12 changes: 10 additions & 2 deletions extensions/ql-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ import { TestRunner } from "./query-testing/test-runner";
import { TestManagerBase } from "./query-testing/test-manager-base";
import { NewQueryRunner, QueryRunner, QueryServerClient } from "./query-server";
import { QueriesModule } from "./queries-panel/queries-module";
import { OpenReferencedFileCodeLensProvider } from "./local-queries/open-referenced-file-code-lens-provider";

/**
* extension.ts
Expand Down Expand Up @@ -332,10 +333,17 @@ export async function activate(

const app = new ExtensionApp(ctx);

const codelensProvider = new QuickEvalCodeLensProvider();
const quickEvalCodeLensProvider = new QuickEvalCodeLensProvider();
languages.registerCodeLensProvider(
{ scheme: "file", language: "ql" },
codelensProvider,
quickEvalCodeLensProvider,
);

const openReferencedFileCodeLensProvider =
new OpenReferencedFileCodeLensProvider();
languages.registerCodeLensProvider(
{ scheme: "file", pattern: "**/*.qlref" },
openReferencedFileCodeLensProvider,
);

ctx.subscriptions.push(distributionConfigListener);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
CodeLensProvider,
TextDocument,
CodeLens,
Command,
Range,
} from "vscode";

export class OpenReferencedFileCodeLensProvider implements CodeLensProvider {
async provideCodeLenses(document: TextDocument): Promise<CodeLens[]> {
const codeLenses: CodeLens[] = [];

// A .qlref file is a file that contains a single line with a path to a .ql file.
if (document.fileName.endsWith(".qlref")) {
const textLine = document.lineAt(0);
const range: Range = new Range(
textLine.range.start.line,
textLine.range.start.character,
textLine.range.start.line,
textLine.range.end.character,
);

const command: Command = {
command: "codeQL.openReferencedFile",
title: `Open referenced file`,
arguments: [document.uri],
};
const codeLens = new CodeLens(range, command);
codeLenses.push(codeLens);
}

return codeLenses;
}
}