-
Notifications
You must be signed in to change notification settings - Fork 191
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
Add Generate Qlhelp preview command #988
Conversation
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 new command looks exciting! (Not a real review yet, just a small comment about terminology)
d03d7a1
to
8a4b6fd
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.
Thanks! This is a good start to a much-awaited feature.
Most comments are about security (this command should only be run in a trusted workspace) and file/path handling. There is one longer suggestion about whether we should share the temporary file mechanism used for DIL and results files, on which I'd like opinions from the others on the team.
async function previewQueryHelp( | ||
selectedQuery: Uri | ||
): Promise<void> { | ||
const path = selectedQuery ? selectedQuery.path : window.activeTextEditor!.document.uri.fsPath; |
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.
If this command is called from the context menu on the editor, I would expect selectedQuery
to be exactly window.activeTextEditor.document.uri
. Is that what you observed while testing this?
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.
Yes, as far as I've observed they are equal. JSON.stringify(selectedQuery) === JSON.stringify(window.activeTextEditor.document.uri)
also evaluates to true
in the cases I've tested
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.
In that case I think it should be enough to use selectedQuery.fsPath
.
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.
As in path = selectedQuery ? selectedQuery.fsPath : window.activeTextEditor.document.uri
or just path = selectedQuery.fsPath
?
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.
Just path = selectedQuery.fsPath
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.
path = selectedQuery.fsPath
fails for me when I run the command from the palette
const path = selectedQuery ? selectedQuery.path : window.activeTextEditor!.document.uri.fsPath; | ||
if(path) { | ||
// Create temporary directory | ||
const tmpDir = tmp.dirSync(); |
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.
Using a temporary directory is sensible. However we must be extra careful to clean it up properly, especially on Windows.
Have you seen the other uses of temporary directories in run-queries.ts
? I suggest you follow that pattern as closely as possible. In particular, I recommend passing similar options to dirSync
, and creating a dispose callback that can be registered with the extension via ctx.subscriptions.push(callback)
, so that the extension cleans up the temporary directories when it shuts down.
More detailed discussion: We could achieve more elegant code by adding an extra field to the QueryInfo
class in run-queries.ts
, which currently tracks a dilPath
and resultsPath
for each completed query. What do others think?
- Advantages: It handles all the temporary directories already, associates each query with a number of temporary file paths, and doesn't repeat work if the file has already been generated.
- Disadvantages: It only works for queries that have been run, which seems unreasonable for previewing query help. We would also have to track whether the
.qhelp
file had been modified.
const errorMessage = err.message.includes('Generating qhelp in markdown') ? ( | ||
`Could not generate markdown from ${path}: Bad formatting in .qhelp file.` | ||
) : `Could not open a preview of the generated file (${absolutePathToMd}).`; | ||
void helpers.showAndLogErrorMessage(errorMessage); |
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 think this will suppress the error message from the CLI, which is hopefully useful. Could we include err
in the message we construct here?
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.
Just tried this locally and found one more thing! Looks good otherwise 🎇
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.
Sorry to leave this hanging! I think this is mostly good to merge, though I've highlighted one of the earlier review comments which looks worth doing 😃
const errorMessage = err.message.includes('Generating qhelp in markdown') ? ( | ||
`Could not generate markdown from ${pathToQhelp}: Bad formatting in .qhelp file.` | ||
) : `Could not open a preview of the generated file (${absolutePathToMd}).`; | ||
void helpers.showAndLogErrorMessage(errorMessage); |
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.
As @adityasharad mentioned above (in #988 (comment)), it would be nice to print err
itself somewhere (perhaps using logger.log(...)
?) 📝
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.
Looking good, thank you. Final round of minor suggestions :)
@@ -493,6 +494,32 @@ async function activateWithInstalledDistribution( | |||
} | |||
} | |||
|
|||
const tmpDir = tmp.dirSync({ prefix: 'qhelp_', keep: false, unsafeCleanup: true }); |
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.
Minor: Rename this to qhelpTmpDir
(or something similarly meaningful) so we can remember what it's for.
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.
Also I think this pattern does the right thing on Windows (since we use it elsewhere in the extension), but I would not object to a second look from @shati-patel.
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.
Also I think this pattern does the right thing on Windows (since we use it elsewhere in the extension), but I would not object to a second look from @shati-patel.
Looks good to me too! 😊
76c63a8
to
3d198e7
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 good to me! Once you've tidied up the changelog this should be ready to merge 🥳
extensions/ql-vscode/CHANGELOG.md
Outdated
- Add a _CodeQL: Preview Query Help_ command to generate Markdown previews of `.qhelp` query help files. This command should only be run in trusted workspaces. See https://codeql.github.com/docs/codeql-cli/testing-query-help-files for more information about query help. [#988](https://github.com/github/vscode-codeql/pull/988) | ||
- Make "Open Referenced File" command accessible from the active editor menu. [#989](https://github.com/github/vscode-codeql/pull/989) | ||
- Add a _CodeQL: Preview Query Help File_ command to generate and preview query documentation in markdown format from a .qhelp file. [#988](https://github.com/github/vscode-codeql/pull/988) | ||
- Add a _CodeQL: Preview Query Help_ command to generate Markdown previews of `.qhelp` query help files. See https://codeql.github.com/docs/codeql-cli/testing-query-help-files for more information about query help. [#988](https://github.com/github/vscode-codeql/pull/988) |
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.
There are some outdated copies of the changelog entry here! The top one looks most correct, so you can delete the others :)
d5b29bb
to
7f5ef6f
Compare
Nice work! Thank you 🎈 🥳 |
Adds a "Generate Query Help" command which generates a .md file from a selected .qhelp file and opens it for preview in vscode. Implements #481
Checklist
@github/docs-content-codeql
has been cc'd in all issues for UI or other user-facing changes made by this pull request.