Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion packages/tailwindcss-language-service/src/util/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
doc: TextDocument,
range?: Range
Expand All @@ -360,7 +376,12 @@ export function findHelperFunctionsInRange(

return matches.map((match) => {
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
return ''
})
Expand Down