MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / addIncludeIgnoredPatterns

Function addIncludeIgnoredPatterns

src/project-config.ts:359–396  ·  view source on GitHub ↗
(rootDir: string, patterns: string[])

Source from the content-addressed store, hash-verified

357 * index in the same process sees the new patterns.
358 */
359export function addIncludeIgnoredPatterns(rootDir: string, patterns: string[]): number {
360 const file = path.join(rootDir, PROJECT_CONFIG_FILENAME);
361 let config: Record<string, unknown> = {};
362 let raw: string | null = null;
363 try {
364 raw = fs.readFileSync(file, 'utf-8');
365 } catch {
366 raw = null; // missing file — create a fresh one below
367 }
368 if (raw !== null) {
369 let parsed: unknown;
370 try {
371 parsed = JSON.parse(raw);
372 } catch {
373 throw new Error(`${PROJECT_CONFIG_FILENAME} is not valid JSON — fix it by hand, then re-run.`);
374 }
375 if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
376 config = parsed as Record<string, unknown>;
377 }
378 }
379
380 const existing = Array.isArray(config.includeIgnored)
381 ? (config.includeIgnored as unknown[]).filter((p): p is string => typeof p === 'string')
382 : [];
383 const merged = [...existing];
384 const seen = new Set(existing);
385 let added = 0;
386 for (const p of patterns) {
387 if (seen.has(p)) continue;
388 seen.add(p);
389 merged.push(p);
390 added++;
391 }
392 config.includeIgnored = merged;
393 fs.writeFileSync(file, JSON.stringify(config, null, 2) + '\n');
394 clearProjectConfigCache();
395 return added;
396}

Callers 2

offerIndexIgnoredReposFunction · 0.85

Calls 3

clearProjectConfigCacheFunction · 0.85
hasMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected