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.
This commit is contained in:
committed by
Dave Bartolomeo
parent
cd427ee119
commit
c2d3829a72
@@ -31,26 +31,24 @@ export async function qlpackOfDatabase(cli: CodeQLCliServer, db: DatabaseItem):
|
||||
* @returns The found queries from the first pack in which any matching queries were found.
|
||||
*/
|
||||
async function resolveQueriesFromPacks(cli: CodeQLCliServer, qlpacks: string[], keyType: KeyType): Promise<string[]> {
|
||||
const suiteFile = (await tmp.file({
|
||||
postfix: '.qls'
|
||||
})).path;
|
||||
const suiteYaml = [];
|
||||
for (const qlpack of qlpacks) {
|
||||
const suiteFile = (await tmp.file({
|
||||
postfix: '.qls'
|
||||
})).path;
|
||||
const suiteYaml = {
|
||||
qlpack,
|
||||
suiteYaml.push({
|
||||
from: qlpack,
|
||||
queries: '.',
|
||||
include: {
|
||||
kind: kindOfKeyType(keyType),
|
||||
'tags contain': tagOfKeyType(keyType)
|
||||
}
|
||||
};
|
||||
await fs.writeFile(suiteFile, yaml.safeDump(suiteYaml), 'utf8');
|
||||
|
||||
const queries = await cli.resolveQueriesInSuite(suiteFile, helpers.getOnDiskWorkspaceFolders());
|
||||
if (queries.length > 0) {
|
||||
return queries;
|
||||
}
|
||||
});
|
||||
}
|
||||
await fs.writeFile(suiteFile, yaml.safeDump(suiteYaml), 'utf8');
|
||||
|
||||
return [];
|
||||
const queries = await cli.resolveQueriesInSuite(suiteFile, helpers.getOnDiskWorkspaceFolders());
|
||||
return queries;
|
||||
}
|
||||
|
||||
export async function resolveQueries(cli: CodeQLCliServer, qlpacks: QlPacksForLanguage, keyType: KeyType): Promise<string[]> {
|
||||
|
||||
@@ -7,6 +7,8 @@ import { CodeQLCliServer, QueryInfoByLanguage } from '../../cli';
|
||||
import { CodeQLExtensionInterface } from '../../extension';
|
||||
import { skipIfNoCodeQL } from '../ensureCli';
|
||||
import { getOnDiskWorkspaceFolders } from '../../helpers';
|
||||
import { resolveQueries } from '../../contextual/queryResolver';
|
||||
import { KeyType } from '../../contextual/keyType';
|
||||
|
||||
/**
|
||||
* Perform proper integration tests by running the CLI
|
||||
@@ -68,4 +70,16 @@ describe('Use cli', function() {
|
||||
const queryInfo: QueryInfoByLanguage = await cli.resolveQueryByLanguage(getOnDiskWorkspaceFolders(), Uri.file(queryPath));
|
||||
expect((Object.keys(queryInfo.byLanguage))[0]).to.eql('javascript');
|
||||
});
|
||||
|
||||
it.only('should resolve printAST queries', async function() {
|
||||
skipIfNoCodeQL(this);
|
||||
|
||||
const result = await resolveQueries(cli, {
|
||||
dbschemePack: 'codeql/javascript-all',
|
||||
dbschemePackIsLibraryPack: true,
|
||||
queryPack: 'codeql/javascript-queries'
|
||||
}, KeyType.PrintAstQuery);
|
||||
expect(result.length).to.eq(1);
|
||||
expect(result[0].endsWith('javascript/ql/src/printAst.ql')).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user