Tweak `theme` helper detection (#689)

master
Brad Cornes 2023-01-04 10:34:41 +00:00 committed by GitHub
parent 3beff1474a
commit b0e4fadc4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -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

View File

@ -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 = ''
@ -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',