Skip to content

Commit ed18a2a

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 ed18a2a

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

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+
const editor = 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)