Skip to content
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

Add modifier completions for @apply and classRegex configs #732

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Changes from all commits
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
33 changes: 20 additions & 13 deletions packages/tailwindcss-language-service/src/completionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export function completionsFromClassList(
classList: string,
classListRange: Range,
filter?: (item: CompletionItem) => boolean,
document?: TextDocument,
context?: CompletionContext
): CompletionList {
let classNames = classList.split(/[\s+]/)
Expand Down Expand Up @@ -464,7 +463,6 @@ async function provideClassAttributeCompletions(
end: position,
},
undefined,
document,
context
)
}
Expand All @@ -476,7 +474,8 @@ async function provideClassAttributeCompletions(
async function provideCustomClassNameCompletions(
state: State,
document: TextDocument,
position: Position
position: Position,
context?: CompletionContext
): Promise<CompletionList> {
const settings = await state.editor.getConfiguration(document.uri)
const regexes = settings.tailwindCSS.experimental.classRegex
Expand Down Expand Up @@ -527,13 +526,19 @@ async function provideCustomClassNameCompletions(
classList = containerMatch[1].substr(0, cursor - matchStart)
}

return completionsFromClassList(state, classList, {
start: {
line: position.line,
character: position.character - classList.length,
return completionsFromClassList(
state,
classList,
{
start: {
line: position.line,
character: position.character - classList.length,
},
end: position,
},
end: position,
})
undefined,
context
)
}
}
} catch (_) {}
Expand All @@ -545,7 +550,8 @@ async function provideCustomClassNameCompletions(
function provideAtApplyCompletions(
state: State,
document: TextDocument,
position: Position
position: Position,
context?: CompletionContext
): CompletionList {
let str = document.getText({
start: { line: Math.max(position.line - 30, 0), character: 0 },
Expand Down Expand Up @@ -580,7 +586,8 @@ function provideAtApplyCompletions(
let className = item.data?.className ?? item.label
let validated = validateApply(state, [...variants, className])
return validated !== null && validated.isApplyable === true
}
},
context
)
}

Expand All @@ -596,7 +603,7 @@ async function provideClassNameCompletions(
context?: CompletionContext
): Promise<CompletionList> {
if (isCssContext(state, document, position)) {
return provideAtApplyCompletions(state, document, position)
return provideAtApplyCompletions(state, document, position, context)
}

if (isHtmlContext(state, document, position) || isJsxContext(state, document, position)) {
Expand Down Expand Up @@ -1329,7 +1336,7 @@ export async function doComplete(
provideTailwindDirectiveCompletions(state, document, position) ||
provideLayerDirectiveCompletions(state, document, position) ||
(await provideConfigDirectiveCompletions(state, document, position)) ||
(await provideCustomClassNameCompletions(state, document, position))
(await provideCustomClassNameCompletions(state, document, position, context))

if (result) return result

Expand Down