Skip to content

Commit 2c52884

Browse files
committed
feat(vitepress): support errorRendering hover
1 parent 28e325c commit 2c52884

File tree

5 files changed

+44
-14
lines changed

5 files changed

+44
-14
lines changed

docs/.vitepress/config.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,11 @@ export default withMermaid(defineConfig({
112112
},
113113
},
114114
transformerTwoslash({
115+
// errorRendering: 'hover',
115116
processHoverInfo(info) {
116117
return defaultHoverInfoProcessor(info)
117118
// Remove shiki_core namespace
118-
.replace(/shiki_core\./g, '')
119-
// Remove member access
120-
.replace(/^[a-zA-Z0-9_]*(\<[^\>]*\>)?\./, '')
119+
.replace(/_shikijs_core[\w_]*\./g, '')
121120
},
122121
}),
123122
{

packages/twoslash/style-rich.css

+4
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@
140140
color: var(--twoslash-error-color);
141141
padding: 6px 12px;
142142
margin: 0.2em 0;
143+
min-width: 100%;
144+
width: max-content;
143145
}
144146

145147
.twoslash .twoslash-error-line.twoslash-error-level-warning {
@@ -250,6 +252,8 @@
250252
display: flex;
251253
align-items: center;
252254
gap: 0.3em;
255+
min-width: 100%;
256+
width: max-content;
253257
}
254258

255259
.twoslash .twoslash-tag-line .twoslash-tag-icon {

packages/vitepress-twoslash/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TransformerTwoslashOptions, TwoslashFunction } from '@shikijs/twoslash/core'
1+
import type { TransformerTwoslashOptions } from '@shikijs/twoslash/core'
22
import { createTransformerFactory } from '@shikijs/twoslash/core'
33
import { createTwoslasher } from 'twoslash-vue'
44
import type { ShikiTransformer } from 'shiki'

packages/vitepress-twoslash/src/renderer-floating-vue.ts

+14
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export function rendererFloatingVue(options: TwoslashFloatingVueRendererOptions
3737
floatingVueThemeCompletion = 'twoslash-completion',
3838
} = options.floatingVue || {}
3939

40+
const {
41+
errorRendering = 'line',
42+
} = options
43+
4044
const hoverBasicProps = {
4145
'class': 'twoslash-hover',
4246
'popper-class': ['shiki', classFloatingPanel, classCopyIgnore, classCode].join(' '),
@@ -91,6 +95,16 @@ export function rendererFloatingVue(options: TwoslashFloatingVueRendererOptions
9195
popupDocsTags: {
9296
class: `twoslash-popup-docs twoslash-popup-docs-tags ${classMarkdown}`,
9397
},
98+
errorToken: errorRendering === 'line'
99+
? undefined
100+
: {
101+
tagName: 'v-menu',
102+
properties: {
103+
...hoverBasicProps,
104+
class: 'twoslash-error twoslash-error-hover',
105+
},
106+
},
107+
errorCompose: compose,
94108
completionCompose({ popup, cursor }) {
95109
return [
96110
<Element>{

packages/vitepress-twoslash/src/style.css

+23-10
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
--twoslash-unmatched-color: var(--vp-c-text-2);
1313
}
1414

15-
.twoslash-error-line,
16-
.twoslash-tag-line {
17-
width: max-content;
18-
}
19-
2015
.v-popper--theme-twoslash {
2116
z-index: calc(var(--vp-z-index-local-nav) - 1);
2217
}
@@ -63,9 +58,8 @@
6358
white-space: pre-wrap;
6459
}
6560

66-
.twoslash-floating .twoslash-popup-docs {
67-
border-top: 1px solid var(--twoslash-border-color);
68-
color: var(--twoslash-docs-color);
61+
.twoslash-floating .twoslash-popup-docs,
62+
.twoslash-floating .twoslash-popup-error {
6963
padding: 0px 12px 0px 12px !important;
7064
font-family: var(--twoslash-docs-font);
7165
font-size: 0.9em;
@@ -76,13 +70,32 @@
7670
text-wrap: balance;
7771
}
7872

79-
.twoslash-floating .twoslash-popup-docs p {
73+
.twoslash-floating .twoslash-popup-docs {
74+
border-top: 1px solid var(--twoslash-border-color);
75+
color: var(--twoslash-docs-color);
76+
}
77+
78+
.twoslash-floating .twoslash-popup-error {
79+
color: var(--twoslash-error-color);
80+
}
81+
82+
.twoslash-floating .twoslash-popup-error.twoslash-error-level-warning {
83+
color: var(--twoslash-warn-color);
84+
}
85+
86+
.twoslash-floating .twoslash-popup-docs p,
87+
.twoslash-floating .twoslash-popup-error p {
8088
margin: 0;
8189
padding: 6px 0;
8290
text-wrap: balance;
8391
}
8492

85-
.twoslash-floating .twoslash-popup-docs pre {
93+
.twoslash-floating
94+
.twoslash-popup-docs
95+
pre
96+
.twoslash-floating
97+
.twoslash-popup-error
98+
pre {
8699
background-color: var(--vp-code-block-bg);
87100
border-radius: 8px;
88101
padding: 12px;

0 commit comments

Comments
 (0)