Skip to content

Commit daa09cd

Browse files
committed
Refactor
1 parent 8b6eafa commit daa09cd

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

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

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ declare namespace OxideV2 {
3636
}
3737
}
3838

39-
// This covers the Oxide API from v4.0.0-alpha.20+
40-
declare namespace OxideV3 {
39+
// This covers the Oxide API from v4.0.0-alpha.30+
40+
declare namespace OxideV3And4 {
4141
interface GlobEntry {
4242
base: string
4343
pattern: string
@@ -61,7 +61,7 @@ declare namespace OxideV3 {
6161
interface Oxide {
6262
scanDir?(options: OxideV1.ScanOptions): OxideV1.ScanResult
6363
scanDir?(options: OxideV2.ScanOptions): OxideV2.ScanResult
64-
Scanner?: OxideV3.ScannerConstructor
64+
Scanner?: OxideV3And4.ScannerConstructor
6565
}
6666

6767
async function loadOxideAtPath(id: string): Promise<Oxide | null> {
@@ -73,21 +73,22 @@ async function loadOxideAtPath(id: string): Promise<Oxide | null> {
7373
return oxide
7474
}
7575

76-
interface GlobEntry {
76+
interface SourceEntry {
7777
base: string
7878
pattern: string
79+
negated: boolean
7980
}
8081

8182
interface ScanOptions {
8283
oxidePath: string
8384
oxideVersion: string
8485
basePath: string
85-
sources: Array<GlobEntry>
86+
sources: Array<SourceEntry>
8687
}
8788

8889
interface ScanResult {
8990
files: Array<string>
90-
globs: Array<GlobEntry>
91+
sources: Array<SourceEntry>
9192
}
9293

9394
/**
@@ -113,43 +114,48 @@ export async function scan(options: ScanOptions): Promise<ScanResult | null> {
113114

114115
return {
115116
files: result.files,
116-
globs: result.globs.map((g) => ({ base: g.base, pattern: g.glob })),
117+
sources: result.globs.map((s) => ({ base: s.base, pattern: s.glob, negated: false })),
117118
}
118119
}
119120

120121
// V2
121-
if (lte(options.oxideVersion, '4.0.0-alpha.19')) {
122+
else if (lte(options.oxideVersion, '4.0.0-alpha.19')) {
122123
let result = oxide.scanDir({
123124
base: options.basePath,
124125
sources: options.sources,
125126
})
126127

127128
return {
128129
files: result.files,
129-
globs: result.globs,
130+
sources: result.globs.map((s) => ({ base: s.base, pattern: s.pattern, negated: false })),
130131
}
131132
}
132133

133134
// V3
134-
if (lte(options.oxideVersion, '4.0.0-alpha.30')) {
135-
let scanner = new oxide.Scanner({
135+
else if (lte(options.oxideVersion, '4.0.0-alpha.30')) {
136+
let scanner = new (oxide.Scanner as OxideV3And4.ScannerConstructor)({
136137
detectSources: { base: options.basePath },
137-
sources: options.sources,
138+
sources: options.sources.map((s) => ({ base: s.base, pattern: s.pattern })),
138139
})
139140

140141
return {
141142
files: scanner.files,
142-
globs: scanner.globs,
143+
sources: scanner.globs.map((s) => ({ base: s.base, pattern: s.pattern, negated: false })),
143144
}
144145
}
145146

146147
// V4
147-
let scanner = new oxide.Scanner({
148-
sources: [{ base: options.basePath, pattern: '**/*' }, ...options.sources],
149-
})
148+
else {
149+
let scanner = new (oxide.Scanner as OxideV3And4.ScannerConstructor)({
150+
sources: [
151+
{ base: options.basePath, pattern: '**/*' },
152+
...options.sources.map((s) => ({ base: s.base, pattern: s.pattern })),
153+
],
154+
})
150155

151-
return {
152-
files: scanner.files,
153-
globs: scanner.globs,
156+
return {
157+
files: scanner.files,
158+
sources: scanner.globs.map((s) => ({ base: s.base, pattern: s.pattern, negated: false })),
159+
}
154160
}
155161
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,9 @@ async function* detectContentFiles(
652652
yield normalizePath(file)
653653
}
654654

655-
for (let { base, pattern } of result.globs) {
655+
for (let { base, pattern, negated } of result.sources) {
656+
if (negated) continue
657+
656658
// Do not normalize the glob itself as it may contain escape sequences
657659
yield normalizePath(base) + '/' + pattern
658660
}

0 commit comments

Comments
 (0)