Skip to content

Commit c2d3829

Browse files
aeisenbergDave Bartolomeo
authored andcommitted
Fix AST Viewer
The previous synthetic query suite was not finding the ast query because the `qlpack` directive in a query suite only matches queries from the default suite, which `printAST.ql` is not part of. This changes to using `from` and `queries` directives. Also, adds an integration test to ensure we find the queries using different CLIs. However, this only tests using the latest `main` from the codeql repository. I wonder if we should start testing using different versions of the repo.
1 parent cd427ee commit c2d3829

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

extensions/ql-vscode/src/contextual/queryResolver.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,24 @@ export async function qlpackOfDatabase(cli: CodeQLCliServer, db: DatabaseItem):
3131
* @returns The found queries from the first pack in which any matching queries were found.
3232
*/
3333
async function resolveQueriesFromPacks(cli: CodeQLCliServer, qlpacks: string[], keyType: KeyType): Promise<string[]> {
34+
const suiteFile = (await tmp.file({
35+
postfix: '.qls'
36+
})).path;
37+
const suiteYaml = [];
3438
for (const qlpack of qlpacks) {
35-
const suiteFile = (await tmp.file({
36-
postfix: '.qls'
37-
})).path;
38-
const suiteYaml = {
39-
qlpack,
39+
suiteYaml.push({
40+
from: qlpack,
41+
queries: '.',
4042
include: {
4143
kind: kindOfKeyType(keyType),
4244
'tags contain': tagOfKeyType(keyType)
4345
}
44-
};
45-
await fs.writeFile(suiteFile, yaml.safeDump(suiteYaml), 'utf8');
46-
47-
const queries = await cli.resolveQueriesInSuite(suiteFile, helpers.getOnDiskWorkspaceFolders());
48-
if (queries.length > 0) {
49-
return queries;
50-
}
46+
});
5147
}
48+
await fs.writeFile(suiteFile, yaml.safeDump(suiteYaml), 'utf8');
5249

53-
return [];
50+
const queries = await cli.resolveQueriesInSuite(suiteFile, helpers.getOnDiskWorkspaceFolders());
51+
return queries;
5452
}
5553

5654
export async function resolveQueries(cli: CodeQLCliServer, qlpacks: QlPacksForLanguage, keyType: KeyType): Promise<string[]> {

extensions/ql-vscode/src/vscode-tests/cli-integration/run-cli.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { CodeQLCliServer, QueryInfoByLanguage } from '../../cli';
77
import { CodeQLExtensionInterface } from '../../extension';
88
import { skipIfNoCodeQL } from '../ensureCli';
99
import { getOnDiskWorkspaceFolders } from '../../helpers';
10+
import { resolveQueries } from '../../contextual/queryResolver';
11+
import { KeyType } from '../../contextual/keyType';
1012

1113
/**
1214
* Perform proper integration tests by running the CLI
@@ -68,4 +70,16 @@ describe('Use cli', function() {
6870
const queryInfo: QueryInfoByLanguage = await cli.resolveQueryByLanguage(getOnDiskWorkspaceFolders(), Uri.file(queryPath));
6971
expect((Object.keys(queryInfo.byLanguage))[0]).to.eql('javascript');
7072
});
73+
74+
it.only('should resolve printAST queries', async function() {
75+
skipIfNoCodeQL(this);
76+
77+
const result = await resolveQueries(cli, {
78+
dbschemePack: 'codeql/javascript-all',
79+
dbschemePackIsLibraryPack: true,
80+
queryPack: 'codeql/javascript-queries'
81+
}, KeyType.PrintAstQuery);
82+
expect(result.length).to.eq(1);
83+
expect(result[0].endsWith('javascript/ql/src/printAst.ql')).to.be.true;
84+
});
7185
});

0 commit comments

Comments
 (0)