-
Notifications
You must be signed in to change notification settings - Fork 189
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
Autodetect what language a query is for #915
Conversation
c17caba
to
dac4201
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks right to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good apart from a minor comment inline. I'll hold off on approving it, though, since we paired on this for a bit so it should probably have another set of eyes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I think the code is mostly ready to go, with one outstanding suggestion from Edoardo about return types, and one from me about logging.
I've added some suggestions about tests, but I think those are fine to add later, since it will require some upfront work to set up tests for this part of the code.
Have we been adding changelog entries for this feature?
* Resolves the language for a query. | ||
* @param queryUri The URI of the query | ||
*/ | ||
async resolveQueryByLanguage(workspaces: string[], queryUri: Uri): Promise<QueryInfoByLanguage> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you asked about tests:
extensions/ql-vscode/src/vscode-tests/cli-integration/run-cli.test.ts
is a good place to add integration tests for theresolveQueryByLanguage
andresolveLanguages
functions.- You can use the existing tests as an example.
resolveLanguages
is probably easier to write a test for because there's no query as input.resolveQueryByLanguage
will require a test query: there are some examples in thedata
folders, but as far as I can tell none of them depend on an actual language. So you may need to add one, or save this test for later.
* Finds the language that a query targets. | ||
* If it can't be autodetected, prompt the user to specify the language manually. | ||
*/ | ||
export async function findLanguage( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you asked about tests: I agree that having tests for this function would be handy, and give you confidence in its behaviour. However we don't yet have a test module for run-remote-query
due to the experimental nature of the entire feature, so adding a test requires some upfront work. (In future it will be easier :) )
I'll record some pointers here about how you could create those tests, but I'm not expecting you to do it in this PR. We can look at test coverage together after this PR.
- For integration tests (which use a real query and actually run the underlying commands), copy
extensions/ql-vscode/src/vscode-tests/cli-integration/queries.test.ts
as a template. I think it would make sense to have:- one test function that runs
findLanguage
on a query with a real language dependency and identifies the language - one test function that runs it on a dummy query and returns
undefined
- any other cases you can think of
- one test function that runs
- For unit tests (which don't run the actual commands, but simulate the underlying behaviour), use
extensions/ql-vscode/src/vscode-tests/no-workspace/query-results.test.ts
as a template. Those tests mock the behaviour of the CLI server.
Also use autodection in relevant places - When running on multiple databases - When running a remote query
- Tweak return types + logging - Update changelog
b8a90b7
to
83c68ec
Compare
Thank you for the reviews ✨ I've addressed the main comments in 83c68ec and added a minimal changelog entry that covers the user-facing part of this. I'll look at adding tests in a separate PR! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple more minor comments, but otherwise looks good!
return; | ||
} | ||
} | ||
const quickPickItems = filteredDBs.map<DatabaseQuickPickItem>(dbItem => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that if the user has no databases and doesn't pick a language when prompted, we try to display this prompt with nothing in it. There should probably be an extra check to display an error in this case and return, similarly to what happens with the filtered list above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops, good point! Thanks 😄
const repositories = config.repositories; | ||
|
||
if (!language) { | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a brief comment stating that we don't need an error message here because findLanguage
already displays one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing all my comments, this LGTM 👍🏼
Adds a
findLanguage
function that usescodeql resolve queries --format bylanguage
to detect a query's language. This might not work for some queries, so I've added a manual selection as a fallback.This is used in two places:
.repositories
config. This config file is going to be replaced by a different UI soon.)Question: Does this need tests? I wasn't sure where/how to go about that!
Checklist
@github/docs-content-codeql
has been cc'd in all issues for UI or other user-facing changes made by this pull request.