-
Notifications
You must be signed in to change notification settings - Fork 191
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,8 +57,13 @@ import { pickExtensionPack } from "./extension-pack-picker"; | |
import { getLanguageDisplayName } from "../common/query-language"; | ||
import { runAutoModelQueries } from "./auto-model-codeml-queries"; | ||
import { createAutoModelV2Request } from "./auto-model-v2"; | ||
import { load as loadYaml } from "js-yaml"; | ||
import { load as loadYaml, dump as dumpYaml } from "js-yaml"; | ||
import { loadDataExtensionYaml } from "./yaml"; | ||
import { extLogger } from "../common/logging/vscode"; | ||
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.
|
||
|
||
export class DataExtensionsEditorView extends AbstractWebview< | ||
ToDataExtensionsEditorMessage, | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This dir will be cleaned when vscode exits? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
const syntheticConfigPack = { | ||
name: "codeql/automodel-filter", | ||
version: "0.0.0", | ||
library: true, | ||
extensionTargets: { | ||
[`codeql/${this.databaseItem.language}-all`]: "*", | ||
}, | ||
dataExtensions: ["filter.yml"], | ||
}; | ||
Comment on lines
+391
to
+399
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice |
||
|
||
const qlpackFile = join(packDir, "codeql-pack.yml"); | ||
await outputFile(qlpackFile, dumpYaml(syntheticConfigPack), "utf8"); | ||
|
||
// TODO: this filter is just static as an example. We want to generate this from the usages. | ||
const filter = { | ||
extensions: [ | ||
{ | ||
addsTo: { | ||
pack: `codeql/${this.databaseItem.language}-queries`, | ||
extensible: "automodelCandidateFilter", | ||
}, | ||
data: [ | ||
["org.sql2o", "Sql2o", "open", "()"], | ||
[ | ||
"org.springframework.boot", | ||
"SpringApplication", | ||
"run", | ||
"(Class,String[])", | ||
], | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
const filterFile = join(packDir, "filter.yml"); | ||
await writeFile(filterFile, dumpYaml(filter), "utf8"); | ||
|
||
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], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
and pass those directly to the run method:
|
||
}); | ||
if (!usages) { | ||
return; | ||
|
@@ -398,6 +444,38 @@ export class DataExtensionsEditorView extends AbstractWebview< | |
message: "Creating request", | ||
}); | ||
|
||
// TODO: TEMP LOGGING CODE - START | ||
const results = usages.candidates.runs[0].results; | ||
void extLogger.log(`CANDIDATES:`); | ||
results?.forEach((result) => { | ||
const pckage = | ||
result.relatedLocations?.[1].physicalLocation?.artifactLocation?.uri?.substring( | ||
6, | ||
); | ||
const tp = | ||
result.relatedLocations?.[2].physicalLocation?.artifactLocation?.uri?.substring( | ||
6, | ||
); | ||
const method = | ||
result.relatedLocations?.[4].physicalLocation?.artifactLocation?.uri?.substring( | ||
6, | ||
); | ||
let signature = | ||
result.relatedLocations?.[5].physicalLocation?.artifactLocation?.uri?.substring( | ||
6, | ||
); | ||
signature = signature && decodeURI(signature); | ||
let input = | ||
result.relatedLocations?.[6].physicalLocation?.artifactLocation?.uri?.substring( | ||
6, | ||
); | ||
input = input && decodeURI(input); | ||
void extLogger.log( | ||
`${pckage}.${tp}.${method}${signature} @ ${input}`, | ||
); | ||
}); | ||
// TODO: TEMP LOGGING CODE - END | ||
|
||
const request = await createAutoModelV2Request(this.mode, usages); | ||
|
||
progress({ | ||
|
Check notice
Code scanning / CodeQL
Unused variable, import, function or class