Fix `theme` helper handling when specifying default value (#747)

* Fix `theme` helper handling when specifying default value

* Tidy
master
Brad Cornes 2023-03-27 20:20:21 +01:00 committed by GitHub
parent db61c8891b
commit 6c2dbf7355
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 1 deletions

View File

@ -348,6 +348,22 @@ export function findHelperFunctionsInDocument(
) )
} }
function getFirstCommaIndex(str: string): number | null {
let quoteChar: string | undefined
for (let i = 0; i < str.length; i++) {
let char = str[i]
if (char === ',' && !quoteChar) {
return i
}
if (!quoteChar && (char === '"' || char === "'")) {
quoteChar = char
} else if (char === quoteChar) {
quoteChar = undefined
}
}
return null
}
export function findHelperFunctionsInRange( export function findHelperFunctionsInRange(
doc: TextDocument, doc: TextDocument,
range?: Range range?: Range
@ -360,7 +376,12 @@ export function findHelperFunctionsInRange(
return matches.map((match) => { return matches.map((match) => {
let quotesBefore = '' let quotesBefore = ''
let path = match.groups.path.replace(/['"]+$/, '').replace(/^['"]+/, (m) => { let path = match.groups.path
let commaIndex = getFirstCommaIndex(path)
if (commaIndex !== null) {
path = path.slice(0, commaIndex).trimEnd()
}
path = path.replace(/['"]+$/, '').replace(/^['"]+/, (m) => {
quotesBefore = m quotesBefore = m
return '' return ''
}) })