Skip to content

Commit

Permalink
feat(autocomplete): read autocomplete config from shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 29, 2022
1 parent 20788c8 commit f88ef8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/autocomplete/src/create.ts
Expand Up @@ -169,6 +169,7 @@ export function createAutocomplete(uno: UnoGenerator) {
templates.push(
...uno.config.autocomplete.templates || [],
...uno.config.rulesDynamic.flatMap(i => toArray(i?.[2]?.autocomplete || [])),
...uno.config.shortcuts.flatMap(i => toArray(i?.[2]?.autocomplete || [])),
)
}

Expand Down
11 changes: 11 additions & 0 deletions test/autocomplete.test.ts
Expand Up @@ -15,6 +15,7 @@ describe('autocomplete', () => {
'foo': 'text-red',
'foo-bar': 'text-red',
},
[/^bg-mode-(.+)$/, ([, mode]) => `bg-blend-${mode}`, { autocomplete: ['bg-mode-(color|normal)'] }],
],
})

Expand Down Expand Up @@ -162,6 +163,16 @@ describe('autocomplete', () => {
]
`)
})

it('should suggest shortcuts with autocomplete key', async () => {
expect(await ac.suggest('bg-mode-'))
.toMatchInlineSnapshot(`
[
"bg-mode-color",
"bg-mode-normal",
]
`)
})
})

describe('use uno cache', () => {
Expand Down

0 comments on commit f88ef8d

Please sign in to comment.