vtcode_commons/
at_pattern.rs1use regex::Regex;
4use std::sync::LazyLock;
5
6pub static AT_PATTERN_REGEX: LazyLock<Regex> = LazyLock::new(|| {
9 match Regex::new(r#"@(?:\"([^\"]+)\"|'([^']+)'|([^\s"'\[\](){}<>|\\^`]+))"#) {
10 Ok(regex) => regex,
11 Err(error) => panic!("Failed to compile @ pattern regex: {error}"),
12 }
13});
14
15#[derive(Debug, Clone, PartialEq, Eq)]
17pub struct AtPatternMatch<'a> {
18 pub full_match: &'a str,
20 pub path: &'a str,
22 pub start: usize,
24 pub end: usize,
26}
27
28pub fn find_at_patterns(text: &str) -> Vec<AtPatternMatch<'_>> {
30 AT_PATTERN_REGEX
31 .captures_iter(text)
32 .filter_map(|cap| {
33 let full_match = cap.get(0)?;
34 let path_part = cap.get(1).or_else(|| cap.get(2)).or_else(|| cap.get(3))?;
35
36 Some(AtPatternMatch {
37 full_match: full_match.as_str(),
38 path: path_part.as_str(),
39 start: full_match.start(),
40 end: full_match.end(),
41 })
42 })
43 .collect()
44}