Skip to content

Commit c1e9cc9

Browse files
jxomantfu
andauthored
fix(twoslash): completion on string quotes and literals (#99)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
1 parent bd12cae commit c1e9cc9

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ export function rendererRich(options: RendererRichOptions = {}): TwoslashRendere
204204
class: ['twoslash-completion-list', classExtra].filter(Boolean).join(' '),
205205
},
206206
children: query.completions!
207-
.filter(i => i.name.startsWith(query.completionsPrefix || '____'))
208207
.map(i => ({
209208
type: 'element',
210209
tagName: 'li',
@@ -236,7 +235,9 @@ export function rendererRich(options: RendererRichOptions = {}): TwoslashRendere
236235
children: [
237236
{
238237
type: 'text',
239-
value: query.completionsPrefix || '',
238+
value: i.name.startsWith(query.completionsPrefix)
239+
? query.completionsPrefix
240+
: '',
240241
},
241242
],
242243
},
@@ -247,7 +248,9 @@ export function rendererRich(options: RendererRichOptions = {}): TwoslashRendere
247248
children: [
248249
{
249250
type: 'text',
250-
value: i.name.slice(query.completionsPrefix?.length || 0),
251+
value: i.name.startsWith(query.completionsPrefix)
252+
? i.name.slice(query.completionsPrefix.length || 0)
253+
: i.name,
251254
},
252255
],
253256
},
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
11
// @noErrors
22
console.e
33
// ^|
4+
5+
6+
const a: { test: 'foo' | 'bar' | 'baz' } = {
7+
test: 'foo'
8+
}
9+
a.t
10+
// ^|
11+
12+
13+
a.test === '
14+
// ^|
15+
16+
17+
a.test === 'b
18+
// ^|
19+
20+
21+
a.test === 'bar'
22+
// ^|
23+
24+
25+
a.test === 'bar'
26+
// ^|

0 commit comments

Comments
 (0)