colgrep 1.3.0

Semantic code search powered by ColBERT
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//! Common test utilities and helper functions.

use crate::parser::{extract_units, CodeUnit, Language};
use std::path::Path;

/// Helper to extract units from source code with a given language.
pub fn parse(source: &str, lang: Language, filename: &str) -> Vec<CodeUnit> {
    extract_units(Path::new(filename), source, lang)
}

/// Get the first unit with the given name.
pub fn get_unit_by_name<'a>(units: &'a [CodeUnit], name: &str) -> Option<&'a CodeUnit> {
    units.iter().find(|u| u.name == name)
}