Skip to content

Commit 2bb7a5b

Browse files
committed
Re-implement project search with fdir
1 parent 488f037 commit 2bb7a5b

File tree

3 files changed

+61
-9
lines changed

3 files changed

+61
-9
lines changed

packages/tailwindcss-language-server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"enhanced-resolve": "^5.16.1",
6969
"esbuild": "^0.25.0",
7070
"fast-glob": "3.2.4",
71+
"fdir": "^6.4.3",
7172
"find-up": "5.0.0",
7273
"jiti": "^2.3.3",
7374
"klona": "2.0.4",
Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import glob from 'fast-glob'
2-
import os from 'node:os'
1+
import { fdir } from 'fdir'
2+
import picomatch from 'picomatch'
33

44
interface SearchFilesOptions {
55
/** The directory to search in */
@@ -13,15 +13,51 @@ interface SearchFilesOptions {
1313
}
1414

1515
export async function searchFiles(opts: SearchFilesOptions) {
16-
let results = await glob(opts.include, {
17-
cwd: opts.root,
18-
ignore: opts.exclude,
19-
onlyFiles: true,
20-
absolute: true,
16+
// Ignore patterns in the project search are generally intended to match
17+
// directories but _may_ also match files.
18+
//
19+
// A pattern like `**/node_modules` should match like these:
20+
// - `**/node_modules/` to exclude directories from traversal
21+
// - `**/node_modules/**/*` to exclude files from results
22+
//
23+
// This approximately matches how fast-glob's `ignore` option works.
24+
let shouldIgnore = picomatch(
25+
[...new Set(opts.exclude.flatMap((x) => [x, `${x}/`, `${x}/**/*`]))],
26+
{ dot: true },
27+
)
28+
29+
let crawler = new fdir({
30+
// onlyFiles: true
31+
includeDirs: false,
32+
excludeFiles: false,
33+
34+
// absolute: true
35+
relativePaths: false,
36+
resolvePaths: false,
37+
includeBasePath: true,
38+
39+
// followSymbolicLinks: true
40+
resolveSymlinks: false,
41+
excludeSymlinks: false,
42+
43+
//
2144
suppressErrors: true,
22-
dot: true,
23-
concurrency: Math.max(os.cpus().length, 1),
45+
46+
// Normalize Windows paths to use forward slashes
47+
pathSeparator: '/',
48+
49+
// Don't return files that are ignored
50+
filters: [(path) => !shouldIgnore(path)],
51+
52+
// Don't traverse into directories that are ignored
53+
exclude: (_, path) => shouldIgnore(path),
54+
55+
globFunction: picomatch,
2456
})
2557

58+
crawler = crawler.globWithOptions(opts.include, { dot: true })
59+
60+
let results = await crawler.crawl(opts.root).withPromise()
61+
2662
return results
2763
}

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)