MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / walkDirectoryWithFd

Function walkDirectoryWithFd

packages/pi-tui/src/autocomplete.ts:124–217  ·  view source on GitHub ↗
(
	baseDir: string,
	fdPath: string,
	query: string,
	maxResults: number,
	signal: AbortSignal,
)

Source from the content-addressed store, hash-verified

122
123// Use fd to walk directory tree (fast, respects .gitignore)
124async function walkDirectoryWithFd(
125 baseDir: string,
126 fdPath: string,
127 query: string,
128 maxResults: number,
129 signal: AbortSignal,
130): Promise<Array<{ path: string; isDirectory: boolean }>> {
131 const args = [
132 "--base-directory",
133 baseDir,
134 "--max-results",
135 String(maxResults),
136 "--type",
137 "f",
138 "--type",
139 "d",
140 "--follow",
141 "--hidden",
142 "--exclude",
143 ".git",
144 "--exclude",
145 ".git/*",
146 "--exclude",
147 ".git/**",
148 ];
149
150 if (toDisplayPath(query).includes("/")) {
151 args.push("--full-path");
152 }
153
154 if (query) {
155 args.push(buildFdPathQuery(query));
156 }
157
158 return await new Promise((resolve) => {
159 if (signal.aborted) {
160 resolve([]);
161 return;
162 }
163
164 const child = spawn(fdPath, args, {
165 stdio: ["ignore", "pipe", "pipe"],
166 });
167 let stdout = "";
168 let resolved = false;
169
170 const finish = (results: Array<{ path: string; isDirectory: boolean }>) => {
171 if (resolved) return;
172 resolved = true;
173 signal.removeEventListener("abort", onAbort);
174 resolve(results);
175 };
176
177 const onAbort = () => {
178 if (child.exitCode === null) {
179 child.kill("SIGKILL");
180 }
181 };

Callers 1

Calls 7

toDisplayPathFunction · 0.85
buildFdPathQueryFunction · 0.85
finishFunction · 0.70
onMethod · 0.65
resolveFunction · 0.50
spawnFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected