Skip to content

Commit c080688

Browse files
Simplify details for utility completions (#1356)
Fixes #1347 This PR addresses two problems (see screenshots below): 1. Utilities that generate `@property` rules will include the declarations from `@property` in the completion details. 2. Custom variants that include declarations will include those declarations in the completion details. To fix these we are now: 1. Generating details using the "base" utility 2. Dropping any uses of `@property` before calculating the list of declarations **Before** <img width="1197" alt="Screenshot 2025-05-09 at 18 08 57" src="https://github.com/user-attachments/assets/59193060-7cc7-4d25-ae69-fd60be2899c6" /> <img width="1078" alt="Screenshot 2025-05-09 at 18 10 12" src="https://github.com/user-attachments/assets/b1e97530-cfd0-44db-9bb1-5b7392eacdc6" /> **After** <img width="1031" alt="Screenshot 2025-05-09 at 18 11 36" src="https://github.com/user-attachments/assets/96405f6e-9e5c-4c6e-a123-b0a42d088521" /> <img width="1174" alt="Screenshot 2025-05-09 at 18 12 46" src="https://github.com/user-attachments/assets/d4a8a9c0-4735-4976-a57a-32f720edfb36" /> Note that the "documentation" portion of completion items is unchanged and shows the full candidate with all the CSS included (for non-color utilities): <img width="1075" alt="Screenshot 2025-05-09 at 18 14 53" src="https://github.com/user-attachments/assets/5e67090d-faea-4de1-9eab-8ee9709b123e" />
1 parent e2cfc2c commit c080688

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

packages/tailwindcss-language-service/src/completionProvider.ts

+20-7
Original file line numberDiff line numberDiff line change
@@ -2280,24 +2280,37 @@ export async function resolveCompletionItem(
22802280
if (state.v4) {
22812281
if (item.kind === 9) return item
22822282
if (item.detail && item.documentation) return item
2283+
2284+
let base = state.designSystem.compile([className])[0]
22832285
let root = state.designSystem.compile([[...variants, className].join(state.separator)])[0]
2286+
22842287
let rules = root.nodes.filter((node) => node.type === 'rule')
22852288
if (rules.length === 0) return item
22862289

22872290
if (!item.detail) {
22882291
if (rules.length === 1) {
22892292
let decls: postcss.Declaration[] = []
22902293

2291-
root.walkDecls((node) => {
2294+
// Remove any `@property` rules
2295+
base = base.clone()
2296+
base.walkAtRules((rule) => {
2297+
// Ignore declarations inside `@property` rules
2298+
if (rule.name === 'property') {
2299+
rule.remove()
2300+
}
2301+
2302+
// Ignore declarations @supports (-moz-orient: inline)
2303+
// this is a hack used for `@property` fallbacks in Firefox
2304+
if (rule.name === 'supports' && rule.params === '(-moz-orient: inline)') {
2305+
rule.remove()
2306+
}
2307+
})
2308+
2309+
base.walkDecls((node) => {
22922310
decls.push(node)
22932311
})
22942312

2295-
item.detail = await jit.stringifyDecls(
2296-
state,
2297-
postcss.rule({
2298-
nodes: decls,
2299-
}),
2300-
)
2313+
item.detail = await jit.stringifyDecls(state, postcss.rule({ nodes: decls }))
23012314
} else {
23022315
item.detail = `${rules.length} rules`
23032316
}

packages/vscode-tailwindcss/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
- Fix error when using VSCode < 1.78 ([#1353](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1353))
1212
- Don’t skip suggesting empty variant implementations ([#1352](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1352))
1313
- Handle helper function lookups in nested parens ([#1354](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1354))
14+
- Hide `@property` declarations from completion details ([#1356](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1356))
15+
- Hide variant-provided declarations from completion details for a utility ([#1356](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1356))
1416

1517
# 0.14.16
1618

0 commit comments

Comments
 (0)