Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft PR showcasing how to use filtered queries in the extension. #2661

Closed
wants to merge 1 commit into from

Conversation

starcke
Copy link
Contributor

@starcke starcke commented Aug 2, 2023

This is draft/WIP example on how to use an extensible predicate in the extraction queries, it showcases and relies on using the queries from github/codeql#13852.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

import { extLogger } from "../common/logging/vscode";
import { dir } from "tmp-promise";
import { writeFile, outputFile } from "fs-extra";
import { autoPickExtensionsDirectory } from "./extensions-workspace-folder";

Check notice

Code scanning / CodeQL

Unused variable, import, function or class

Unused import autoPickExtensionsDirectory.
import { dir } from "tmp-promise";
import { writeFile, outputFile } from "fs-extra";
import { autoPickExtensionsDirectory } from "./extensions-workspace-folder";
import { sign } from "crypto";

Check notice

Code scanning / CodeQL

Unused variable, import, function or class

Unused import sign.
Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I think this is reasonable.

@@ -380,13 +385,54 @@ export class DataExtensionsEditorView extends AbstractWebview<
let predictedModeledMethods: Record<string, ModeledMethod>;

if (useLlmGenerationV2()) {
// Generate a qlpack with a filter that only includes the usages we want to model.
const packDir = (await dir({ unsafeCleanup: true })).path;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dir will be cleaned when vscode exits?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure it does. I am working on the actual PR right now, this was mostly to a showcase to show how we could use the queries.

Comment on lines +391 to +399
const syntheticConfigPack = {
name: "codeql/automodel-filter",
version: "0.0.0",
library: true,
extensionTargets: {
[`codeql/${this.databaseItem.language}-all`]: "*",
},
dataExtensions: ["filter.yml"],
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

const usages = await runAutoModelQueries({
mode: this.mode,
cliServer: this.cliServer,
queryRunner: this.queryRunner,
queryStorageDir: this.queryStorageDir,
databaseItem: this.databaseItem,
progress: (update) => progress({ ...update, maxStep }),
extraExtensionPacks: [packDir],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting to see the name of the extension pack here. I haven't looked at the entire implementation, so you may already be doing this properly. The --extension-packs argument must be the name (and optional version) of the extension/model pack you want to use. And this pack must be available either in the package cache or from addtional-packs or from the workspace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored this slightly in my other PR. I moved package generation to auto-model-codeml-queries.ts. That means we can just do:

const additionalPacks = [...getOnDiskWorkspaceFolders(), filterPackDir];
const extensionPacks = Object.keys(
    await cliServer.resolveQlpacks(additionalPacks, true),
  );

and pass those directly to the run method:

  const candidates = await runAutoModelQuery({
    ...
    additionalPacks,
    extensionPacks,
    ...
  });

@starcke
Copy link
Contributor Author

starcke commented Aug 4, 2023

Closing in favor of #2670

@starcke starcke closed this Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants