Skip to content

Commit 3d9db7b

Browse files
committed
wip
1 parent cf48ebc commit 3d9db7b

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

packages/tailwindcss-language-service/src/diagnostics/getDeprecatedClassDiagnostics.ts

+41-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { State, Settings } from '../util/state'
2-
import { type DeprecatedClassDiagnostic } from './types'
2+
import { type DeprecatedClassDiagnostic, DiagnosticKind } from './types'
3+
import { findClassListsInDocument, getClassNamesInClassList } from '../util/find'
34
import type { TextDocument } from 'vscode-languageserver-textdocument'
45

56
export async function getDeprecatedClassDiagnostics(
@@ -16,7 +17,46 @@ export async function getDeprecatedClassDiagnostics(
1617
let severity = settings.tailwindCSS.lint.deprecatedClass
1718
if (severity === 'ignore') return []
1819

20+
// Fill in the list of statically known deprecated classes
21+
let deprecations = new Map<string, boolean>(
22+
state.classList.map(([className, meta]) => [className, meta.deprecated ?? false]),
23+
)
24+
25+
function isDeprecated(className: string) {
26+
if (deprecations.has(className)) {
27+
return deprecations.get(className)
28+
}
29+
30+
let metadata = state.designSystem.classMetadata([className])[0]
31+
let deprecated = metadata?.deprecated ?? false
32+
33+
deprecations.set(className, deprecated)
34+
35+
return deprecated
36+
}
37+
1938
let diagnostics: DeprecatedClassDiagnostic[] = []
39+
let classLists = await findClassListsInDocument(state, document)
40+
41+
for (let classList of classLists) {
42+
let classNames = getClassNamesInClassList(classList, state.blocklist)
43+
44+
for (let className of classNames) {
45+
if (!isDeprecated(className.className)) continue
46+
47+
diagnostics.push({
48+
code: DiagnosticKind.DeprecatedClass,
49+
className,
50+
range: className.range,
51+
severity:
52+
severity === 'error'
53+
? 1 /* DiagnosticSeverity.Error */
54+
: 2 /* DiagnosticSeverity.Warning */,
55+
message: `'${className.className}' is deprecated.`,
56+
suggestions: [],
57+
})
58+
}
59+
}
2060

2161
return diagnostics
2262
}

packages/tailwindcss-language-service/src/util/state.ts

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export interface Variant {
9393
export interface ClassMetadata {
9494
color: culori.Color | KeywordColor | null
9595
modifiers?: string[]
96+
deprecated?: boolean
9697
}
9798

9899
export type ClassEntry = [string, ClassMetadata]

packages/tailwindcss-language-service/src/util/v4/design-system.ts

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export interface Theme {
1010

1111
export interface ClassMetadata {
1212
modifiers: string[]
13+
deprecated?: boolean
14+
}
15+
16+
export interface VariantMetadata {
17+
deprecated?: boolean
1318
}
1419

1520
export type ClassEntry = [string, ClassMetadata]
@@ -40,6 +45,8 @@ export interface DesignSystem {
4045

4146
// Optional because it did not exist in earlier v4 alpha versions
4247
resolveThemeValue?(path: string): string | undefined
48+
classMetadata?(classes: string[]): (ClassMetadata | null)[]
49+
variantMetadata?(variants: string[]): (VariantMetadata | null)[]
4350
}
4451

4552
export interface DesignSystem {

packages/vscode-tailwindcss/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Show source diagnostics when imports contain a layer ([#1204](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1204))
88
- Only detect project roots in v4 when using certain CSS features ([#1205](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1205))
99
- Update Tailwind CSS v4 version to v4.0.6 ([#1207](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1207))
10+
- Add support for detecting deprecated classes ([#1084](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1084))
1011

1112
## 0.14.4
1213

0 commit comments

Comments
 (0)