-
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
Remote queries: Open query file/text from webview #1041
Conversation
extensions/ql-vscode/src/remote-queries/shared/remote-query-result.ts
Outdated
Show resolved
Hide resolved
extensions/ql-vscode/src/remote-queries/remote-queries-interface.ts
Outdated
Show resolved
Hide resolved
f581df3
to
fc70f6b
Compare
Latest commit adds a temporary file containing exact query text. In the local version of showing query text, we create a "text provider" and write to a read-only document: vscode-codeql/extensions/ql-vscode/src/query-history.ts Lines 343 to 356 in 6195c65
I couldn't work out how to re-use that code, or just import the relevant parts (creating a read-only doc), so I've gone with a more lightweight approach of writing to a temporary file for now. Happy to adjust if anyone has suggestions! 🙇🏽♀️ |
// Get the query text from query file and save it in a temporary .ql file. | ||
const queryTextTmpFilePath = path.join(tmpDir.name, `tmp-${queryName}`); | ||
const queryText = await fs.readFile(queryFilePath, 'utf8'); | ||
await fs.writeFile( |
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.
So, this creates the temp file before a user ever tries to open it (and the user may never try to do so). Also, this file may get cleaned up if the user restarts vscode. Can we ever get a situation where the file is removed before someone tries to open it (eg- after a restart)?
Maybe it's safer to generate this file only when requested.
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.
Moved to a different approach (using a virtual file), so this temporary file no longer exists! ☁️
(There's still the general problem that remote query data doesn't persist across restarts, but that's beyond this PR 😅 We have a separate issue for that somewhere)
Do you want to have a look at that together? |
dc72f5a
to
4d97015
Compare
We worked through this using the existing I've registered a new "remote-query" text provider to let us write to a readonly file. Ideally, I'd like to slightly refactor the QueryHistoryManager code, so that we use a single |
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 great! Only super minor things.
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.
Lets make sure the styling is correct for the new buttons.
private async openFile(filePath: string) { | ||
try { | ||
const textDocument = await workspace.openTextDocument(filePath); | ||
await Window.showTextDocument(textDocument, ViewColumn.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.
true | ||
); | ||
const doc = await workspace.openTextDocument(uri); | ||
await Window.showTextDocument(doc, { preview: false }); |
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.
Is this read-only? It's possible to make happen, but I forget how.
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.
Indeed, it's read-only! That's what the remote-query
prefix and the corresponding provideTextDocumentContent function do 😃
Adds some interaction to these buttons in the remote queries webview:
Follow up
remote-query
andcodeql
text providers.Checklist
N/A: Still an internal-only feature. No user-visible changes.
@github/docs-content-codeql
has been cc'd in all issues for UI or other user-facing changes made by this pull request.