Skip to content

Commit 6978d59

Browse files
Update theme entry suggestions for the v4 beta (#1105)
We forgot to update these.
1 parent 805dfe1 commit 6978d59

File tree

3 files changed

+72
-42
lines changed

3 files changed

+72
-42
lines changed

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

+63-38
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { customClassesIn } from './util/classes'
4040
import { IS_SCRIPT_SOURCE, IS_TEMPLATE_SOURCE } from './metadata/extensions'
4141
import * as postcss from 'postcss'
4242
import { findFileDirective } from './completions/file-paths'
43+
import type { ThemeEntry } from './util/v4'
4344

4445
let isUtil = (className) =>
4546
Array.isArray(className.__info)
@@ -789,6 +790,8 @@ function provideThemeVariableCompletions(
789790
position: Position,
790791
_context?: CompletionContext,
791792
): CompletionList {
793+
if (!state.v4) return null
794+
792795
// Make sure we're in a CSS "context'
793796
if (!isCssContext(state, document, position)) return null
794797
let text = getTextWithoutComments(document, 'css', {
@@ -804,52 +807,74 @@ function provideThemeVariableCompletions(
804807
if (themeBlock === -1) return null
805808
if (braceLevel(text.slice(themeBlock)) !== 1) return null
806809

807-
function themeVar(label: string) {
808-
return {
809-
label,
810-
kind: CompletionItemKind.Variable,
811-
// insertTextFormat: InsertTextFormat.Snippet,
812-
// textEditText: `${label}-[\${1}]`,
813-
}
810+
let entries: ThemeEntry[] = [
811+
// Polyfill data for older versions of the design system
812+
{ kind: 'variable', name: '--default-transition-duration' },
813+
{ kind: 'variable', name: '--default-transition-timing-function' },
814+
{ kind: 'variable', name: '--default-font-family' },
815+
{ kind: 'variable', name: '--default-font-feature-settings' },
816+
{ kind: 'variable', name: '--default-font-variation-settings' },
817+
{ kind: 'variable', name: '--default-mono-font-family' },
818+
{ kind: 'variable', name: '--default-mono-font-feature-settings' },
819+
{ kind: 'variable', name: '--default-mono-font-variation-settings' },
820+
{ kind: 'namespace', name: '--breakpoint' },
821+
{ kind: 'namespace', name: '--color' },
822+
{ kind: 'namespace', name: '--animate' },
823+
{ kind: 'namespace', name: '--blur' },
824+
{ kind: 'namespace', name: '--radius' },
825+
{ kind: 'namespace', name: '--shadow' },
826+
{ kind: 'namespace', name: '--inset-shadow' },
827+
{ kind: 'namespace', name: '--drop-shadow' },
828+
{ kind: 'namespace', name: '--spacing' },
829+
{ kind: 'namespace', name: '--width' },
830+
{ kind: 'namespace', name: '--font-family' },
831+
{ kind: 'namespace', name: '--font-size' },
832+
{ kind: 'namespace', name: '--letter-spacing' },
833+
{ kind: 'namespace', name: '--line-height' },
834+
{ kind: 'namespace', name: '--transition-timing-function' },
835+
]
836+
837+
if (semver.gte(state.version, '4.0.0-beta.1')) {
838+
entries = [
839+
{ kind: 'variable', name: '--default-transition-duration' },
840+
{ kind: 'variable', name: '--default-transition-timing-function' },
841+
{ kind: 'variable', name: '--default-font-family' },
842+
{ kind: 'variable', name: '--default-font-feature-settings' },
843+
{ kind: 'variable', name: '--default-font-variation-settings' },
844+
{ kind: 'variable', name: '--default-mono-font-family' },
845+
{ kind: 'variable', name: '--default-mono-font-feature-settings' },
846+
{ kind: 'variable', name: '--default-mono-font-variation-settings' },
847+
{ kind: 'namespace', name: '--breakpoint' },
848+
{ kind: 'namespace', name: '--color' },
849+
{ kind: 'namespace', name: '--animate' },
850+
{ kind: 'namespace', name: '--blur' },
851+
{ kind: 'namespace', name: '--radius' },
852+
{ kind: 'namespace', name: '--shadow' },
853+
{ kind: 'namespace', name: '--inset-shadow' },
854+
{ kind: 'namespace', name: '--drop-shadow' },
855+
{ kind: 'variable', name: '--spacing' },
856+
{ kind: 'namespace', name: '--container' },
857+
{ kind: 'namespace', name: '--font' },
858+
{ kind: 'namespace', name: '--font-size' },
859+
{ kind: 'namespace', name: '--tracking' },
860+
{ kind: 'namespace', name: '--leading' },
861+
{ kind: 'namespace', name: '--ease' },
862+
]
814863
}
815864

816-
function themeNamespace(label: string) {
817-
return {
818-
label: `${label}-`,
865+
let items: CompletionItem[] = []
866+
867+
for (let entry of entries) {
868+
items.push({
869+
label: entry.kind === 'namespace' ? `${entry.name}-` : entry.name,
819870
kind: CompletionItemKind.Variable,
820-
// insertTextFormat: InsertTextFormat.Snippet,
821-
// textEditText: `${label}-[\${1}]`,
822-
}
871+
})
823872
}
824873

825874
return withDefaults(
826875
{
827876
isIncomplete: false,
828-
items: [
829-
themeVar('--default-transition-duration'),
830-
themeVar('--default-transition-timing-function'),
831-
themeVar('--default-font-family'),
832-
themeVar('--default-font-feature-settings'),
833-
themeVar('--default-font-variation-settings'),
834-
themeVar('--default-mono-font-family'),
835-
themeVar('--default-mono-font-feature-settings'),
836-
themeVar('--default-mono-font-variation-settings'),
837-
themeNamespace('--breakpoint'),
838-
themeNamespace('--color'),
839-
themeNamespace('--animate'),
840-
themeNamespace('--blur'),
841-
themeNamespace('--radius'),
842-
themeNamespace('--shadow'),
843-
themeNamespace('--inset-shadow'),
844-
themeNamespace('--drop-shadow'),
845-
themeNamespace('--spacing'),
846-
themeNamespace('--width'),
847-
themeNamespace('--font-family'),
848-
themeNamespace('--font-size'),
849-
themeNamespace('--letter-spacing'),
850-
themeNamespace('--line-height'),
851-
themeNamespace('--transition-timing-function'),
852-
],
877+
items,
853878
},
854879
{
855880
data: {

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export interface VariantEntry {
2424

2525
export type VariantFn = (rule: Rule, variant: NamedVariant) => null | void
2626

27+
export interface ThemeEntry {
28+
kind: 'namespace' | 'variable'
29+
name: string
30+
}
31+
2732
export interface DesignSystem {
2833
theme: Theme
2934
variants: Map<string, VariantFn>
@@ -32,12 +37,12 @@ export interface DesignSystem {
3237
getClassOrder(classes: string[]): [string, bigint | null][]
3338
getClassList(): ClassEntry[]
3439
getVariants(): VariantEntry[]
40+
41+
// Optional because it did not exist in earlier v4 alpha versions
42+
resolveThemeValue?(path: string): string | undefined
3543
}
3644

3745
export interface DesignSystem {
3846
compile(classes: string[]): postcss.Root[]
3947
toCss(nodes: postcss.Root | postcss.Node[]): string
40-
41-
// Optional because it did not exist in earlier v4 alpha versions
42-
resolveThemeValue?(path: string): string | undefined
4348
}

packages/vscode-tailwindcss/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Prerelease
44

5-
- Nothing yet
5+
- Update theme entry suggestions ([#1105](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1105))
66

77
## 0.12.15
88

0 commit comments

Comments
 (0)