Skip to content

Commit

Permalink
Tweak theme helper detection (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradlc committed Jan 4, 2023
1 parent 3beff14 commit b0e4fad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ function provideCssHelperCompletions(

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

if (match === null) {
return null
Expand Down
11 changes: 9 additions & 2 deletions packages/tailwindcss-language-service/src/util/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ export function findHelperFunctionsInRange(
range?: Range
): DocumentHelperFunction[] {
const text = getTextWithoutComments(doc, 'css', range)
let matches = findAll(/\b(?<helper>config|theme)(?<innerPrefix>\(\s*)(?<path>[^)]*?)\s*\)/g, text)
let matches = findAll(
/(?<prefix>[\s:;/*(){}])(?<helper>config|theme)(?<innerPrefix>\(\s*)(?<path>[^)]*?)\s*\)/g,
text
)

return matches.map((match) => {
let quotesBefore = ''
Expand All @@ -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',
Expand Down

0 comments on commit b0e4fad

Please sign in to comment.