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

Function addIncludeIgnoredPatterns

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

Source from the content-addressed store, hash-verified

410 * index in the same process sees the new patterns.
411 */
412export function addIncludeIgnoredPatterns(rootDir: string, patterns: string[]): number {
413 const file = path.join(rootDir, PROJECT_CONFIG_FILENAME);
414 let config: Record<string, unknown> = {};
415 let raw: string | null = null;
416 try {
417 raw = fs.readFileSync(file, 'utf-8');
418 } catch {
419 raw = null; // missing file — create a fresh one below
420 }
421 if (raw !== null) {
422 let parsed: unknown;
423 try {
424 parsed = JSON.parse(raw);
425 } catch {
426 throw new Error(`${PROJECT_CONFIG_FILENAME} is not valid JSON — fix it by hand, then re-run.`);
427 }
428 if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
429 config = parsed as Record<string, unknown>;
430 }
431 }
432
433 const existing = Array.isArray(config.includeIgnored)
434 ? (config.includeIgnored as unknown[]).filter((p): p is string => typeof p === 'string')
435 : [];
436 const merged = [...existing];
437 const seen = new Set(existing);
438 let added = 0;
439 for (const p of patterns) {
440 if (seen.has(p)) continue;
441 seen.add(p);
442 merged.push(p);
443 added++;
444 }
445 config.includeIgnored = merged;
446 fs.writeFileSync(file, JSON.stringify(config, null, 2) + '\n');
447 clearProjectConfigCache();
448 return added;
449}

Callers 2

offerIndexIgnoredReposFunction · 0.85

Calls 3

clearProjectConfigCacheFunction · 0.85
hasMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected