feat: support .codegraphignore for excluding files from index#360
Open
Krislu1221 wants to merge 1 commit into
Open
feat: support .codegraphignore for excluding files from index#360Krislu1221 wants to merge 1 commit into
Krislu1221 wants to merge 1 commit into
Conversation
Adds .codegraphignore support alongside .gitignore for fine-grained
control over which files CodeGraph indexes.
Motivation:
- .gitignore affects git tracking, not just CodeGraph
- Users often want to exclude build artifacts, sandboxes, or large
dependency directories from the code graph without changing their
.gitignore
- Example: monorepo with .sandbox-home/, node_modules/ that should
not be indexed
Changes:
- scanDirectoryWalk (fs fallback): loadIgnore() now reads both
.gitignore and .codegraphignore, OR-ing patterns from both
- scanDirectory (git fast path): applies root .codegraphignore as
a second-pass filter after git ls-files
- scanDirectoryAsync: same treatment as scanDirectory
.gitignore syntax rules are used for .codegraphignore, consistent
with how the tool already parses .gitignore files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
CodeGraph currently indexes every file in the project (aside from what
.gitignoreexcludes). In many real-world projects this means significant noise:.sandbox-home/,dist/,build/directories.venv/,venv/,__pycache__/node_modules/Users do not want to add these to
.gitignorebecause they are either git-tracked or serve a different purpose. They want CodeGraph to skip them independently.In my case, 97% of the 7175 indexed files were third-party dependencies under
.sandbox-home/— makingcodegraph contextandcodegraph queryresults dominated by noise.Solution
Add
.codegraphignoresupport using the same gitignore syntax (theignorenpm package is already a dependency). Patterns from.gitignoreand.codegraphignoreare OR-d together — a file is excluded if it matches a pattern in either file.Changes
scanDirectoryWalk(filesystem fallback path):loadIgnore()now reads both.gitignoreand.codegraphignorefrom each directory level. When both exist, patterns from both are merged into one matcher.scanDirectory(git fast path): Applies root.codegraphignoreas a second-pass filter aftergit ls-files. Since the git path already respects.gitignoreviagit ls-files, only.codegraphignorepatterns need to be checked additionally.scanDirectoryAsync: Same treatment asscanDirectory.Usage
Create a
.codegraphignorefile in the project root (or any subdirectory for the walk path):Then run
codegraph index --forceto rebuild the index with the new exclusion rules.Testing
tsc+ copy-assets).codegraphignorewith.sandbox-home/pattern in a test project, confirmed the directory is excluded fromcodegraph files --jsonoutput.