In Visual Studio code version 1.64, MarkdownString with 4 leading spaces is displayed as blank in Hover

Viewed 53

Our Visual Studio Code Extension uses the HoverProvider API to show custom hovers on the editor. We are using MarkdownString for the hover content with 4 leading spaces for each line to enable syntax coloring. Till version 1.63, this was working fine. But on using vscode version 1.64, hover shows empty tooltips.

Turns out that the issue is resolved once the leading spaces are removed. But the syntax coloring does not show up if there are no leading spaces. Is there a change in the behavior of MarkdownString, or is there a different way to enable syntax coloring for the data type?

1 Answers

I think the preferred way is to use this:

const markdownString = new vscode.MarkdownString();
        
const codeBlock = `const a = 12;
if (a) return;`;    // any preceding tabs will be rendered in a template literal, so flush left

// const codeBlock2 = `const c = 12;\nif (c) return;`;  // works, alternate form with newline

markdownString.appendCodeblock(codeBlock, "javascript");

markdownString.isTrusted = true;

return new vscode.Hover(markdownString, new vscode.Range(position, position));

Also the <pre> and <code> tags are supported in markdownString's:

content.appendMarkdown(`<p><b> Some label: <code>${value}</code></b></p>`);
Related