Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions src/core/index_filter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
use std::fs;
use std::path::Path;

pub(crate) fn should_index_path(path: &Path, max_file_size: u64) -> bool {
if let Ok(metadata) = fs::metadata(path) {
if metadata.len() > max_file_size {
return false;
}
}

let ext = path
.extension()
.and_then(|e| e.to_str())
.unwrap_or("")
.to_lowercase();

matches!(
ext.as_str(),
"rs" | "py"
| "js"
| "ts"
| "tsx"
| "jsx"
| "go"
| "c"
| "cpp"
| "h"
| "hpp"
| "java"
| "kt"
| "swift"
| "rb"
| "php"
| "cs"
| "fs"
| "scala"
| "clj"
| "ex"
| "exs"
| "erl"
| "hs"
| "ml"
| "lua"
| "r"
| "jl"
| "dart"
| "vue"
| "svelte"
| "astro"
| "html"
| "htm"
| "css"
| "scss"
| "sass"
| "less"
| "json"
| "yaml"
| "yml"
| "toml"
| "xml"
| "md"
| "markdown"
| "txt"
| "rst"
| "tex"
| "sh"
| "bash"
| "zsh"
| "fish"
| "ps1"
| "bat"
| "cmd"
| "sql"
| "graphql"
| "proto"
) || path.file_name().is_some_and(|n| {
let name = n.to_string_lossy().to_lowercase();
matches!(
name.as_str(),
"dockerfile"
| "makefile"
| "cmakelists.txt"
| "rakefile"
| "gemfile"
| "podfile"
| "vagrantfile"
| ".gitignore"
| ".dockerignore"
| ".env.example"
| "readme"
| "license"
| "changelog"
)
})
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn does_not_index_extensionless_files_by_default() {
assert!(!should_index_path(Path::new("my_binary"), 512 * 1024));
}

#[test]
fn indexes_known_extensionless_filenames() {
assert!(should_index_path(Path::new("Makefile"), 512 * 1024));
assert!(should_index_path(Path::new("Dockerfile"), 512 * 1024));
assert!(should_index_path(Path::new("README"), 512 * 1024));
}

#[test]
fn indexes_known_extensions() {
assert!(should_index_path(Path::new("src/main.rs"), 512 * 1024));
assert!(should_index_path(Path::new("script.SH"), 512 * 1024));
}
}
184 changes: 2 additions & 182 deletions src/core/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,97 +236,7 @@ impl Indexer {
}

fn should_index(&self, path: &Path) -> bool {
if let Ok(metadata) = fs::metadata(path) {
if metadata.len() > self.max_file_size {
return false;
}
}

let ext = path
.extension()
.and_then(|e| e.to_str())
.unwrap_or("")
.to_lowercase();

matches!(
ext.as_str(),
"rs" | "py"
| "js"
| "ts"
| "tsx"
| "jsx"
| "go"
| "c"
| "cpp"
| "h"
| "hpp"
| "java"
| "kt"
| "swift"
| "rb"
| "php"
| "cs"
| "fs"
| "scala"
| "clj"
| "ex"
| "exs"
| "erl"
| "hs"
| "ml"
| "lua"
| "r"
| "jl"
| "dart"
| "vue"
| "svelte"
| "astro"
| "html"
| "htm"
| "css"
| "scss"
| "sass"
| "less"
| "json"
| "yaml"
| "yml"
| "toml"
| "xml"
| "md"
| "markdown"
| "txt"
| "rst"
| "tex"
| "sh"
| "bash"
| "zsh"
| "fish"
| "ps1"
| "bat"
| "cmd"
| "sql"
| "graphql"
| "proto"
| ""
) || path.file_name().is_some_and(|n| {
let name = n.to_string_lossy().to_lowercase();
matches!(
name.as_str(),
"dockerfile"
| "makefile"
| "cmakelists.txt"
| "rakefile"
| "gemfile"
| "podfile"
| "vagrantfile"
| ".gitignore"
| ".dockerignore"
| ".env.example"
| "readme"
| "license"
| "changelog"
)
})
super::index_filter::should_index_path(path, self.max_file_size)
}

fn chunk_content(&self, content: &str) -> Vec<FileChunk> {
Expand Down Expand Up @@ -612,97 +522,7 @@ impl ServerIndexer {
}

fn should_index(&self, path: &Path) -> bool {
if let Ok(metadata) = fs::metadata(path) {
if metadata.len() > self.max_file_size {
return false;
}
}

let ext = path
.extension()
.and_then(|e| e.to_str())
.unwrap_or("")
.to_lowercase();

matches!(
ext.as_str(),
"rs" | "py"
| "js"
| "ts"
| "tsx"
| "jsx"
| "go"
| "c"
| "cpp"
| "h"
| "hpp"
| "java"
| "kt"
| "swift"
| "rb"
| "php"
| "cs"
| "fs"
| "scala"
| "clj"
| "ex"
| "exs"
| "erl"
| "hs"
| "ml"
| "lua"
| "r"
| "jl"
| "dart"
| "vue"
| "svelte"
| "astro"
| "html"
| "htm"
| "css"
| "scss"
| "sass"
| "less"
| "json"
| "yaml"
| "yml"
| "toml"
| "xml"
| "md"
| "markdown"
| "txt"
| "rst"
| "tex"
| "sh"
| "bash"
| "zsh"
| "fish"
| "ps1"
| "bat"
| "cmd"
| "sql"
| "graphql"
| "proto"
| ""
) || path.file_name().is_some_and(|n| {
let name = n.to_string_lossy().to_lowercase();
matches!(
name.as_str(),
"dockerfile"
| "makefile"
| "cmakelists.txt"
| "rakefile"
| "gemfile"
| "podfile"
| "vagrantfile"
| ".gitignore"
| ".dockerignore"
| ".env.example"
| "readme"
| "license"
| "changelog"
)
})
super::index_filter::should_index_path(path, self.max_file_size)
}

fn chunk_content(&self, content: &str) -> Vec<FileChunk> {
Expand Down
1 change: 1 addition & 0 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

mod db;
mod embeddings;
pub(crate) mod index_filter;
mod indexer;
mod search;

Expand Down
Loading
Loading