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

Class ScopeIgnore

src/extraction/index.ts:1048–1127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1046}
1047
1048export class ScopeIgnore {
1049 private embedded: Array<{ root: string; matcher: Ignore }>;
1050 private defaults: Ignore = defaultsOnlyIgnore();
1051 constructor(
1052 private rootMatcher: Ignore,
1053 embedded: Array<{ root: string; matcher: Ignore }>,
1054 /**
1055 * Project `codegraph.json` `exclude` patterns (#999), matched against the
1056 * full root-relative path. Wins over everything else — an explicit user
1057 * exclude applies even to tracked files and even inside embedded repos.
1058 */
1059 private exclude: Ignore | null = null,
1060 /**
1061 * Project `codegraph.json` `include` patterns — first-party source forced
1062 * INTO the index despite `.gitignore`. When a path matches, it is NOT
1063 * ignored (so the watcher watches it), overriding `.gitignore`/`rootMatcher`
1064 * — but never `exclude` (checked first) and never a built-in default-ignored
1065 * dir. `includeRoots` are the static prefixes so a gitignored ANCESTOR
1066 * directory of an included subtree still isn't pruned by the directory
1067 * walker/watcher.
1068 */
1069 private include: Ignore | null = null,
1070 private includeRoots: string[] = [],
1071 /**
1072 * The directories `git ls-files --exclude-standard` reports as ignored
1073 * (see listGitIgnoredDirectories): root-relative, trailing-slashed paths.
1074 * Each names one directory and is matched as a literal path prefix, never
1075 * as a gitignore pattern. As a pattern, `src/` matched every `src/` below
1076 * the root too, hiding a whole Maven monorepo's sources (#2849), and a
1077 * folder named `[draft]` or `a[b` read as a glob (or did not compile).
1078 */
1079 private gitIgnoredDirs: ReadonlySet<string> = new Set(),
1080 ) {
1081 // Longest root first so paths in nested embedded repos hit the innermost matcher.
1082 this.embedded = [...embedded].sort((a, b) => b.root.length - a.root.length);
1083 }
1084
1085 /** True when `rel` is one of {@link gitIgnoredDirs} or lies inside one. */
1086 private inGitIgnoredDir(rel: string): boolean {
1087 if (this.gitIgnoredDirs.size === 0) return false;
1088 for (let slash = rel.indexOf('/'); slash !== -1; slash = rel.indexOf('/', slash + 1)) {
1089 if (this.gitIgnoredDirs.has(rel.slice(0, slash + 1))) return true;
1090 }
1091 return false;
1092 }
1093
1094 ignores(rel: string): boolean {
1095 // User `exclude` (#999) is checked first and against the full root-relative
1096 // path: it must drop git-TRACKED paths (which `.gitignore` can't) and apply
1097 // everywhere, including ancestors of embedded repos.
1098 if (this.exclude && this.exclude.ignores(rel)) return true;
1099 // User `include`: force first-party source in despite `.gitignore`. Never
1100 // resurfaces a built-in default-ignored dir (node_modules/dist/…), so an
1101 // include pattern can't accidentally pull in dependency/build trees.
1102 if (this.include && !this.defaults.ignores(rel)) {
1103 if (rel.endsWith('/')) {
1104 // A directory on (or leading to) an included subtree must stay walkable
1105 // so the watcher/walker descends to reach the forced-in files.

Callers

nothing calls this directly

Calls 1

defaultsOnlyIgnoreFunction · 0.85

Tested by

no test coverage detected