From b0e4fadc4f14d017ede5500a00a6e34e98540be0 Mon Sep 17 00:00:00 2001 From: Brad Cornes Date: Wed, 4 Jan 2023 10:34:41 +0000 Subject: [PATCH] Tweak `theme` helper detection (#689) --- .../src/completionProvider.ts | 2 +- .../tailwindcss-language-service/src/util/find.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/tailwindcss-language-service/src/completionProvider.ts b/packages/tailwindcss-language-service/src/completionProvider.ts index d8bee18..63a5edf 100644 --- a/packages/tailwindcss-language-service/src/completionProvider.ts +++ b/packages/tailwindcss-language-service/src/completionProvider.ts @@ -614,7 +614,7 @@ function provideCssHelperCompletions( const match = text .substr(0, text.length - 1) // don't include that extra character from earlier - .match(/\b(?config|theme)\(\s*['"]?(?[^)'"]*)$/) + .match(/[\s:;/*(){}](?config|theme)\(\s*['"]?(?[^)'"]*)$/) if (match === null) { return null diff --git a/packages/tailwindcss-language-service/src/util/find.ts b/packages/tailwindcss-language-service/src/util/find.ts index 0283865..1977ef8 100644 --- a/packages/tailwindcss-language-service/src/util/find.ts +++ b/packages/tailwindcss-language-service/src/util/find.ts @@ -350,7 +350,10 @@ export function findHelperFunctionsInRange( range?: Range ): DocumentHelperFunction[] { const text = getTextWithoutComments(doc, 'css', range) - let matches = findAll(/\b(?config|theme)(?\(\s*)(?[^)]*?)\s*\)/g, text) + let matches = findAll( + /(?[\s:;/*(){}])(?config|theme)(?\(\s*)(?[^)]*?)\s*\)/g, + text + ) return matches.map((match) => { let quotesBefore = '' @@ -364,7 +367,11 @@ export function findHelperFunctionsInRange( } path = path.replace(/['"]*\s*$/, '') - let startIndex = match.index + match.groups.helper.length + match.groups.innerPrefix.length + let startIndex = + match.index + + match.groups.prefix.length + + match.groups.helper.length + + match.groups.innerPrefix.length return { helper: match.groups.helper === 'theme' ? 'theme' : 'config',