Skip to content

Commit 9dc65c9

Browse files
committed
Fix errors thrown by detecting content files with oxide (#942)
1 parent d25652b commit 9dc65c9

File tree

3 files changed

+197
-6
lines changed

3 files changed

+197
-6
lines changed

package-lock.json

Lines changed: 182 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/tailwindcss-language-server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@tailwindcss/forms": "0.5.3",
4040
"@tailwindcss/language-service": "*",
4141
"@tailwindcss/line-clamp": "0.4.2",
42+
"@tailwindcss/oxide": "^4.0.0-alpha.11",
4243
"@tailwindcss/typography": "0.5.7",
4344
"@types/color-name": "^1.1.3",
4445
"@types/culori": "^2.1.0",

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import resolveFrom from './util/resolveFrom'
1616
import { type Feature, supportedFeatures } from '@tailwindcss/language-service/src/features'
1717
import { pathToFileURL } from 'node:url'
1818
import { resolveCssImports } from './resolve-css-imports'
19+
import type { GlobEntry } from '@tailwindcss/oxide'
1920

2021
export interface ProjectConfig {
2122
/** The folder that contains the project */
@@ -439,27 +440,34 @@ async function* contentSelectorsFromCssConfig(entry: ConfigEntry): AsyncIterable
439440
} else if (item.kind === 'auto' && !auto) {
440441
auto = true
441442
for await (let file of detectContentFiles(entry.packageRoot)) {
442-
yield {
443-
pattern: normalizePath(file),
444-
priority: DocumentSelectorPriority.CONTENT_FILE,
443+
if (typeof file === 'string') {
444+
yield {
445+
pattern: normalizePath(file),
446+
priority: DocumentSelectorPriority.CONTENT_FILE,
447+
}
445448
}
446449
}
447450
}
448451
}
449452
}
450453

451-
async function* detectContentFiles(base: string): AsyncIterable<string> {
454+
async function* detectContentFiles(base: string): AsyncIterable<string | GlobEntry> {
452455
try {
453456
let oxidePath = resolveFrom(path.dirname(base), '@tailwindcss/oxide')
454457
oxidePath = pathToFileURL(oxidePath).href
455458

456459
// This isn't a v4 project
457460
const oxide = await import(oxidePath)
458-
if (!oxide.scanDir) {
461+
462+
function validateOxide(input: any): input is typeof import('@tailwindcss/oxide') {
463+
return !!oxide.scanDir
464+
}
465+
466+
if (!validateOxide(oxide)) {
459467
return
460468
}
461469

462-
let { files, globs } = await oxide.scanDir({ base, globs: true })
470+
let { files, globs } = oxide.scanDir({ base, globs: true })
463471

464472
yield* files
465473
yield* globs

0 commit comments

Comments
 (0)