Add code lens for "Open referenced file" (#2704)

This commit is contained in:
Shati Patel
2023-08-14 15:26:43 +01:00
committed by GitHub
parent a46209b22d
commit 2569f631a2
3 changed files with 46 additions and 2 deletions

View File

@@ -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)

View File

@@ -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
@@ -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);

View File

@@ -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;
}
}