@@ -91,39 +91,48 @@ export function transformerTwoSlash(options: TransformerTwoSlashOptions = {}): S
91
91
throw new Error ( `[shikiji-twoslash] Cannot find token at L${ line } :${ character } ` )
92
92
}
93
93
94
+ const skipTokens = new Set < Element | Text > ( )
95
+
94
96
for ( const error of twoslash . errors ) {
95
97
if ( error . line == null || error . character == null )
96
98
return
97
99
const token = locateTextToken ( error . line , error . character )
98
100
if ( ! token )
99
101
continue
100
102
103
+ skipTokens . add ( token )
104
+
101
105
const clone = { ...token }
102
106
Object . assign ( token , renderer . nodeError . call ( this , error , clone ) )
103
107
104
108
insertAfterLine ( error . line , renderer . lineError . call ( this , error ) )
105
109
}
106
110
111
+ for ( const query of twoslash . queries ) {
112
+ if ( query . kind === 'completions' ) {
113
+ insertAfterLine ( query . line , renderer . lineCompletions . call ( this , query ) )
114
+ }
115
+ else if ( query . kind === 'query' ) {
116
+ const token = locateTextToken ( query . line - 1 , query . offset )
117
+ if ( token )
118
+ skipTokens . add ( token )
119
+ insertAfterLine ( query . line , renderer . lineQuery . call ( this , query , token ) )
120
+ }
121
+ }
122
+
107
123
for ( const info of twoslash . staticQuickInfos ) {
108
124
const token = locateTextToken ( info . line , info . character )
109
125
if ( ! token || token . type !== 'text' )
110
126
continue
111
127
128
+ // If it's already rendered as popup or error, skip it
129
+ if ( skipTokens . has ( token ) )
130
+ continue
131
+
112
132
const clone = { ...token }
113
133
Object . assign ( token , renderer . nodeStaticInfo . call ( this , info , clone ) )
114
134
}
115
135
116
- for ( const query of twoslash . queries ) {
117
- insertAfterLine (
118
- query . line ,
119
- query . kind === 'completions'
120
- ? renderer . lineCompletions . call ( this , query )
121
- : query . kind === 'query'
122
- ? renderer . lineQuery . call ( this , query , locateTextToken ( query . line - 1 , query . offset ) )
123
- : [ ] ,
124
- )
125
- }
126
-
127
136
for ( const tag of twoslash . tags )
128
137
insertAfterLine ( tag . line , renderer . lineCustomTag . call ( this , tag ) )
129
138
} ,
0 commit comments