Skip to main content

marco_core/intelligence/editor/
completion.rs

1//! Markdown completion helpers.
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4/// A single completion candidate returned to editor integrations.
5pub struct CompletionItem {
6    /// User-visible completion label.
7    pub label: String,
8    /// Text inserted into the document when completion is accepted.
9    pub insert_text: String,
10    /// Optional short detail describing completion origin/type.
11    pub detail: String,
12}
13
14/// Return markdown completions for the given query.
15///
16/// Current implementation provides emoji shortcode completion and is designed
17/// to be extended with markdown-structural completions.
18pub fn get_markdown_completions(query: &str) -> Vec<CompletionItem> {
19    crate::logic::text_completion::emoji_completion_items()
20        .iter()
21        .filter(|item| {
22            crate::logic::text_completion::emoji_shortcode_matches_query(&item.shortcode, query)
23        })
24        .map(|item| CompletionItem {
25            label: item.display.clone(),
26            insert_text: item.shortcode.clone(),
27            detail: "Emoji shortcode".to_string(),
28        })
29        .collect()
30}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35
36    #[test]
37    fn smoke_test_get_markdown_completions_empty_query_returns_all() {
38        let items = get_markdown_completions("");
39        assert!(
40            !items.is_empty(),
41            "empty query should return all emoji completions"
42        );
43        // All items must have non-empty insert_text and label
44        for item in &items {
45            assert!(
46                !item.insert_text.is_empty(),
47                "insert_text must not be empty"
48            );
49            assert!(!item.label.is_empty(), "label must not be empty");
50            assert_eq!(item.detail, "Emoji shortcode");
51        }
52    }
53
54    #[test]
55    fn smoke_test_get_markdown_completions_filters_by_prefix() {
56        let smile_items = get_markdown_completions("smile");
57        assert!(
58            !smile_items.is_empty(),
59            "query 'smile' should match at least one emoji shortcode"
60        );
61        // All returned items should have 'smile' in their shortcode
62        for item in &smile_items {
63            assert!(
64                item.insert_text.contains("smile"),
65                "shortcode '{}' should contain 'smile'",
66                item.insert_text
67            );
68        }
69    }
70
71    #[test]
72    fn smoke_test_get_markdown_completions_unknown_query_returns_empty() {
73        let items = get_markdown_completions("xyzzy_no_such_emoji_exists_42");
74        assert!(
75            items.is_empty(),
76            "nonsense query should return no completions"
77        );
78    }
79}