From 3f9762e00302725e9863c568ca7081d590847979 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Wed, 19 Oct 2022 19:18:06 +0200 Subject: [PATCH] Handle the `DEFAULT` case for `matchVariant` (#635) * handle the `DEFAULT` case * Prettier Co-authored-by: Brad Cornes --- .../src/completionProvider.ts | 9 +++++++-- .../src/diagnostics/getInvalidVariantDiagnostics.ts | 4 +++- .../src/util/getVariantsFromClassName.ts | 4 +++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/tailwindcss-language-service/src/completionProvider.ts b/packages/tailwindcss-language-service/src/completionProvider.ts index 4b1ca1d..cc269c8 100644 --- a/packages/tailwindcss-language-service/src/completionProvider.ts +++ b/packages/tailwindcss-language-service/src/completionProvider.ts @@ -216,7 +216,10 @@ export function completionsFromClassList( .filter((value) => !existingVariants.includes(`${variant.name}-${value}`)) .map((value) => variantItem({ - label: `${variant.name}${variant.hasDash ? '-' : ''}${value}${sep}`, + label: + value === 'DEFAULT' + ? `${variant.name}${sep}` + : `${variant.name}${variant.hasDash ? '-' : ''}${value}${sep}`, detail: variant.selectors({ value }).join(', '), }) ) @@ -845,7 +848,9 @@ function provideVariantsDirectiveCompletions( let possibleVariants = state.variants.flatMap((variant) => { if (variant.values.length) { - return variant.values.map((value) => `${variant.name}${variant.hasDash ? '-' : ''}${value}`) + return variant.values.map((value) => + value === 'DEFAULT' ? variant.name : `${variant.name}${variant.hasDash ? '-' : ''}${value}` + ) } return [variant.name] }) diff --git a/packages/tailwindcss-language-service/src/diagnostics/getInvalidVariantDiagnostics.ts b/packages/tailwindcss-language-service/src/diagnostics/getInvalidVariantDiagnostics.ts index 454e0f5..1f2a46e 100644 --- a/packages/tailwindcss-language-service/src/diagnostics/getInvalidVariantDiagnostics.ts +++ b/packages/tailwindcss-language-service/src/diagnostics/getInvalidVariantDiagnostics.ts @@ -34,7 +34,9 @@ export function getInvalidVariantDiagnostics( let possibleVariants = state.variants.flatMap((variant) => { if (variant.values.length) { - return variant.values.map((value) => `${variant.name}${variant.hasDash ? '-' : ''}${value}`) + return variant.values.map((value) => + value === 'DEFAULT' ? variant.name : `${variant.name}${variant.hasDash ? '-' : ''}${value}` + ) } return [variant.name] }) diff --git a/packages/tailwindcss-language-service/src/util/getVariantsFromClassName.ts b/packages/tailwindcss-language-service/src/util/getVariantsFromClassName.ts index b1709e1..e83e65a 100644 --- a/packages/tailwindcss-language-service/src/util/getVariantsFromClassName.ts +++ b/packages/tailwindcss-language-service/src/util/getVariantsFromClassName.ts @@ -7,7 +7,9 @@ export function getVariantsFromClassName( ): { variants: string[]; offset: number } { let allVariants = state.variants.flatMap((variant) => { if (variant.values.length) { - return variant.values.map((value) => `${variant.name}${variant.hasDash ? '-' : ''}${value}`) + return variant.values.map((value) => + value === 'DEFAULT' ? variant.name : `${variant.name}${variant.hasDash ? '-' : ''}${value}` + ) } return [variant.name] })