Remote queries: Open query file/text from webview#1041
Remote queries: Open query file/text from webview#1041shati-patel merged 5 commits intogithub:mainfrom
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.
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.
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 |
charisk
left a comment
There was a problem hiding this comment.
Looks great! Only super minor things.
charisk
left a comment
There was a problem hiding this comment.
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); |
| true | ||
| ); | ||
| const doc = await workspace.openTextDocument(uri); | ||
| await Window.showTextDocument(doc, { preview: false }); |
There was a problem hiding this comment.
Is this read-only? It's possible to make happen, but I forget how.
There was a problem hiding this comment.
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-queryandcodeqltext providers.Checklist
N/A: Still an internal-only feature. No user-visible changes.
@github/docs-content-codeqlhas been cc'd in all issues for UI or other user-facing changes made by this pull request.