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