Skip to content

Commit cd6c1d4

Browse files
WIPWIP V4 load custom @content
1 parent 7eab19f commit cd6c1d4

File tree

15 files changed

+319
-83
lines changed

15 files changed

+319
-83
lines changed

packages/tailwindcss-language-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@tailwindcss/forms": "0.5.3",
3737
"@tailwindcss/language-service": "workspace:*",
3838
"@tailwindcss/line-clamp": "0.4.2",
39-
"@tailwindcss/oxide": "^4.0.0-alpha.16",
39+
"@tailwindcss/oxide": "file:/Users/philipp/dev/tailwindcss/dist/tailwindcss-oxide.tgz",
4040
"@tailwindcss/typography": "0.5.7",
4141
"@types/color-name": "^1.1.3",
4242
"@types/culori": "^2.1.0",

packages/tailwindcss-language-server/src/project-locator.test.ts

Lines changed: 103 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -54,90 +54,116 @@ function testFixture(fixture: string, details: any[]) {
5454
})
5555
}
5656

57-
testFixture('basic', [
57+
// testFixture('basic', [
58+
// //
59+
// { config: 'tailwind.config.js' },
60+
// ])
61+
62+
// testFixture('dependencies', [
63+
// //
64+
// { config: 'tailwind.config.js' },
65+
// ])
66+
67+
// testFixture('multi-config', [
68+
// //
69+
// { config: 'one/tailwind.config.js' },
70+
// { config: 'two/tailwind.config.js' },
71+
// ])
72+
73+
// testFixture('multi-config-content', [
74+
// //
75+
// { config: 'tailwind.config.one.js' },
76+
// { config: 'tailwind.config.two.js' },
77+
// ])
78+
79+
// testFixture('v3/esm-config', [
80+
// //
81+
// { config: 'tailwind.config.mjs' },
82+
// ])
83+
84+
// testFixture('v3/ts-config', [
85+
// //
86+
// { config: 'tailwind.config.ts' },
87+
// ])
88+
89+
// testFixture('v4/basic', [
90+
// //
91+
// { config: 'app.css' },
92+
// ])
93+
94+
// testFixture('v4/multi-config', [
95+
// //
96+
// { config: 'admin/app.css' },
97+
// { config: 'web/app.css' },
98+
// ])
99+
100+
// testFixture('v4/workspaces', [
101+
// {
102+
// config: 'packages/admin/app.css',
103+
// selectors: [
104+
// '{URL}/node_modules/tailwindcss/**',
105+
// '{URL}/node_modules/tailwindcss/index.css',
106+
// '{URL}/node_modules/tailwindcss/theme.css',
107+
// '{URL}/node_modules/tailwindcss/utilities.css',
108+
// '{URL}/packages/admin/**',
109+
// '{URL}/packages/admin/app.css',
110+
// '{URL}/packages/admin/package.json',
111+
// ],
112+
// },
113+
// {
114+
// config: 'packages/web/app.css',
115+
// selectors: [
116+
// '{URL}/node_modules/tailwindcss/**',
117+
// '{URL}/node_modules/tailwindcss/index.css',
118+
// '{URL}/node_modules/tailwindcss/theme.css',
119+
// '{URL}/node_modules/tailwindcss/utilities.css',
120+
// '{URL}/packages/style-export/**',
121+
// '{URL}/packages/style-export/lib.css',
122+
// '{URL}/packages/style-export/theme.css',
123+
// '{URL}/packages/style-main-field/**',
124+
// '{URL}/packages/style-main-field/lib.css',
125+
// '{URL}/packages/web/**',
126+
// '{URL}/packages/web/app.css',
127+
// '{URL}/packages/web/package.json',
128+
// ],
129+
// },
130+
// ])
131+
132+
// testFixture('v4/auto-content', [
133+
// //
134+
// {
135+
// config: 'src/app.css',
136+
// content: [
137+
// '{URL}/package.json',
138+
// '{URL}/src/index.html',
139+
// '{URL}/src/components/example.html',
140+
// '{URL}/src/**/*.{py,tpl,js,vue,php,mjs,cts,jsx,tsx,rhtml,slim,handlebars,twig,rs,njk,svelte,liquid,pug,md,ts,heex,mts,astro,nunjucks,rb,eex,haml,cjs,html,hbs,jade,aspx,razor,erb,mustache,mdx}',
141+
// ],
142+
// },
143+
// ])
144+
145+
testFixture('v4/custom-content', [
58146
//
59-
{ config: 'tailwind.config.js' },
60-
])
61-
62-
testFixture('dependencies', [
63-
//
64-
{ config: 'tailwind.config.js' },
65-
])
66-
67-
testFixture('multi-config', [
68-
//
69-
{ config: 'one/tailwind.config.js' },
70-
{ config: 'two/tailwind.config.js' },
71-
])
72-
73-
testFixture('multi-config-content', [
74-
//
75-
{ config: 'tailwind.config.one.js' },
76-
{ config: 'tailwind.config.two.js' },
77-
])
78-
79-
testFixture('v3/esm-config', [
80-
//
81-
{ config: 'tailwind.config.mjs' },
82-
])
83-
84-
testFixture('v3/ts-config', [
85-
//
86-
{ config: 'tailwind.config.ts' },
87-
])
88-
89-
testFixture('v4/basic', [
90-
//
91-
{ config: 'app.css' },
92-
])
93-
94-
testFixture('v4/multi-config', [
95-
//
96-
{ config: 'admin/app.css' },
97-
{ config: 'web/app.css' },
98-
])
99-
100-
testFixture('v4/workspaces', [
101147
{
102-
config: 'packages/admin/app.css',
103-
selectors: [
104-
'{URL}/node_modules/tailwindcss/**',
105-
'{URL}/node_modules/tailwindcss/index.css',
106-
'{URL}/node_modules/tailwindcss/theme.css',
107-
'{URL}/node_modules/tailwindcss/utilities.css',
108-
'{URL}/packages/admin/**',
109-
'{URL}/packages/admin/app.css',
110-
'{URL}/packages/admin/package.json',
111-
],
112-
},
113-
{
114-
config: 'packages/web/app.css',
115-
selectors: [
116-
'{URL}/node_modules/tailwindcss/**',
117-
'{URL}/node_modules/tailwindcss/index.css',
118-
'{URL}/node_modules/tailwindcss/theme.css',
119-
'{URL}/node_modules/tailwindcss/utilities.css',
120-
'{URL}/packages/style-export/**',
121-
'{URL}/packages/style-export/lib.css',
122-
'{URL}/packages/style-export/theme.css',
123-
'{URL}/packages/style-main-field/**',
124-
'{URL}/packages/style-main-field/lib.css',
125-
'{URL}/packages/web/**',
126-
'{URL}/packages/web/app.css',
127-
'{URL}/packages/web/package.json',
148+
config: 'admin/app.css',
149+
content: [
150+
'{URL}/admin/**/*.{py,tpl,js,vue,php,mjs,cts,jsx,tsx,rhtml,slim,handlebars,twig,rs,njk,svelte,liquid,pug,md,ts,heex,mts,astro,nunjucks,rb,eex,haml,cjs,html,hbs,jade,aspx,razor,erb,mustache,mdx}',
151+
'{URL}/admin/**/*.bin',
152+
'{URL}/admin/foo.bin',
153+
'{URL}/package.json',
154+
'{URL}/shared.html',
155+
'{URL}/web/**/*.{py,tpl,js,vue,php,mjs,cts,jsx,tsx,rhtml,slim,handlebars,twig,rs,njk,svelte,liquid,pug,md,ts,heex,mts,astro,nunjucks,rb,eex,haml,cjs,html,hbs,jade,aspx,razor,erb,mustache,mdx}',
128156
],
129157
},
130-
])
131-
132-
testFixture('v4/auto-content', [
133-
//
134158
{
135-
config: 'src/app.css',
159+
config: 'web/app.css',
136160
content: [
161+
'{URL}/web/**/*.{py,tpl,js,vue,php,mjs,cts,jsx,tsx,rhtml,slim,handlebars,twig,rs,njk,svelte,liquid,pug,md,ts,heex,mts,astro,nunjucks,rb,eex,haml,cjs,html,hbs,jade,aspx,razor,erb,mustache,mdx}',
162+
'{URL}/web/*.bin',
163+
'{URL}/web/bar.bin',
137164
'{URL}/package.json',
138-
'{URL}/src/index.html',
139-
'{URL}/src/components/example.html',
140-
'{URL}/src/**/*.{py,tpl,js,vue,php,mjs,cts,jsx,tsx,rhtml,slim,handlebars,twig,rs,njk,svelte,liquid,pug,md,ts,heex,mts,astro,nunjucks,rb,eex,haml,cjs,html,hbs,jade,aspx,razor,erb,mustache,mdx}',
165+
'{URL}/shared.html',
166+
'{URL}/admin/**/*.{py,tpl,js,vue,php,mjs,cts,jsx,tsx,rhtml,slim,handlebars,twig,rs,njk,svelte,liquid,pug,md,ts,heex,mts,astro,nunjucks,rb,eex,haml,cjs,html,hbs,jade,aspx,razor,erb,mustache,mdx}',
141167
],
142168
},
143169
])

packages/tailwindcss-language-server/src/project-locator.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import resolveFrom from './util/resolveFrom'
1515
import { type Feature, supportedFeatures } from '@tailwindcss/language-service/src/features'
1616
import { resolveCssImports } from './resolve-css-imports'
1717
import { normalizeDriveLetter, normalizePath, pathToFileURL } from './utils'
18+
import { loadConfig } from './util/v4/design-system'
1819

1920
export interface ProjectConfig {
2021
/** The folder that contains the project */
@@ -105,6 +106,7 @@ export class ProjectLocator {
105106
entries: [],
106107
content: [],
107108
packageRoot: '',
109+
globs: [],
108110
}
109111

110112
let tailwind = await this.detectTailwindVersion(config)
@@ -291,6 +293,7 @@ export class ProjectLocator {
291293
entries: [],
292294
packageRoot: null,
293295
content: [],
296+
globs: [],
294297
})),
295298
])
296299
})
@@ -323,6 +326,7 @@ export class ProjectLocator {
323326
entries: [],
324327
packageRoot: null,
325328
content: [],
329+
globs: [],
326330
})),
327331
)
328332
continue
@@ -378,14 +382,19 @@ export class ProjectLocator {
378382
if (indexPath && themePath) graph.connect(indexPath, themePath)
379383
if (indexPath && utilitiesPath) graph.connect(indexPath, utilitiesPath)
380384

385+
// QUESTION: Is this code path only for v4? I don't understand the gating
386+
// here but adding a content kind auto indicates that this is the case.
381387
for (let root of graph.roots()) {
388+
let globs = await loadConfig(root.path, root.content)
389+
382390
let config: ConfigEntry = configs.remember(root.path, () => ({
383391
source: 'css',
384392
type: 'css',
385393
path: root.path,
386394
entries: [],
387395
packageRoot: null,
388396
content: [{ kind: 'auto' }],
397+
globs,
389398
}))
390399

391400
// The root is a CSS entrypoint so lets use it as the "config" file
@@ -500,7 +509,7 @@ async function* contentSelectorsFromCssConfig(entry: ConfigEntry): AsyncIterable
500509
}
501510
} else if (item.kind === 'auto' && !auto) {
502511
auto = true
503-
for await (let pattern of detectContentFiles(entry.packageRoot)) {
512+
for await (let pattern of detectContentFiles(entry.packageRoot, entry.path, entry.globs)) {
504513
yield {
505514
pattern,
506515
priority: DocumentSelectorPriority.CONTENT_FILE,
@@ -510,17 +519,35 @@ async function* contentSelectorsFromCssConfig(entry: ConfigEntry): AsyncIterable
510519
}
511520
}
512521

513-
async function* detectContentFiles(base: string): AsyncIterable<string> {
522+
async function* detectContentFiles(
523+
base: string,
524+
inputFile,
525+
inputGlobs: string[],
526+
): AsyncIterable<string> {
514527
try {
515528
let oxidePath = resolveFrom(path.dirname(base), '@tailwindcss/oxide')
516529
oxidePath = pathToFileURL(oxidePath).href
530+
console.log({ oxidePath })
517531

518-
const oxide: typeof import('@tailwindcss/oxide') = await import(oxidePath)
532+
const oxide: typeof import('@tailwindcss/oxide') = await import(oxidePath).then(
533+
(o) => o.default,
534+
)
519535

520536
// This isn't a v4 project
521537
if (!oxide.scanDir) return
522538

523-
let { files, globs } = oxide.scanDir({ base, globs: true })
539+
console.log(oxide.scanDir.toString())
540+
541+
console.log({
542+
inputFile,
543+
s: inputGlobs.map((pattern) => ({ base: path.dirname(inputFile), pattern })),
544+
})
545+
546+
let { files, globs } = oxide.scanDir({
547+
base,
548+
sources: inputGlobs.map((pattern) => ({ base, pattern })),
549+
})
550+
console.log({ files, globs })
524551

525552
for (let file of files) {
526553
yield normalizePath(file)
@@ -547,6 +574,7 @@ type ConfigEntry = {
547574
entries: FileEntry[]
548575
packageRoot: string
549576
content: ContentItem[]
577+
globs: string[]
550578
}
551579

552580
class FileEntry {

packages/tailwindcss-language-server/src/projects.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ export async function createProjectService(
750750
css,
751751
)
752752

753+
console.log({ designSystem })
754+
753755
state.designSystem = designSystem
754756

755757
originalConfig = { theme: {} }

0 commit comments

Comments
 (0)