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