Skip to content

Commit 9ca3ceb

Browse files
committed
Update diagnostics and completions
1 parent d1af532 commit 9ca3ceb

File tree

3 files changed

+49
-28
lines changed

3 files changed

+49
-28
lines changed

packages/tailwindcss-language-service/src/completionProvider.ts

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,10 @@ function provideVariantsDirectiveCompletions(
711711
return null
712712
}
713713

714+
if (semver.gte(state.version, '2.99.0')) {
715+
return null
716+
}
717+
714718
let text = document.getText({
715719
start: { line: position.line, character: 0 },
716720
end: position,
@@ -862,32 +866,14 @@ function provideCssDirectiveCompletions(
862866
label: '@tailwind',
863867
documentation: {
864868
kind: 'markdown' as typeof MarkupKind.Markdown,
865-
value: `Use the \`@tailwind\` directive to insert Tailwind’s \`base\`, \`components\`, \`utilities\` and \`screens\` styles into your CSS.\n\n[Tailwind CSS Documentation](${docsUrl(
869+
value: `Use the \`@tailwind\` directive to insert Tailwind’s \`base\`, \`components\`, \`utilities\` and \`${
870+
state.jit && semver.gte(state.version, '2.1.99') ? 'variants' : 'screens'
871+
}\` styles into your CSS.\n\n[Tailwind CSS Documentation](${docsUrl(
866872
state.version,
867873
'functions-and-directives/#tailwind'
868874
)})`,
869875
},
870876
},
871-
{
872-
label: '@variants',
873-
documentation: {
874-
kind: 'markdown' as typeof MarkupKind.Markdown,
875-
value: `You can generate \`responsive\`, \`hover\`, \`focus\`, \`active\`, and \`group-hover\` versions of your own utilities by wrapping their definitions in the \`@variants\` directive.\n\n[Tailwind CSS Documentation](${docsUrl(
876-
state.version,
877-
'functions-and-directives/#variants'
878-
)})`,
879-
},
880-
},
881-
{
882-
label: '@responsive',
883-
documentation: {
884-
kind: 'markdown' as typeof MarkupKind.Markdown,
885-
value: `You can generate responsive variants of your own classes by wrapping their definitions in the \`@responsive\` directive.\n\n[Tailwind CSS Documentation](${docsUrl(
886-
state.version,
887-
'functions-and-directives/#responsive'
888-
)})`,
889-
},
890-
},
891877
{
892878
label: '@screen',
893879
documentation: {
@@ -922,6 +908,30 @@ function provideCssDirectiveCompletions(
922908
},
923909
]
924910
: []),
911+
...(semver.gte(state.version, '2.99.0')
912+
? []
913+
: [
914+
{
915+
label: '@variants',
916+
documentation: {
917+
kind: 'markdown' as typeof MarkupKind.Markdown,
918+
value: `You can generate \`responsive\`, \`hover\`, \`focus\`, \`active\`, and other variants of your own utilities by wrapping their definitions in the \`@variants\` directive.\n\n[Tailwind CSS Documentation](${docsUrl(
919+
state.version,
920+
'functions-and-directives/#variants'
921+
)})`,
922+
},
923+
},
924+
{
925+
label: '@responsive',
926+
documentation: {
927+
kind: 'markdown' as typeof MarkupKind.Markdown,
928+
value: `You can generate responsive variants of your own classes by wrapping their definitions in the \`@responsive\` directive.\n\n[Tailwind CSS Documentation](${docsUrl(
929+
state.version,
930+
'functions-and-directives/#responsive'
931+
)})`,
932+
},
933+
},
934+
]),
925935
]
926936

927937
return {

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,26 @@ export function getInvalidTailwindDirectiveDiagnostics(
2727
ranges.push(...boundaries.css)
2828
}
2929

30+
let hasVariantsDirective = state.jit && semver.gte(state.version, '2.1.99')
31+
3032
ranges.forEach((range) => {
3133
let text = document.getText(range)
3234
let matches = findAll(/(?:\s|^)@tailwind\s+(?<value>[^;]+)/g, text)
3335

3436
let valid = [
3537
'utilities',
3638
'components',
37-
state.jit && semver.gte(state.version, '2.1.99') ? 'variants' : 'screens',
39+
'screens',
3840
semver.gte(state.version, '1.0.0-beta.1') ? 'base' : 'preflight',
39-
]
41+
hasVariantsDirective && 'variants',
42+
].filter(Boolean)
43+
44+
let suggestable = valid
45+
46+
if (hasVariantsDirective) {
47+
// Don't suggest `screens`, because it's deprecated
48+
suggestable = suggestable.filter((value) => value !== 'screens')
49+
}
4050

4151
matches.forEach((match) => {
4252
if (valid.includes(match.groups.value)) {
@@ -49,11 +59,8 @@ export function getInvalidTailwindDirectiveDiagnostics(
4959
if (match.groups.value === 'preflight') {
5060
suggestions.push('base')
5161
message += ` Did you mean 'base'?`
52-
} else if (match.groups.value === 'screens') {
53-
suggestions.push('variants')
54-
message += ` Did you mean 'variants'?`
5562
} else {
56-
let suggestion = closest(match.groups.value, valid)
63+
let suggestion = closest(match.groups.value, suggestable)
5764
if (suggestion) {
5865
suggestions.push(suggestion)
5966
message += ` Did you mean '${suggestion}'?`

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getLanguageBoundaries } from '../util/getLanguageBoundaries'
66
import { findAll, indexToPosition } from '../util/find'
77
import { closest } from '../util/closest'
88
import { absoluteRange } from '../util/absoluteRange'
9-
import dlv from 'dlv'
9+
import semver from 'semver'
1010

1111
export function getInvalidVariantDiagnostics(
1212
state: State,
@@ -16,6 +16,10 @@ export function getInvalidVariantDiagnostics(
1616
let severity = settings.tailwindCSS.lint.invalidVariant
1717
if (severity === 'ignore') return []
1818

19+
if (semver.gte(state.version, '2.99.0')) {
20+
return []
21+
}
22+
1923
let diagnostics: InvalidVariantDiagnostic[] = []
2024
let ranges: Range[] = []
2125

0 commit comments

Comments
 (0)