Skip to content

v4: Improve DX around completions when prefixes are in use #1292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 4, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Improve DX around completions when prefixes are in use
  • Loading branch information
thecrypticace committed Apr 3, 2025
commit d650a8cfc511c3b57df1026aa4255e27877a34c3
36 changes: 18 additions & 18 deletions packages/tailwindcss-language-service/src/completionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,29 +261,25 @@ export function completionsFromClassList(

// TODO: This is a bit of a hack
if (prefix.length > 0) {
// No variants seen: suggest the prefix only
// No variants seen:
// - suggest the prefix as a variant
// - Modify the remaining items to include the prefix in the variant name
if (existingVariants.length === 0) {
items = items.slice(0, 1)
items = items.map((item, idx) => {
if (idx === 0) return item

return withDefaults(
{
isIncomplete: false,
items,
},
{
data: {
...(state.completionItemData ?? {}),
...(important ? { important } : {}),
variants: existingVariants,
},
range: replacementRange,
},
state.editor.capabilities.itemDefaults,
)
item.label = `${prefix}:${item.label}`

if (item.textEditText) {
item.textEditText = `${prefix}:${item.textEditText}`
}

return item
})
}

// The first variant is not the prefix: don't suggest anything
if (existingVariants[0] !== prefix) {
if (existingVariants.length > 0 && existingVariants[0] !== prefix) {
return null
}
}
Expand All @@ -304,6 +300,10 @@ export function completionsFromClassList(
documentation = formatColor(color)
}

if (prefix.length > 0 && existingVariants.length === 0) {
className = `${prefix}:${className}`
}

items.push({
label: className,
kind,
Expand Down