Skip to content

Commit 70d5bb6

Browse files
committed
Cancel project search if it takes too long
1 parent 2bb7a5b commit 70d5bb6

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ interface SearchFilesOptions {
55
/** The directory to search in */
66
root: string
77

8+
/** The maximum time to wait for the search to complete */
9+
timeout: number
10+
811
/** A list of patterns to include */
912
include: string[]
1013

@@ -26,7 +29,13 @@ export async function searchFiles(opts: SearchFilesOptions) {
2629
{ dot: true },
2730
)
2831

32+
let controller = new AbortController()
33+
let timer = setTimeout(() => controller.abort(), opts.timeout)
34+
2935
let crawler = new fdir({
36+
// Let us cancel the search if it takes too long
37+
signal: controller.signal,
38+
3039
// onlyFiles: true
3140
includeDirs: false,
3241
excludeFiles: false,
@@ -59,5 +68,7 @@ export async function searchFiles(opts: SearchFilesOptions) {
5968

6069
let results = await crawler.crawl(opts.root).withPromise()
6170

71+
clearTimeout(timer)
72+
6273
return results
6374
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ export class ProjectLocator {
279279
root: this.base,
280280
include: [`**/${CONFIG_GLOB}`, `**/${CSS_GLOB}`],
281281
exclude: this.settings.tailwindCSS.files.exclude,
282+
283+
// If searching takes more than 15 seconds, abort the search
284+
timeout: 15,
282285
})
283286

284287
let realpaths = await Promise.all(files.map((file) => fs.realpath(file)))

0 commit comments

Comments
 (0)