Fix: Correctly handle include patterns in file filtering #19
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.
Description
I encountered a bug where filtering was not working as expected. When
--includewas used (e.g.,-i "*.yml"), files with other extensions (like.rsor.lock) were still in the output.The root cause appears to be with the
add_custom_ignore_filenamemethod inWalkBuilder. It looks like this method is meant for adding custom ignore file names, such as.gitignore, rather than filtering files using glob patterns.Using the Homebrew binary
➜ glimpse -i "*.yml" Token Count Summary: Total tokens: 114,145 Breakdown by file: languages.yml: 52,838 Cargo.lock: 36,912 src/analyzer.rs: 4,559 src/url_processor.rs: 2,982 src/output.rs: 2,621 src/file_picker.rs: 2,552 readme.md: 1,735 src/main.rs: 1,592 src/config.rs: 1,402 src/cli.rs: 1,258 src/source_detection.rs: 1,133 src/git_processor.rs: 1,068 flake.lock: 886 src/tokenizer.rs: 762 build.rs: 648After the fix in this PR
Solution
The filtering logic has been updated to use
ignore::overrides::OverrideBuilderfor both include and exclude patterns.-i) are now added to theOverrideBuilderas positive patterns.-e) continue to be added as negative patterns (with a!).