Skip to content

Commit

Permalink
Add additional-packs to fix library path resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
shati-patel committed Jul 26, 2021
1 parent 5a5f990 commit c17caba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 10 additions & 4 deletions extensions/ql-vscode/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,17 +486,23 @@ export class CodeQLCliServer implements Disposable {
* Finds the language that a query is analyzing.
* @param queryUri The URI of the query
*/

// Note: this currently fails for some queries, e.g. the "example" snippets..."
async findLanguage(queryUri?: Uri): Promise<string> {
async findLanguage(workspaces: string[], queryUri?: Uri): Promise<string> {
let language = '';
if (queryUri) {
const subcommandArgs = [
'--format', 'bylanguage',
queryUri.fsPath,
'--additional-packs',
workspaces.join(path.delimiter)
];
try {
const JSONResults = await this.runCodeQlCliCommand(['resolve', 'queries'], ['--format', 'bylanguage', queryUri.fsPath], 'Finding query language');
const JSONResults = await this.runCodeQlCliCommand(['resolve', 'queries'], subcommandArgs, 'Finding query language');

// This corresponds to `codeql resolve queries <query> --format bylanguage | jq -r '.byLanguage | keys[]'`
language = Object.keys(JSON.parse(JSONResults).byLanguage)[0];
}
catch (e) {
// Add an option to manually specify the language, in case automatic language detection fails.
void this.logger.log('Failed to detect language. Using manual prompt instead.');
language = await window.showQuickPick(
['cpp', 'csharp', 'go', 'java', 'javascript', 'python'], { placeHolder: 'Select language' }
Expand Down
4 changes: 3 additions & 1 deletion extensions/ql-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,13 @@ async function activateWithInstalledDistribution(
}
)
);
// TODO: Remove this. (Temporary command to test `cliServer.findLanguage`)
ctx.subscriptions.push(
commandRunner('codeQL.findLanguage', async (
uri: Uri | undefined
) => {
const language = await cliServer.findLanguage(uri || window.activeTextEditor?.document.uri);
const diskWorkspaceFolders = helpers.getOnDiskWorkspaceFolders();
const language = await cliServer.findLanguage(diskWorkspaceFolders, uri || window.activeTextEditor?.document.uri);
void helpers.showAndLogInformationMessage(language);
})
);
Expand Down

0 comments on commit c17caba

Please sign in to comment.