Exclude classes in `blocklist` from IntelliSense (#746)

master
Brad Cornes 2023-03-27 18:56:02 +01:00 committed by GitHub
parent 7978a2eb28
commit db61c8891b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 15 deletions

View File

@ -1016,6 +1016,8 @@ async function createProjectService(
try { try {
state.config = resolveConfig.module(originalConfig) state.config = resolveConfig.module(originalConfig)
state.separator = state.config.separator state.separator = state.config.separator
state.blocklist = Array.isArray(state.config.blocklist) ? state.config.blocklist : []
delete state.config.blocklist
if (state.jit) { if (state.jit) {
state.jitContext = state.modules.jit.createContext.module(state) state.jitContext = state.modules.jit.createContext.module(state)

View File

@ -242,7 +242,13 @@ export function completionsFromClassList(
{ {
isIncomplete: false, isIncomplete: false,
items: items.concat( items: items.concat(
state.classList.map(([className, { color }], index) => { state.classList.reduce<CompletionItem[]>((items, [className, { color }], index) => {
if (
state.blocklist?.includes([...existingVariants, className].join(state.separator))
) {
return items
}
let kind: CompletionItemKind = color ? 16 : 21 let kind: CompletionItemKind = color ? 16 : 21
let documentation: string | undefined let documentation: string | undefined
@ -250,13 +256,15 @@ export function completionsFromClassList(
documentation = culori.formatRgb(color) documentation = culori.formatRgb(color)
} }
return { items.push({
label: className, label: className,
kind, kind,
...(documentation ? { documentation } : {}), ...(documentation ? { documentation } : {}),
sortText: naturalExpand(index, state.classList.length), sortText: naturalExpand(index, state.classList.length),
} as CompletionItem })
})
return items
}, [] as CompletionItem[])
), ),
}, },
{ {

View File

@ -20,7 +20,7 @@ export async function getCssConflictDiagnostics(
const classLists = await findClassListsInDocument(state, document) const classLists = await findClassListsInDocument(state, document)
classLists.forEach((classList) => { classLists.forEach((classList) => {
const classNames = getClassNamesInClassList(classList) const classNames = getClassNamesInClassList(classList, state.blocklist)
classNames.forEach((className, index) => { classNames.forEach((className, index) => {
if (state.jit) { if (state.jit) {

View File

@ -23,7 +23,7 @@ export async function getRecommendedVariantOrderDiagnostics(
const classLists = await findClassListsInDocument(state, document) const classLists = await findClassListsInDocument(state, document)
classLists.forEach((classList) => { classLists.forEach((classList) => {
const classNames = getClassNamesInClassList(classList) const classNames = getClassNamesInClassList(classList, state.blocklist)
classNames.forEach((className) => { classNames.forEach((className) => {
let { rules } = jit.generateRules(state, [className.className]) let { rules } = jit.generateRules(state, [className.className])
if (rules.length === 0) { if (rules.length === 0) {

View File

@ -22,7 +22,7 @@ export async function getDocumentColors(
let classLists = await findClassListsInDocument(state, document) let classLists = await findClassListsInDocument(state, document)
classLists.forEach((classList) => { classLists.forEach((classList) => {
let classNames = getClassNamesInClassList(classList) let classNames = getClassNamesInClassList(classList, state.blocklist)
classNames.forEach((className) => { classNames.forEach((className) => {
let color = getColor(state, className.className) let color = getColor(state, className.className)
if (color === null || typeof color === 'string' || (color.alpha ?? 1) === 0) { if (color === null || typeof color === 'string' || (color.alpha ?? 1) === 0) {

View File

@ -29,16 +29,15 @@ export function findLast(re: RegExp, str: string): RegExpMatchArray {
return matches[matches.length - 1] return matches[matches.length - 1]
} }
export function getClassNamesInClassList({ export function getClassNamesInClassList(
classList, { classList, range, important }: DocumentClassList,
range, blocklist: State['blocklist']
important, ): DocumentClassName[] {
}: DocumentClassList): DocumentClassName[] {
const parts = classList.split(/(\s+)/) const parts = classList.split(/(\s+)/)
const names: DocumentClassName[] = [] const names: DocumentClassName[] = []
let index = 0 let index = 0
for (let i = 0; i < parts.length; i++) { for (let i = 0; i < parts.length; i++) {
if (i % 2 === 0) { if (i % 2 === 0 && !blocklist.includes(parts[i])) {
const start = indexToPosition(classList, index) const start = indexToPosition(classList, index)
const end = indexToPosition(classList, index + parts[i].length) const end = indexToPosition(classList, index + parts[i].length)
names.push({ names.push({
@ -77,7 +76,9 @@ export async function findClassNamesInRange(
includeCustom: boolean = true includeCustom: boolean = true
): Promise<DocumentClassName[]> { ): Promise<DocumentClassName[]> {
const classLists = await findClassListsInRange(state, doc, range, mode, includeCustom) const classLists = await findClassListsInRange(state, doc, range, mode, includeCustom)
return flatten(classLists.map(getClassNamesInClassList)) return flatten(
classLists.map((classList) => getClassNamesInClassList(classList, state.blocklist))
)
} }
export async function findClassNamesInDocument( export async function findClassNamesInDocument(
@ -85,7 +86,9 @@ export async function findClassNamesInDocument(
doc: TextDocument doc: TextDocument
): Promise<DocumentClassName[]> { ): Promise<DocumentClassName[]> {
const classLists = await findClassListsInDocument(state, doc) const classLists = await findClassListsInDocument(state, doc)
return flatten(classLists.map(getClassNamesInClassList)) return flatten(
classLists.map((classList) => getClassNamesInClassList(classList, state.blocklist))
)
} }
export function findClassListsInCssRange(doc: TextDocument, range?: Range): DocumentClassList[] { export function findClassListsInCssRange(doc: TextDocument, range?: Range): DocumentClassList[] {

View File

@ -99,6 +99,7 @@ export interface State {
screens?: string[] screens?: string[]
variants?: Variant[] variants?: Variant[]
corePlugins?: string[] corePlugins?: string[]
blocklist?: unknown[]
modules?: { modules?: {
tailwindcss?: { version: string; module: any } tailwindcss?: { version: string; module: any }
postcss?: { version: string; module: Postcss } postcss?: { version: string; module: Postcss }