Skip to content

Commit ca655f4

Browse files
committed
track literal --value('…') and --modifier('…') values for suggestions
1 parent a983de4 commit ca655f4

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

Diff for: packages/tailwindcss/src/utilities.ts

+38-12
Original file line numberDiff line numberDiff line change
@@ -4732,7 +4732,10 @@ export function createCssUtility(node: AtRule) {
47324732

47334733
return (designSystem: DesignSystem) => {
47344734
let valueThemeKeys = new Set<`--${string}`>()
4735+
let valueLiterals = new Set<string>()
4736+
47354737
let modifierThemeKeys = new Set<`--${string}`>()
4738+
let modifierLiterals = new Set<string>()
47364739

47374740
// Pre-process the AST to make it easier to work with.
47384741
//
@@ -4784,9 +4787,25 @@ export function createCssUtility(node: AtRule) {
47844787
}
47854788
fn.nodes = ValueParser.parse(args.join(','))
47864789

4787-
// Track the theme keys for suggestions
4790+
// Track information for suggestions
47884791
for (let node of fn.nodes) {
4789-
if (node.kind === 'word' && node.value[0] === '-' && node.value[1] === '-') {
4792+
// Track literal values
4793+
if (
4794+
node.kind === 'word' &&
4795+
(node.value[0] === '"' || node.value[0] === "'") &&
4796+
node.value[0] === node.value[node.value.length - 1]
4797+
) {
4798+
let value = node.value.slice(1, -1)
4799+
4800+
if (fn.value === '--value') {
4801+
valueLiterals.add(value)
4802+
} else if (fn.value === '--modifier') {
4803+
modifierLiterals.add(value)
4804+
}
4805+
}
4806+
4807+
// Track theme keys
4808+
else if (node.kind === 'word' && node.value[0] === '-' && node.value[1] === '-') {
47904809
let value = node.value.replace(/-\*.*$/g, '') as `--${string}`
47914810

47924811
if (fn.value === '--value') {
@@ -4930,16 +4949,23 @@ export function createCssUtility(node: AtRule) {
49304949
})
49314950

49324951
designSystem.utilities.suggest(name.slice(0, -2), () => {
4933-
return [
4934-
{
4935-
values: designSystem.theme
4936-
.keysInNamespaces(valueThemeKeys)
4937-
.map((x) => x.replaceAll('_', '.')),
4938-
modifiers: designSystem.theme
4939-
.keysInNamespaces(modifierThemeKeys)
4940-
.map((x) => x.replaceAll('_', '.')),
4941-
},
4942-
] satisfies SuggestionGroup[]
4952+
let values = []
4953+
for (let value of valueLiterals) {
4954+
values.push(value)
4955+
}
4956+
for (let value of designSystem.theme.keysInNamespaces(valueThemeKeys)) {
4957+
values.push(value.replaceAll('_', '.'))
4958+
}
4959+
4960+
let modifiers = []
4961+
for (let modifier of modifierLiterals) {
4962+
modifiers.push(modifier)
4963+
}
4964+
for (let value of designSystem.theme.keysInNamespaces(modifierThemeKeys)) {
4965+
modifiers.push(value.replaceAll('_', '.'))
4966+
}
4967+
4968+
return [{ values, modifiers }] satisfies SuggestionGroup[]
49434969
})
49444970
}
49454971
}

0 commit comments

Comments
 (0)