diff --git a/packages/tailwindcss-language-service/src/util/find.test.ts b/packages/tailwindcss-language-service/src/util/find.test.ts index bdc25fe6..fa35a389 100644 --- a/packages/tailwindcss-language-service/src/util/find.test.ts +++ b/packages/tailwindcss-language-service/src/util/find.test.ts @@ -1102,6 +1102,41 @@ test('Helper functions can start with --', async ({ expect }) => { ]) }) +test('Helper functions can span multiple lines', async ({ expect }) => { + let file = createDocument({ + name: 'file.css', + lang: 'css', + content: ` + .a { + color: theme( + 'colors.red.500' + ); + } + .b { + color: theme( + 'colors.red.500', + red + ); + } + `, + }) + + let fns = findHelperFunctionsInDocument(file.state, file.doc) + + expect(fns).toEqual([ + { + helper: 'theme', + path: 'colors.red.500', + ranges: { full: range(2, 21, 4, 8), path: range(3, 11, 3, 25) }, + }, + { + helper: 'theme', + path: 'colors.red.500', + ranges: { full: range(7, 21, 10, 8), path: range(8, 11, 8, 25) }, + }, + ]) +}) + test('Can find helper functions in SCSS', async ({ expect }) => { let file = createDocument({ name: 'file.scss', diff --git a/packages/tailwindcss-language-service/src/util/find.ts b/packages/tailwindcss-language-service/src/util/find.ts index f02fe493..e0ac2781 100644 --- a/packages/tailwindcss-language-service/src/util/find.ts +++ b/packages/tailwindcss-language-service/src/util/find.ts @@ -509,12 +509,12 @@ export function findHelperFunctionsInRange( let path = text.slice(pathStart, pathEnd) // Skip leading/trailing whitespace - pathStart += path.match(/^\s+/)?.length ?? 0 - pathEnd -= path.match(/\s+$/)?.length ?? 0 + pathStart += path.match(/^\s+/)?.[0].length ?? 0 + pathEnd -= path.match(/\s+$/)?.[0].length ?? 0 // Skip leading/trailing quotes - let quoteStart = path.match(/^['"]+/)?.length ?? 0 - let quoteEnd = path.match(/['"]+$/)?.length ?? 0 + let quoteStart = path.match(/^['"]+/)?.[0].length ?? 0 + let quoteEnd = path.match(/['"]+$/)?.[0].length ?? 0 if (quoteStart && quoteEnd) { pathStart += quoteStart @@ -542,15 +542,15 @@ export function findHelperFunctionsInRange( // Skip leading/trailing whitespace // // This can happen if we've clipped the path down to before the `/` - pathStart += path.match(/^\s+/)?.length ?? 0 - pathEnd -= path.match(/\s+$/)?.length ?? 0 + pathStart += path.match(/^\s+/)?.[0].length ?? 0 + pathEnd -= path.match(/\s+$/)?.[0].length ?? 0 // Re-slice path = text.slice(pathStart, pathEnd) // Skip leading/trailing quotes - quoteStart = path.match(/^['"]+/)?.length ?? 0 - quoteEnd = path.match(/['"]+$/)?.length ?? 0 + quoteStart = path.match(/^['"]+/)?.[0].length ?? 0 + quoteEnd = path.match(/['"]+$/)?.[0].length ?? 0 pathStart += quoteStart pathEnd -= quoteEnd diff --git a/packages/vscode-tailwindcss/CHANGELOG.md b/packages/vscode-tailwindcss/CHANGELOG.md index 8e9edb95..d7c39a8a 100644 --- a/packages/vscode-tailwindcss/CHANGELOG.md +++ b/packages/vscode-tailwindcss/CHANGELOG.md @@ -2,7 +2,7 @@ ## Prerelease -- Nothing yet! +- Fix incorrect `invalidConfigPath` warnings when a `theme(…)` or `config(…)` call spans multiple lines ([#1606](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1606)) ## 0.16.0