Palate
File type detection combining the best of tft and hyperpolyglot.
Acknowledgments
This project is a reassembly of code from several excellent projects:
- tft - Tree-sitter File Type, providing fast file type detection using tree-sitter grammars
- Neovim - The original source of filetype detection heuristics and patterns
- hyperpolyglot - Language detection library with comprehensive language patterns
This crate essentially combines and curates the detection logic from these sources into a unified, ergonomic API.
License
GPL-3.0-or-later
This project is derived from tft (GPL-3.0-or-later), which itself incorporates code from Neovim (Apache-2.0/Vim license). As a derivative of GPL-3.0 work, this project is licensed under GPL-3.0-or-later.
Features
- Comprehensive file type detection
- Fast PHF-based lookups
- Content-based detection with heuristics
- Shebang interpretation support
- Naive Bayes classifier fallback (with
classifierfeature)
Usage
use ;
// Detect file type with fallback to Text
let ft = detect;
assert_eq!;
// Try detection without fallback
let ft = try_detect;
assert_eq!;
Detection Pipeline
- Path suffix matching
- Filename matching
- Pattern matching (with priorities)
- File extension matching (PHF map)
- Negative priority patterns
- Content-based detection (dynamic resolvers)
Features
detect(default): Enable file type detectionclassifier: Enable naive Bayes classifierserde: Enable serde serialization for FileType