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

Function addIncludeIgnoredPatterns

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

Source from the content-addressed store, hash-verified

469 * index in the same process sees the new patterns.
470 */
471export function addIncludeIgnoredPatterns(rootDir: string, patterns: string[]): number {
472 const file = path.join(rootDir, PROJECT_CONFIG_FILENAME);
473 let config: Record<string, unknown> = {};
474 let raw: string | null = null;
475 try {
476 raw = readRegularFileSync(file, 'utf-8');
477 } catch {
478 raw = null; // missing file — create a fresh one below
479 }
480 if (raw !== null) {
481 let parsed: unknown;
482 try {
483 parsed = JSON.parse(raw);
484 } catch {
485 throw new Error(`${PROJECT_CONFIG_FILENAME} is not valid JSON — fix it by hand, then re-run.`);
486 }
487 if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
488 config = parsed as Record<string, unknown>;
489 }
490 }
491
492 const existing = Array.isArray(config.includeIgnored)
493 ? (config.includeIgnored as unknown[]).filter((p): p is string => typeof p === 'string')
494 : [];
495 const merged = [...existing];
496 const seen = new Set(existing);
497 let added = 0;
498 for (const p of patterns) {
499 if (seen.has(p)) continue;
500 seen.add(p);
501 merged.push(p);
502 added++;
503 }
504 config.includeIgnored = merged;
505 writeRegularFileSync(file, JSON.stringify(config, null, 2) + '\n');
506 clearProjectConfigCache();
507 return added;
508}

Callers 2

offerIndexIgnoredReposFunction · 0.85

Calls 8

readRegularFileSyncFunction · 0.90
writeRegularFileSyncFunction · 0.90
clearProjectConfigCacheFunction · 0.85
parseMethod · 0.80
hasMethod · 0.80
pushMethod · 0.80
joinMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected