From f067c6540bf0b05fcc43f8352e233390a99d563c Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Mon, 31 Jul 2023 16:18:34 -0700 Subject: [PATCH] Ensure the qhelp preview is refreshed after editing This commit fixes a bug in the extension where the qhelp preview was not being refreshed after the first time the preview was rendered. The reason is that vscode will not refresh the markdown preview unless the original file with the markdown in it is already open in the editor. This fix will briefly open the raw markdown, refresh the preview and close the raw markdown. --- extensions/ql-vscode/CHANGELOG.md | 1 + extensions/ql-vscode/src/common/commands.ts | 1 + .../ql-vscode/src/language-support/query-editor.ts | 11 ++++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index 472b02026..dd3fbbed9 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -5,6 +5,7 @@ - Remove "last updated" information and sorting from variant analysis results view. [#2637](https://github.com/github/vscode-codeql/pull/2637) - Links to code on GitHub now include column numbers as well as line numbers. [#2406](https://github.com/github/vscode-codeql/pull/2406) - No longer highlight trailing commas for jump to definition. [#2615](https://github.com/github/vscode-codeql/pull/2615) +- Fix a bug where the QHelp preview page was not being refreshed after changes to the underlying `.qhelp` file. ## 1.8.8 - 17 July 2023 diff --git a/extensions/ql-vscode/src/common/commands.ts b/extensions/ql-vscode/src/common/commands.ts index d7fd85899..93a310e90 100644 --- a/extensions/ql-vscode/src/common/commands.ts +++ b/extensions/ql-vscode/src/common/commands.ts @@ -59,6 +59,7 @@ type BuiltInVsCodeCommands = { // The codeQLDatabases.focus command is provided by VS Code because we've registered the custom view "codeQLDatabases.focus": () => Promise; "markdown.showPreviewToSide": (uri: Uri) => Promise; + "workbench.action.closeActiveEditor": () => Promise; revealFileInOS: (uri: Uri) => Promise; setContext: ( key: `${"codeql" | "codeQL"}${string}`, diff --git a/extensions/ql-vscode/src/language-support/query-editor.ts b/extensions/ql-vscode/src/language-support/query-editor.ts index 32f840657..3e393a9d6 100644 --- a/extensions/ql-vscode/src/language-support/query-editor.ts +++ b/extensions/ql-vscode/src/language-support/query-editor.ts @@ -1,4 +1,4 @@ -import { Uri, window } from "vscode"; +import { Uri, ViewColumn, window, workspace } from "vscode"; import { CodeQLCliServer } from "../codeql-cli/cli"; import { QueryRunner } from "../query-server"; import { basename, join } from "path"; @@ -74,7 +74,16 @@ async function previewQueryHelp( const uri = Uri.file(absolutePathToMd); try { await cliServer.generateQueryHelp(pathToQhelp, absolutePathToMd); + // Open the raw markdown file as well as the rendered file. + // This will force the rendered page to refresh if there has been a change to the markdown. + await window.showTextDocument(uri, { + viewColumn: ViewColumn.Active, + }); await commandManager.execute("markdown.showPreviewToSide", uri); + // close the editor we just opened. Users will see a brief flicker of this editor + // being opened, but doing so will ensure that the preview is refreshed. + await window.showTextDocument(uri); + await commandManager.execute("workbench.action.closeActiveEditor"); } catch (e) { const errorMessage = getErrorMessage(e).includes( "Generating qhelp in markdown",