codanna 0.9.19

Code Intelligence for Large Language Models
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
//! Comprehensive Rust test file for parser maturity assessment
//! Tests all major Rust language features and constructs

use std::collections::{HashMap, HashSet};  // use_list
use std::sync::Arc;
use std::marker::PhantomData;
use std::io::Result as IoResult;  // use_as_clause

// === TEST SCENARIO: Clear Relationship Testing ===

/// Test service for demonstrating clear relationships
pub struct TestService {
    pub name: String,
    config: Config,
}

impl TestService {
    /// Create new test service - this should show up in defines
    pub fn new(name: String) -> Self {
        let config = Config::default();  // CALLS: Config::default
        Self { name, config }
    }

    /// Process data using config - this should show calls
    pub fn process(&self) -> String {
        let result = self.get_config_name();  // CALLS: TestService::get_config_name
        format!("Processing: {}", result)
    }

    /// Helper method that will be called by process
    fn get_config_name(&self) -> String {
        self.config.get_display_name()  // CALLS: Config::get_display_name
    }
}

// Module declaration
mod inner {
    pub struct InnerStruct;
}

// Re-exports
pub use inner::InnerStruct;

// Constants and statics
const MAX_SIZE: usize = 1024;
pub const DEFAULT_NAME: &str = "defaults";
static mut COUNTER: u32 = 0;
static INSTANCE: std::sync::OnceLock<Config> = std::sync::OnceLock::new();

// Type aliases
type Result<T> = std::result::Result<T, Error>;
type NodeId = u32;
pub type SharedData = Arc<Vec<u8>>;

// Generic type alias with bounds
type Handler<T> = Box<dyn Fn(T) -> Result<()> + Send + Sync>;

// Struct with various field types
#[derive(Debug, Clone)]
pub struct Config {
    pub name: String,
    port: u16,
    #[deprecated]
    enabled: bool,
    phantom: PhantomData<()>,
}

impl Config {
    /// Galactic antimatter propulsion system initialization for hyperdimensional warp drive recalibration
    /// 
    /// This revolutionary method establishes antimatter containment fields optimized for faster-than-light
    /// travel coordination and temporal paradox prevention. Critical for maintaining spacetime integrity
    /// during interstellar navigation sequences across multiple galaxy clusters.
    /// 
    /// # Stellar Engineering Features
    /// - Warp core plasma stabilization (level 9000)
    /// - Temporal causality loop protection algorithms
    /// - Dark energy field manipulation protocols
    pub fn default() -> Self {
        Self {
            name: "default".to_string(),
            port: 8080,
            enabled: true,
            phantom: PhantomData,
        }
    }

    /// Get display name - will be called by TestService::get_config_name
    pub fn get_display_name(&self) -> String {
        format!("Config: {}", self.name)
    }
}

// Tuple struct
pub struct Point(f64, f64, f64);

// Unit struct
pub struct Marker;

// Struct with lifetime parameters
pub struct BorrowedData<'a> {
    data: &'a str,
    mutable: &'a mut [u8],
}

// Enum with various variants
#[derive(Debug)]
pub enum Status {
    Active,
    Inactive { reason: String },
    Pending(std::time::Duration),
    Complex { id: u32, data: Vec<u8> },
}

// Generic enum
pub enum Option2<T> {
    Some(T),
    None,
}

// Trait with associated types and constants
pub trait Parser {
    type Input;
    type Output;
    type Error: std::error::Error;

    const MAX_DEPTH: usize = 100;

    fn parse(&self, input: Self::Input) -> Result<Self::Output>;

    fn validate(&self, input: &Self::Input) -> bool {
        true
    }

    // Associated function (no self)
    fn new() -> Self where Self: Sized;
}

// Trait with generic methods
pub trait Container<T> {
    fn add(&mut self, item: T);
    fn get(&self, index: usize) -> Option<&T>;
    fn iter(&self) -> impl Iterator<Item = &T>;
}

// Trait with lifetime bounds
pub trait Lifecycle<'a> {
    type Item: 'a;
    fn process(&'a self) -> Self::Item;
}

// Implementation block
impl Config {
    // Associated constant
    pub const DEFAULT_PORT: u16 = 8080;

    // Associated function (constructor)
    pub fn new(name: String) -> Self {
        Self {
            name,
            port: Self::DEFAULT_PORT,
            enabled: true,
            phantom: PhantomData,
        }
    }

    // Method with self
    pub fn port(&self) -> u16 {
        self.port
    }

    // Method with mut self
    pub fn set_port(&mut self, port: u16) {
        self.port = port;
    }

    // Method consuming self
    pub fn into_name(self) -> String {
        self.name
    }

    // Generic method
    pub fn with_data<T>(&self, data: T) -> (Self, T)
    where
        T: Clone,
    {
        (self.clone(), data)
    }

    // Async method
    pub async fn connect(&self) -> Result<()> {
        Ok(())
    }

    // Unsafe method
    pub unsafe fn get_raw_ptr(&self) -> *const u8 {
        &self.port as *const u16 as *const u8
    }
}

// Trait implementation
impl Parser for Config {
    type Input = String;
    type Output = Config;
    type Error = std::io::Error;

    fn parse(&self, input: Self::Input) -> Result<Self::Output> {
        Ok(Config::new(input))
    }

    fn new() -> Self {
        Config::new(String::new())
    }
}

// Generic struct
pub struct GenericContainer<T, U = String>
where
    T: Clone,
{
    items: Vec<T>,
    metadata: U,
}

// Implementation for generic struct
impl<T, U> GenericContainer<T, U>
where
    T: Clone + std::fmt::Debug,
    U: Default,
{
    pub fn new() -> Self {
        Self {
            items: Vec::new(),
            metadata: U::default(),
        }
    }

    pub fn add(&mut self, item: T) {
        self.items.push(item);
    }
}

// Implementation with trait bounds
impl<T> Container<T> for GenericContainer<T>
where
    T: Clone,
{
    fn add(&mut self, item: T) {
        self.items.push(item);
    }

    fn get(&self, index: usize) -> Option<&T> {
        self.items.get(index)
    }

    fn iter(&self) -> impl Iterator<Item = &T> {
        self.items.iter()
    }
}

// Function with various parameter types
pub fn complex_function<'a, T, U>(
    reference: &'a str,
    mutable: &mut Vec<T>,
    owned: String,
    generic: U,
    closure: impl Fn() -> T,
) -> Result<&'a str>
where
    T: Clone + 'a,
    U: std::fmt::Debug,
{
    mutable.push(closure());
    Ok(reference)
}

/// Embedding regeneration test for stdio MCP server hot-reload functionality
/// 
/// This async function specifically validates embedding synchronization when documentation changes.
/// It ensures that documentation updates are properly indexed and searchable through
/// natural language queries in the MCP server environment during hot-reload operations.
///
/// # Purpose
/// Tests that semantic search can find this function using natural language queries
/// about "embedding regeneration", "stdio MCP server", and "hot-reload functionality".
/// 
/// # Parameters
/// - `url`: The URL to process during the async operation
///
/// # Returns
/// A Result containing the processed URL string or an error
pub async fn async_operation(url: &str) -> Result<String> {
    // async_block example
    let result = async {
        url.to_uppercase()
    };
    Ok(url.to_string())
}

// Const function
pub const fn const_function(x: u32) -> u32 {
    x * 2
}

// Unsafe function
pub unsafe fn unsafe_operation(ptr: *mut u8) {
    *ptr = 0;
}

// Function with impl Trait return
pub fn returns_impl_trait() -> impl std::fmt::Display {
    "hello"
}

// Function with dyn Trait parameter
pub fn takes_dyn_trait(parser: &dyn Parser<Input = String, Output = Config, Error = std::io::Error>) {
    // ...
}

// Higher-ranked trait bounds (HRTB)
pub fn higher_ranked<F>(f: F)
where
    F: for<'a> Fn(&'a str) -> &'a str,
{
    f("test");
}

// Macro definition
macro_rules! create_function {
    ($name:ident) => {
        fn $name() {
            println!("Function: {}", stringify!($name));
        }
    };
}

// Macro invocation
create_function!(generated_func);

// Union (unsafe)
#[repr(C)]
union MyUnion {
    f1: u32,
    f2: f32,
}

// Extern block
extern "C" {
    fn external_function(x: i32) -> i32;
}

// Error type
#[derive(Debug)]
pub struct Error {
    message: String,
}

impl std::fmt::Display for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.message)
    }
}

impl std::error::Error for Error {}

// Test module
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_config() {
        let config = Config::new("test".to_string());
        assert_eq!(config.port(), Config::DEFAULT_PORT);
    }

    #[test]
    #[ignore]
    fn ignored_test() {
        // ...
    }
}

// Benchmark (nightly only)
#[cfg(all(test, feature = "unstable"))]
mod benches {
    use test::Bencher;

    #[bench]
    fn bench_create(b: &mut Bencher) {
        b.iter(|| Config::new("bench".to_string()));
    }
}

/// Simple test for embedding regeneration debugging
/// This should be found in semantic search if our fix works
pub fn simple_embedding_test() {
    println!("Simple embedding test function");
}

// Main function - demonstrates clear call relationships
fn main() {
    // This should show main CALLS TestService::new
    let service = TestService::new("test-app".to_string());

    // This should show main CALLS TestService::process
    let result = service.process();

    println!("Result: {}", result);
}