pub const SIMILAR_CODE_EXTRACTION_SEMANTICS_VERSION: u32 = 1;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct SimilarCodeSourceDigest([u8; 32]);
impl SimilarCodeSourceDigest {
#[must_use]
pub const fn new(bytes: [u8; 32]) -> Self {
Self(bytes)
}
#[must_use]
pub const fn as_bytes(&self) -> &[u8; 32] {
&self.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum SimilarCodeFunctionKind {
FunctionDeclaration,
FunctionExpression,
ArrowFunction,
ClassMethod,
ObjectMethod,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum SimilarCodeSideEffectHint {
PureLooking,
MayHaveSideEffects,
Unknown,
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct SimilarCodeFunctionLocation {
pub file: String,
pub start_byte: u32,
pub end_byte: u32,
pub start_line: u32,
pub start_column_utf8: u32,
pub end_line: u32,
pub end_column_utf8: u32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExtractedSimilarCodeFunction {
pub name: String,
pub kind: SimilarCodeFunctionKind,
pub location: SimilarCodeFunctionLocation,
pub source_sha256: SimilarCodeSourceDigest,
pub source: String,
pub param_count: u32,
pub is_async: bool,
pub is_generator: bool,
pub has_await: bool,
pub has_throw: bool,
pub side_effect_hint: SimilarCodeSideEffectHint,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SimilarCodeExtractionLimits {
pub max_functions: usize,
pub max_source_bytes_per_function: usize,
pub max_total_source_bytes: usize,
}
impl Default for SimilarCodeExtractionLimits {
fn default() -> Self {
const MAX_FUNCTIONS: usize = 10_000;
const MAX_SOURCE_BYTES_PER_FUNCTION: usize = 64 * 1024;
const MAX_TOTAL_SOURCE_BYTES: usize = 16 * 1024 * 1024;
Self {
max_functions: MAX_FUNCTIONS,
max_source_bytes_per_function: MAX_SOURCE_BYTES_PER_FUNCTION,
max_total_source_bytes: MAX_TOTAL_SOURCE_BYTES,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive]
pub enum SimilarCodeExtractionSkipReason {
NonUtf8Path,
UnsupportedFileType,
DeclarationFile,
GeneratedSource,
SyntaxDiagnostic,
DeclarationWithoutBody,
NestedFunction,
UnsupportedFunctionForm,
InvalidSourceSpan,
SourceBytesPerFunctionLimit,
FunctionLimit,
TotalSourceBytesLimit,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SimilarCodeExtractionSkip {
pub reason: SimilarCodeExtractionSkipReason,
pub count: usize,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SimilarCodeExtraction {
pub extraction_semantics_version: u32,
pub functions: Vec<ExtractedSimilarCodeFunction>,
pub source_bytes: usize,
pub skipped: Vec<SimilarCodeExtractionSkip>,
}