Skip to content

Commit de461cb

Browse files
committed
track literal --value('…') and --modifier('…') values for suggestions
1 parent 523c74d commit de461cb

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

packages/tailwindcss/src/utilities.ts

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4739,7 +4739,10 @@ export function createCssUtility(node: AtRule) {
47394739

47404740
return (designSystem: DesignSystem) => {
47414741
let valueThemeKeys = new Set<`--${string}`>()
4742+
let valueLiterals = new Set<string>()
4743+
47424744
let modifierThemeKeys = new Set<`--${string}`>()
4745+
let modifierLiterals = new Set<string>()
47434746

47444747
// Pre-process the AST to make it easier to work with.
47454748
//
@@ -4791,9 +4794,25 @@ export function createCssUtility(node: AtRule) {
47914794
}
47924795
fn.nodes = ValueParser.parse(args.join(','))
47934796

4794-
// Track the theme keys for suggestions
4797+
// Track information for suggestions
47954798
for (let node of fn.nodes) {
4796-
if (node.kind === 'word' && node.value[0] === '-' && node.value[1] === '-') {
4799+
// Track literal values
4800+
if (
4801+
node.kind === 'word' &&
4802+
(node.value[0] === '"' || node.value[0] === "'") &&
4803+
node.value[0] === node.value[node.value.length - 1]
4804+
) {
4805+
let value = node.value.slice(1, -1)
4806+
4807+
if (fn.value === '--value') {
4808+
valueLiterals.add(value)
4809+
} else if (fn.value === '--modifier') {
4810+
modifierLiterals.add(value)
4811+
}
4812+
}
4813+
4814+
// Track theme keys
4815+
else if (node.kind === 'word' && node.value[0] === '-' && node.value[1] === '-') {
47974816
let value = node.value.replace(/-\*.*$/g, '') as `--${string}`
47984817

47994818
if (fn.value === '--value') {
@@ -4937,16 +4956,23 @@ export function createCssUtility(node: AtRule) {
49374956
})
49384957

49394958
designSystem.utilities.suggest(name.slice(0, -2), () => {
4940-
return [
4941-
{
4942-
values: designSystem.theme
4943-
.keysInNamespaces(valueThemeKeys)
4944-
.map((x) => x.replaceAll('_', '.')),
4945-
modifiers: designSystem.theme
4946-
.keysInNamespaces(modifierThemeKeys)
4947-
.map((x) => x.replaceAll('_', '.')),
4948-
},
4949-
] satisfies SuggestionGroup[]
4959+
let values = []
4960+
for (let value of valueLiterals) {
4961+
values.push(value)
4962+
}
4963+
for (let value of designSystem.theme.keysInNamespaces(valueThemeKeys)) {
4964+
values.push(value.replaceAll('_', '.'))
4965+
}
4966+
4967+
let modifiers = []
4968+
for (let modifier of modifierLiterals) {
4969+
modifiers.push(modifier)
4970+
}
4971+
for (let value of designSystem.theme.keysInNamespaces(modifierThemeKeys)) {
4972+
modifiers.push(value.replaceAll('_', '.'))
4973+
}
4974+
4975+
return [{ values, modifiers }] satisfies SuggestionGroup[]
49504976
})
49514977
}
49524978
}

0 commit comments

Comments
 (0)