Skip to main content

pelicode_core/
lib.rs

1//! Feature extraction shared by the indexer and the detector of pelicode.
2//!
3//! Source code is parsed with Tree-sitter, split into function units,
4//! normalized at several levels, and turned into exact hashes, winnowing
5//! fingerprints, MinHash signatures and LSH buckets.
6
7#![warn(missing_docs)]
8
9pub mod config;
10pub mod extract;
11pub mod hash;
12pub mod language;
13mod normalize;
14pub mod scan;
15
16use std::path::PathBuf;
17
18pub use config::{Config, IdentMode, Level, NORMALIZER_VERSION};
19pub use extract::{
20    FileFeatures, FunctionFeatures, LevelFeatures, extract_bytes, extract_file, extract_source,
21};
22pub use hash::{Fingerprint, Hash128};
23pub use language::Language;
24pub use scan::{SourceFile, discover, extract_all, slash_path};
25
26/// Errors of feature extraction.
27#[derive(Debug, thiserror::Error)]
28pub enum Error {
29    /// A file could not be read; holds its path.
30    #[error("{0}: {1}")]
31    Io(PathBuf, #[source] std::io::Error),
32    /// Tree-sitter could not set up the language or parse the source.
33    #[error("parse error: {0}")]
34    Parse(String),
35    /// A directory could not be walked.
36    #[error("directory walk error: {0}")]
37    Walk(String),
38    /// A [`Config`] or a value given for one is invalid.
39    #[error("invalid configuration: {0}")]
40    InvalidConfig(String),
41}