Skip to content

Commit 30df247

Browse files
Fix incorrect diagnostic for --theme(--some-var inline) (#1443)
Fixes #1440
1 parent 0ebb126 commit 30df247

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

packages/tailwindcss-language-service/src/util/find.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,3 +1156,37 @@ test('classFunctions are detected inside of arrays in javascript just after open
11561156
},
11571157
])
11581158
})
1159+
1160+
test("--theme's inline helper is not considered part of the path", async ({ expect }) => {
1161+
let file = createDocument({
1162+
name: 'file.css',
1163+
lang: 'css',
1164+
settings: {
1165+
tailwindCSS: {
1166+
classFunctions: ['clsx'],
1167+
},
1168+
},
1169+
content: `
1170+
.a { color: --theme(--my-color inline); }
1171+
.a { color: theme(--my-color inline); }
1172+
`,
1173+
})
1174+
1175+
let fns = findHelperFunctionsInDocument(file.state, file.doc)
1176+
1177+
expect(fns).toEqual([
1178+
{
1179+
helper: 'theme',
1180+
path: '--my-color',
1181+
ranges: { full: range(1, 26, 1, 43), path: range(1, 26, 1, 36) },
1182+
},
1183+
1184+
// This is on purpose:
1185+
// The `theme()` function doesn't have an inline option only `--theme()`.
1186+
{
1187+
helper: 'theme',
1188+
path: '--my-color inline',
1189+
ranges: { full: range(2, 24, 2, 41), path: range(2, 24, 2, 41) },
1190+
},
1191+
])
1192+
})

packages/tailwindcss-language-service/src/util/find.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,15 @@ export function findHelperFunctionsInRange(
557557
// Re-slice
558558
path = text.slice(pathStart, pathEnd)
559559

560+
// The `--theme(…)` function has an optional `inline` modifier that can appear at the end
561+
// NOTE: The non-dashed `theme(…)` function does not have this
562+
//
563+
// TODO: We should validate that this modifier is `inline` and issue a diagnostic if its not
564+
if (path.endsWith(' inline') && match.groups.helper === '--theme') {
565+
path = path.slice(0, -7)
566+
pathEnd -= 7
567+
}
568+
560569
fns.push({
561570
helper,
562571
path,

packages/vscode-tailwindcss/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Publish our fork of the CSS language server ([#1437](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1437))
66
- Suggest default variant values when they also support arbitrary values ([#1439](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1439))
77
- Show color swatches for OKLCH colors with units in all positions ([#1442](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1442))
8+
- Fix incorrect diagnostic for `--theme(--some-var inline)` ([#1443](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1443))
89

910
## 0.14.26
1011

0 commit comments

Comments
 (0)