Skip to content

Commit b0e4fad

Browse files
authored
Tweak theme helper detection (tailwindlabs#689)
1 parent 3beff14 commit b0e4fad

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/tailwindcss-language-service/src/completionProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ function provideCssHelperCompletions(
614614

615615
const match = text
616616
.substr(0, text.length - 1) // don't include that extra character from earlier
617-
.match(/\b(?<helper>config|theme)\(\s*['"]?(?<path>[^)'"]*)$/)
617+
.match(/[\s:;/*(){}](?<helper>config|theme)\(\s*['"]?(?<path>[^)'"]*)$/)
618618

619619
if (match === null) {
620620
return null

packages/tailwindcss-language-service/src/util/find.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,10 @@ export function findHelperFunctionsInRange(
350350
range?: Range
351351
): DocumentHelperFunction[] {
352352
const text = getTextWithoutComments(doc, 'css', range)
353-
let matches = findAll(/\b(?<helper>config|theme)(?<innerPrefix>\(\s*)(?<path>[^)]*?)\s*\)/g, text)
353+
let matches = findAll(
354+
/(?<prefix>[\s:;/*(){}])(?<helper>config|theme)(?<innerPrefix>\(\s*)(?<path>[^)]*?)\s*\)/g,
355+
text
356+
)
354357

355358
return matches.map((match) => {
356359
let quotesBefore = ''
@@ -364,7 +367,11 @@ export function findHelperFunctionsInRange(
364367
}
365368
path = path.replace(/['"]*\s*$/, '')
366369

367-
let startIndex = match.index + match.groups.helper.length + match.groups.innerPrefix.length
370+
let startIndex =
371+
match.index +
372+
match.groups.prefix.length +
373+
match.groups.helper.length +
374+
match.groups.innerPrefix.length
368375

369376
return {
370377
helper: match.groups.helper === 'theme' ? 'theme' : 'config',

0 commit comments

Comments
 (0)