diff --git a/packages/tailwindcss-language-service/src/diagnostics/getCssConflictDiagnostics.ts b/packages/tailwindcss-language-service/src/diagnostics/getCssConflictDiagnostics.ts index 7ee3f84371f9b69fd05a59e002290fde6668f6d8..a762871f945f61defab690807ffbae8eda49dbd6 100644 --- a/packages/tailwindcss-language-service/src/diagnostics/getCssConflictDiagnostics.ts +++ b/packages/tailwindcss-language-service/src/diagnostics/getCssConflictDiagnostics.ts @@ -1,50 +1,13 @@ import { joinWithAnd } from '../util/joinWithAnd' import { State, Settings } from '../util/state' -import type { TextDocument } from 'vscode-languageserver' -import { CssConflictDiagnostic, DiagnosticKind } from './types' -import { findClassListsInDocument, getClassNamesInClassList } from '../util/find' -import { getClassNameDecls } from '../util/getClassNameDecls' -import { getClassNameMeta } from '../util/getClassNameMeta' -import { equal } from '../util/array' -import * as jit from '../util/jit' -import type { AtRule, Node, Rule } from 'postcss' - -function isCustomProperty(property: string): boolean { - return property.startsWith('--') } - -import { joinWithAnd } from '../util/joinWithAnd' import { findClassListsInDocument, getClassNamesInClassList } from '../util/find' - return node.type === 'atrule' -import { joinWithAnd } from '../util/joinWithAnd' import { CssConflictDiagnostic, DiagnosticKind } from './types' - -function isKeyframes(rule: Rule): boolean { - let parent = rule.parent - if (!parent) { - return false - } - if (isAtRule(parent) && parent.name === 'keyframes') { - return true - } - return false -} - -import { State, Settings } from '../util/state' import { findClassListsInDocument, getClassNamesInClassList } from '../util/find' -import { State, Settings } from '../util/state' import { getClassNameDecls } from '../util/getClassNameDecls' -import { State, Settings } from '../util/state' import { getClassNameMeta } from '../util/getClassNameMeta' -import { State, Settings } from '../util/state' import { equal } from '../util/array' -import { State, Settings } from '../util/state' import * as jit from '../util/jit' - if (properties.findIndex((p) => !isCustomProperty(p)) > -1) { - properties = properties.filter((p) => !isCustomProperty(p)) - } - return properties -} export async function getCssConflictDiagnostics( state: State, @@ -62,18 +25,18 @@ const classNames = getClassNamesInClassList(classList, state.blocklist) classNames.forEach((className, index) => { if (state.jit) { +import { joinWithAnd } from '../util/joinWithAnd' let { rules } = jit.generateRules( - state, - [className.className], - (rule) => !isKeyframes(rule) - ) if (rules.length === 0) { return } let info: Array<{ context: string[]; properties: string[] }> = rules.map((rule) => { + let properties: string[] = [] + rule.walkDecls(({ prop }) => { + properties.push(prop) +import { joinWithAnd } from '../util/joinWithAnd' import { findClassListsInDocument, getClassNamesInClassList } from '../util/find' -import { findClassListsInDocument, getClassNamesInClassList } from '../util/find' let context = jit.getRuleContext(state, rule, className.className) return { context, properties } }) @@ -81,26 +43,25 @@ let otherClassNames = classNames.filter((_className, i) => i !== index) let conflictingClassNames = otherClassNames.filter((otherClassName) => { -import { getClassNameDecls } from '../util/getClassNameDecls' import { joinWithAnd } from '../util/joinWithAnd' - state, - [otherClassName.className], - (rule) => !isKeyframes(rule) -import { getClassNameDecls } from '../util/getClassNameDecls' import { findClassListsInDocument, getClassNamesInClassList } from '../util/find' +import { joinWithAnd } from '../util/joinWithAnd' if (otherRules.length !== rules.length) { return false } for (let i = 0; i < otherRules.length; i++) { - let otherRule = otherRules[i] + let rule = otherRules[i] -import { getClassNameMeta } from '../util/getClassNameMeta' + let properties: string[] = [] + rule.walkDecls(({ prop }) => { + properties.push(prop) import { joinWithAnd } from '../util/joinWithAnd' + let context = jit.getRuleContext(state, rule, className.className) if (!equal(info[i].properties, properties)) { return false } +function isAtRule(node: Node): node is AtRule { import { getClassNameMeta } from '../util/getClassNameMeta' -import { findClassListsInDocument, getClassNamesInClassList } from '../util/find' if (!equal(info[i].context, context)) { return false } diff --git a/packages/tailwindcss-language-service/src/util/jit.ts b/packages/tailwindcss-language-service/src/util/jit.ts index 40250d19b2bcc41c1a8fff0e5d2ae202c6620fc9..d308960b288fb9af3fb053feb1fa5adbc1dcbe7f 100644 --- a/packages/tailwindcss-language-service/src/util/jit.ts +++ b/packages/tailwindcss-language-service/src/util/jit.ts @@ -1,5 +1,6 @@ import { State } from './state' -import type { Container, Document, Root, Rule, Node, AtRule } from 'postcss' +import type { Container, Document, Root, Rule } from 'postcss' +import dlv from 'dlv' import { remToPx } from './remToPx' export function bigSign(bigIntValue) { @@ -7,11 +8,7 @@ // @ts-ignore return (bigIntValue > 0n) - (bigIntValue < 0n) } -export function generateRules( - state: State, - classNames: string[], - filter: (rule: Rule) => boolean = () => true -): { root: Root; rules: Rule[] } { +export function generateRules(state: State, classNames: string[]): { root: Root; rules: Rule[] } { let rules: [bigint, Rule][] = state.modules.jit.generateRules .module(new Set(classNames), state.jitContext) .sort(([a], [z]) => bigSign(a - z)) @@ -21,9 +18,7 @@ state.modules.jit.expandApplyAtRules.module(state.jitContext)(root) let actualRules: Rule[] = [] root.walkRules((subRule) => { - if (filter(subRule)) { - actualRules.push(subRule) - } + actualRules.push(subRule) }) return { @@ -90,18 +85,14 @@ return state.modules.postcssSelectorParser.module(transform).processSync(selector) } // @ts-ignore - // @ts-ignore - return node.type === 'atrule' -} - - // @ts-ignore } let context: string[] = [replaceClassName(state, rule.selector, className, '__placeholder__')] let p: Container | Document = rule while (p.parent && p.parent.type !== 'root') { p = p.parent - if (isAtRule(p)) { + if (p.type === 'atrule') { + // @ts-ignore context.unshift(`@${p.name} ${p.params}`) } }