Skip to content

Commit 2aa39c8

Browse files
committed
Skip @apply validation if applyComplexClasses flag is enabled
1 parent 81446ac commit 2aa39c8

File tree

6 files changed

+41
-10
lines changed

6 files changed

+41
-10
lines changed

src/class-names/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export default async function getClassNames(
4747
let tailwindcss
4848
let browserslistModule
4949
let version
50+
let featureFlags = { future: [], experimental: [] }
5051

5152
const configPaths = (
5253
await glob(CONFIG_GLOB, {
@@ -75,6 +76,10 @@ export default async function getClassNames(
7576
browserslistModule = importFrom(tailwindBase, 'browserslist')
7677
} catch (_) {}
7778

79+
try {
80+
featureFlags = importFrom(tailwindBase, './lib/featureFlags.js').default
81+
} catch (_) {}
82+
7883
const sepLocation = semver.gte(version, '0.99.0')
7984
? ['separator']
8085
: ['options', 'separator']
@@ -152,6 +157,7 @@ export default async function getClassNames(
152157
tailwindcss,
153158
postcss,
154159
},
160+
featureFlags,
155161
}
156162
}
157163

src/lsp/providers/completionProvider.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import {
2828
getClassAttributeLexer,
2929
getComputedClassAttributeLexer,
3030
} from '../util/lexers'
31+
import { validateApply } from '../util/validateApply'
32+
import { flagEnabled } from '../util/flagEnabled'
3133

3234
function completionsFromClassList(
3335
state: State,
@@ -193,16 +195,11 @@ function provideAtApplyCompletions(
193195
end: position,
194196
},
195197
(item) => {
196-
// TODO: first line excludes all subtrees but there could _technically_ be
197-
// valid apply-able class names in there. Will be correct in 99% of cases
198-
if (item.kind === CompletionItemKind.Module) return false
199-
let info = dlv(state.classNames.classNames, item.data)
200-
return (
201-
!Array.isArray(info) &&
202-
info.__source === 'utilities' &&
203-
info.__context.length === 0 &&
204-
info.__pseudo.length === 0
205-
)
198+
if (item.kind === CompletionItemKind.Module) {
199+
return flagEnabled(state, 'applyComplexClasses')
200+
}
201+
let validated = validateApply(state, item.data)
202+
return validated !== null && validated.isApplyable === true
206203
}
207204
)
208205
}

src/lsp/providers/diagnostics/getInvalidApplyDiagnostics.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { InvalidApplyDiagnostic, DiagnosticKind } from './types'
33
import { Settings, State } from '../../util/state'
44
import { TextDocument, DiagnosticSeverity } from 'vscode-languageserver'
55
import { validateApply } from '../../util/validateApply'
6+
import { flagEnabled } from '../../util/flagEnabled'
67

78
export function getInvalidApplyDiagnostics(
89
state: State,
@@ -11,6 +12,7 @@ export function getInvalidApplyDiagnostics(
1112
): InvalidApplyDiagnostic[] {
1213
let severity = settings.lint.invalidApply
1314
if (severity === 'ignore') return []
15+
if (flagEnabled(state, 'applyComplexClasses')) return []
1416

1517
const classNames = findClassNamesInRange(document, undefined, 'css')
1618

src/lsp/util/flagEnabled.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { State } from './state'
2+
const dlv = require('dlv')
3+
4+
export function flagEnabled(state: State, flag: string) {
5+
if (state.featureFlags.future.includes(flag)) {
6+
return (
7+
state.config.future === 'all' ||
8+
dlv(state.config, ['future', flag], false)
9+
)
10+
}
11+
12+
if (state.featureFlags.experimental.includes(flag)) {
13+
return (
14+
state.config.experimental === 'all' ||
15+
dlv(state.config, ['experimental', flag], false)
16+
)
17+
}
18+
19+
return false
20+
}

src/lsp/util/state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export type State = null | {
5757
variants?: string[]
5858
classNames?: ClassNames
5959
dependencies?: string[]
60+
featureFlags?: { future: string[]; experimental: string[] }
6061
editor?: EditorState
6162
error?: Error
6263
}

src/lsp/util/validateApply.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { State } from './state'
22
import { getClassNameMeta } from './getClassNameMeta'
3+
import { flagEnabled } from './flagEnabled'
34

45
export function validateApply(
56
state: State,
@@ -8,6 +9,10 @@ export function validateApply(
89
const meta = getClassNameMeta(state, classNameOrParts)
910
if (!meta) return null
1011

12+
if (flagEnabled(state, 'applyComplexClasses')) {
13+
return { isApplyable: true }
14+
}
15+
1116
const className = Array.isArray(classNameOrParts)
1217
? classNameOrParts.join(state.separator)
1318
: classNameOrParts

0 commit comments

Comments
 (0)