diff --git a/packages/tailwindcss-language-service/src/util/find.test.ts b/packages/tailwindcss-language-service/src/util/find.test.ts index da6ac60d..77414250 100644 --- a/packages/tailwindcss-language-service/src/util/find.test.ts +++ b/packages/tailwindcss-language-service/src/util/find.test.ts @@ -1156,3 +1156,37 @@ test('classFunctions are detected inside of arrays in javascript just after open }, ]) }) + +test("--theme's inline helper is not considered part of the path", async ({ expect }) => { + let file = createDocument({ + name: 'file.css', + lang: 'css', + settings: { + tailwindCSS: { + classFunctions: ['clsx'], + }, + }, + content: ` + .a { color: --theme(--my-color inline); } + .a { color: theme(--my-color inline); } + `, + }) + + let fns = findHelperFunctionsInDocument(file.state, file.doc) + + expect(fns).toEqual([ + { + helper: 'theme', + path: '--my-color', + ranges: { full: range(1, 26, 1, 43), path: range(1, 26, 1, 36) }, + }, + + // This is on purpose: + // The `theme()` function doesn't have an inline option only `--theme()`. + { + helper: 'theme', + path: '--my-color inline', + ranges: { full: range(2, 24, 2, 41), path: range(2, 24, 2, 41) }, + }, + ]) +}) diff --git a/packages/tailwindcss-language-service/src/util/find.ts b/packages/tailwindcss-language-service/src/util/find.ts index 1b39be69..1bd51cfa 100644 --- a/packages/tailwindcss-language-service/src/util/find.ts +++ b/packages/tailwindcss-language-service/src/util/find.ts @@ -557,6 +557,15 @@ export function findHelperFunctionsInRange( // Re-slice path = text.slice(pathStart, pathEnd) + // The `--theme(…)` function has an optional `inline` modifier that can appear at the end + // NOTE: The non-dashed `theme(…)` function does not have this + // + // TODO: We should validate that this modifier is `inline` and issue a diagnostic if its not + if (path.endsWith(' inline') && match.groups.helper === '--theme') { + path = path.slice(0, -7) + pathEnd -= 7 + } + fns.push({ helper, path, diff --git a/packages/vscode-tailwindcss/CHANGELOG.md b/packages/vscode-tailwindcss/CHANGELOG.md index 537c948f..0908dd7e 100644 --- a/packages/vscode-tailwindcss/CHANGELOG.md +++ b/packages/vscode-tailwindcss/CHANGELOG.md @@ -5,6 +5,7 @@ - Publish our fork of the CSS language server ([#1437](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1437)) - Suggest default variant values when they also support arbitrary values ([#1439](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1439)) - Show color swatches for OKLCH colors with units in all positions ([#1442](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1442)) +- Fix incorrect diagnostic for `--theme(--some-var inline)` ([#1443](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1443)) ## 0.14.26