-
Notifications
You must be signed in to change notification settings - Fork 13.2k
fix: detect newly created files in @ recommendations with core optimizations #24757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
29ff736
8fc72c7
2a3f16b
45983c8
c9d8395
c4b0762
e192a62
e028510
82e5587
cc41101
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -63,6 +63,12 @@ export interface FileSearchOptions { | |||||
| maxFiles?: number; | ||||||
| } | ||||||
|
|
||||||
| enum InitializationState { | ||||||
| Uninitialized, | ||||||
| Initializing, | ||||||
| Initialized, | ||||||
| } | ||||||
|
|
||||||
| export class AbortError extends Error { | ||||||
| constructor(message = 'Search aborted') { | ||||||
| super(message); | ||||||
|
|
@@ -133,26 +139,62 @@ class RecursiveFileSearch implements FileSearch { | |||||
| private resultCache: ResultCache | undefined; | ||||||
| private allFiles: string[] = []; | ||||||
| private fzf: AsyncFzf<string[]> | undefined; | ||||||
| private initializationState = InitializationState.Uninitialized; | ||||||
|
prassamin marked this conversation as resolved.
|
||||||
| private initPromise: Promise<void> | null = null; | ||||||
|
|
||||||
| constructor(private readonly options: FileSearchOptions) {} | ||||||
|
|
||||||
| async initialize(): Promise<void> { | ||||||
| this.ignore = loadIgnoreRules( | ||||||
| this.options.fileDiscoveryService, | ||||||
| this.options.ignoreDirs, | ||||||
| ); | ||||||
| if (this.initializationState === InitializationState.Initializing) { | ||||||
| return this.initPromise || Promise.resolve(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When managing the state of asynchronous operations, rely on the explicit state variable
Suggested change
References
|
||||||
| } | ||||||
|
|
||||||
| this.allFiles = await crawl({ | ||||||
| crawlDirectory: this.options.projectRoot, | ||||||
| cwd: this.options.projectRoot, | ||||||
| ignore: this.ignore, | ||||||
| cache: this.options.cache, | ||||||
| cacheTtl: this.options.cacheTtl, | ||||||
| maxDepth: this.options.maxDepth, | ||||||
| maxFiles: this.options.maxFiles ?? 20000, | ||||||
| }); | ||||||
| this.initPromise = (async () => { | ||||||
| const prevState = this.initializationState; | ||||||
| this.initializationState = InitializationState.Initializing; | ||||||
|
|
||||||
| try { | ||||||
| const nextIgnore = loadIgnoreRules( | ||||||
| this.options.fileDiscoveryService, | ||||||
| this.options.ignoreDirs, | ||||||
| ); | ||||||
|
|
||||||
| const nextFiles = await crawl({ | ||||||
| crawlDirectory: this.options.projectRoot, | ||||||
| cwd: this.options.projectRoot, | ||||||
| ignore: nextIgnore, | ||||||
| cache: this.options.cache, | ||||||
| cacheTtl: this.options.cacheTtl, | ||||||
| maxDepth: this.options.maxDepth, | ||||||
| maxFiles: this.options.maxFiles ?? 20000, | ||||||
| }); | ||||||
|
|
||||||
| if ( | ||||||
| nextFiles === this.allFiles && | ||||||
| this.ignore && | ||||||
| prevState === InitializationState.Initialized | ||||||
| ) { | ||||||
| this.initializationState = InitializationState.Initialized; | ||||||
| // optimization: if the file list is referentially equal (from crawl cache) | ||||||
| // and we already have ignore rules, skip rebuilding the FZF index. | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| this.ignore = nextIgnore; | ||||||
| this.allFiles = nextFiles; | ||||||
| this.buildResultCache(); | ||||||
| this.initializationState = InitializationState.Initialized; | ||||||
| } catch (e) { | ||||||
| this.initializationState = prevState; | ||||||
| throw e; | ||||||
| } | ||||||
| })(); | ||||||
|
|
||||||
| this.buildResultCache(); | ||||||
| try { | ||||||
| await this.initPromise; | ||||||
| } finally { | ||||||
| this.initPromise = null; | ||||||
| } | ||||||
| } | ||||||
|
prassamin marked this conversation as resolved.
|
||||||
|
|
||||||
| async search( | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.