Skip to content

Commit f067c65

Browse files
committed
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.
1 parent 34fa629 commit f067c65

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

extensions/ql-vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Remove "last updated" information and sorting from variant analysis results view. [#2637](https://github.com/github/vscode-codeql/pull/2637)
66
- Links to code on GitHub now include column numbers as well as line numbers. [#2406](https://github.com/github/vscode-codeql/pull/2406)
77
- No longer highlight trailing commas for jump to definition. [#2615](https://github.com/github/vscode-codeql/pull/2615)
8+
- Fix a bug where the QHelp preview page was not being refreshed after changes to the underlying `.qhelp` file.
89

910
## 1.8.8 - 17 July 2023
1011

extensions/ql-vscode/src/common/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type BuiltInVsCodeCommands = {
5959
// The codeQLDatabases.focus command is provided by VS Code because we've registered the custom view
6060
"codeQLDatabases.focus": () => Promise<void>;
6161
"markdown.showPreviewToSide": (uri: Uri) => Promise<void>;
62+
"workbench.action.closeActiveEditor": () => Promise<void>;
6263
revealFileInOS: (uri: Uri) => Promise<void>;
6364
setContext: (
6465
key: `${"codeql" | "codeQL"}${string}`,

extensions/ql-vscode/src/language-support/query-editor.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Uri, window } from "vscode";
1+
import { Uri, ViewColumn, window, workspace } from "vscode";
22
import { CodeQLCliServer } from "../codeql-cli/cli";
33
import { QueryRunner } from "../query-server";
44
import { basename, join } from "path";
@@ -74,7 +74,16 @@ async function previewQueryHelp(
7474
const uri = Uri.file(absolutePathToMd);
7575
try {
7676
await cliServer.generateQueryHelp(pathToQhelp, absolutePathToMd);
77+
// Open the raw markdown file as well as the rendered file.
78+
// This will force the rendered page to refresh if there has been a change to the markdown.
79+
await window.showTextDocument(uri, {
80+
viewColumn: ViewColumn.Active,
81+
});
7782
await commandManager.execute("markdown.showPreviewToSide", uri);
83+
// close the editor we just opened. Users will see a brief flicker of this editor
84+
// being opened, but doing so will ensure that the preview is refreshed.
85+
await window.showTextDocument(uri);
86+
await commandManager.execute("workbench.action.closeActiveEditor");
7887
} catch (e) {
7988
const errorMessage = getErrorMessage(e).includes(
8089
"Generating qhelp in markdown",

0 commit comments

Comments
 (0)