blob: 24181c537a3160773aab15a2803b2f525032aa57 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
// Convert protocol hover contents to VS Code MarkdownString objects.
// MarkupContent, legacy MarkedString, and arrays are all valid LSP responses.
function hoverContents(vscode, contents) {
const entries = Array.isArray(contents) ? contents : [contents];
const result = [];
for (const entry of entries) {
if (!entry) continue;
const value = typeof entry === 'string' ? entry : entry.value;
if (typeof value !== 'string' || !value) continue;
const md = new vscode.MarkdownString();
if (typeof entry === 'object' && entry.kind === 'plaintext') md.appendText(value);
else if (typeof entry === 'object' && typeof entry.language === 'string') md.appendCodeblock(value, entry.language);
else md.appendMarkdown(value);
md.supportHtml = false;
md.isTrusted = false;
result.push(md);
}
return result;
}
module.exports = { hoverContents };
|