Skip to content

Modify QueryDiscovery to resolve queries by language#2471

Closed
robertbrignull wants to merge 2 commits intomainfrom
robertbrignull/resolve-queries-by-language
Closed

Modify QueryDiscovery to resolve queries by language#2471
robertbrignull wants to merge 2 commits intomainfrom
robertbrignull/resolve-queries-by-language

Conversation

@robertbrignull
Copy link
Copy Markdown
Contributor

Changes QueryDiscovery to pass the --format=bylanguage arg to codeql resolve queries. This makes it indicate which language each query is for, if that information is known. We're not using this new info yet, but that'll come soon so we want to have the data ready.

The tests proved to be quite fiddly to get right, and creation of mock data is a big clunky. There might be cleaner ways of doing this, and we could look into that if this solution is too awful.

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.

@robertbrignull robertbrignull requested a review from a team June 1, 2023 16:06
@robertbrignull robertbrignull requested a review from a team as a code owner June 1, 2023 16:06
Copy link
Copy Markdown
Contributor

@shati-patel shati-patel left a comment

Choose a reason for hiding this comment

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

[as discussed offline as well]

I've tested this locally and, whilst it does work, it's unbearably slow on my (Windows) machine 😅 E.g. in the vscode-codeql-starter workspace, it takes well over a minute to populate/update the queries panel.

This is an issue with the underlying CLI command to resolve queries by language, so we should think about where/how best to solve this. (I'll link an existing internal issue about the slowness on Windows... 🔗)

*/
private async discoverQueries(
workspaceFolders: readonly WorkspaceFolder[],
workspaceFolders: WorkspaceFolder[],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we instead change the argument types of the discoverQueriesInWorkspaceFolder function so that it also takes a readonly array? It seems like this should still be readonly.

workspaceFolders: WorkspaceFolder[],
): Promise<FileTreeDirectory[]> {
const rootDirectories = [];
const allWorkspceFolderPaths = workspaceFolders.map((f) => f.uri.fsPath);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
const allWorkspceFolderPaths = workspaceFolders.map((f) => f.uri.fsPath);
const allWorkspaceFolderPaths = workspaceFolders.map((f) => f.uri.fsPath);

const fullPath = workspaceFolder.uri.fsPath;
const name = workspaceFolder.name;

// We don't want to log each invocation of resolveQueries, since it clutters up the log.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// We don't want to log each invocation of resolveQueries, since it clutters up the log.
// We don't want to log each invocation of resolveQueryByLanguage, since it clutters up the log.

return jest.fn().mockImplementation((queryDir: Uri) => {
const data = dataFn(queryDir.fsPath);
const value: QueryInfoByLanguage = {
byLanguage: Object.keys(data.byLanguage || {}).reduce((result, key) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we use Object.entries here instead of Object.keys to avoid needing to call data.byLanguage![key]?

result[key] = queriesArrayToRecord(data.byLanguage![key]);
return result;
}, {} as QueryInfoByLanguage["byLanguage"]),
noDeclaredLanguage: queriesArrayToRecord(data.noDeclaredLanguage || []),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We could move the || [] into the declaration of queriesArrayToRecord by adding queries: string[] = []. I think this would make this a bit shorter.

@robertbrignull
Copy link
Copy Markdown
Contributor Author

We're no longer going ahead with this PR. We hit some snags using --format bylanguage and decided to change the approach we use. Instead of using the CodeQL CLI to get all query information for us, we'll do a lot of it more manually.

@robertbrignull robertbrignull deleted the robertbrignull/resolve-queries-by-language branch June 9, 2023 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants