Skip to content

Commit 65bf56f

Browse files
committed
feat(twoslash/rich): renders jsdoc
1 parent 6ca3475 commit 65bf56f

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

packages/shikiji-twoslash/src/renderer-rich.ts

+22
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import type { CompletionItem } from './icons'
44
import { defaultCompletionIcons, defaultCustomTagIcons } from './icons'
55

66
export interface RendererRichOptions {
7+
/**
8+
* Render JSDoc comments in hover popup.
9+
*
10+
* @default true
11+
*/
12+
jsdoc?: boolean
13+
714
/**
815
* Custom icons for completion items.
916
* A map from completion item kind to a HAST node.
@@ -44,6 +51,7 @@ export function rendererRich(options: RendererRichOptions = {}): TwoSlashRendere
4451
customTagIcons = defaultCustomTagIcons,
4552
formatInfo = info => info,
4653
classExtra = '',
54+
jsdoc = true,
4755
} = options
4856
return {
4957
nodeStaticInfo(info, node) {
@@ -53,6 +61,20 @@ export function rendererRich(options: RendererRichOptions = {}): TwoSlashRendere
5361
transforms: undefined,
5462
}).children[0] as Element).children[0] as Element).children
5563

64+
if (jsdoc && info.docs) {
65+
themedContent.push({
66+
type: 'element',
67+
tagName: 'div',
68+
properties: { class: 'twoslash-popup-jsdoc' },
69+
children: [
70+
{
71+
type: 'text',
72+
value: info.docs,
73+
},
74+
],
75+
})
76+
}
77+
5678
return {
5779
type: 'element',
5880
tagName: 'span',

packages/shikiji-twoslash/style-rich.css

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* ===== Basic ===== */
22
:root {
33
--twoslash-border-color: #8888;
4+
--twoslash-jsdoc-color: #888;
45
--twoslash-underline-color: currentColor;
56
--twoslash-popup-bg: #f8f8f8;
67
--twoslash-popup-shadow: rgba(0, 0, 0, 0.08) 0px 1px 4px;
@@ -81,6 +82,14 @@
8182
pointer-events: none;
8283
}
8384

85+
.twoslash .twoslash-popup-jsdoc {
86+
color: var(--twoslash-jsdoc-color);
87+
padding-top: 6px;
88+
padding-bottom: 2px;
89+
font-family: sans-serif;
90+
font-size: 0.8em;
91+
}
92+
8493
/* ===== Error Line ===== */
8594
.twoslash .twoslash-error-line {
8695
position: relative;

0 commit comments

Comments
 (0)