MCPcopy Create free account
hub / github.com/JaredStewart/coderlm / load_annotations

Function load_annotations

server/src/ops/annotations.rs:85–141  ·  view source on GitHub ↗

Load annotations from `.coderlm/annotations.json` and apply them to the file tree and symbol table.

(
    root: &Path,
    file_tree: &Arc<FileTree>,
    symbol_table: &Arc<SymbolTable>,
)

Source from the content-addressed store, hash-verified

83/// Load annotations from `.coderlm/annotations.json` and apply them
84/// to the file tree and symbol table.
85pub fn load_annotations(
86 root: &Path,
87 file_tree: &Arc<FileTree>,
88 symbol_table: &Arc<SymbolTable>,
89) -> Result<AnnotationData, String> {
90 let annotations_path = root.join(ANNOTATIONS_FILE);
91 if !annotations_path.exists() {
92 return Ok(AnnotationData::default());
93 }
94
95 let json = std::fs::read_to_string(&annotations_path)
96 .map_err(|e| format!("Failed to read annotations: {}", e))?;
97 let data: AnnotationData = serde_json::from_str(&json)
98 .map_err(|e| format!("Failed to parse annotations: {}", e))?;
99
100 // Apply file definitions
101 for (path, def) in &data.file_definitions {
102 if let Some(mut entry) = file_tree.files.get_mut(path.as_str()) {
103 entry.definition = Some(def.clone());
104 } else {
105 debug!("Annotation for missing file: {}", path);
106 }
107 }
108
109 // Apply file marks
110 for (path, marks) in &data.file_marks {
111 if let Some(mut entry) = file_tree.files.get_mut(path.as_str()) {
112 for mark_str in marks {
113 if let Some(mark) = FileMark::from_str(mark_str) {
114 if !entry.marks.contains(&mark) {
115 entry.marks.push(mark);
116 }
117 } else {
118 warn!("Unknown mark '{}' for file '{}'", mark_str, path);
119 }
120 }
121 }
122 }
123
124 // Apply symbol definitions
125 for (key, def) in &data.symbol_definitions {
126 if let Some(mut sym) = symbol_table.symbols.get_mut(key) {
127 sym.definition = Some(def.clone());
128 } else {
129 debug!("Annotation for missing symbol: {}", key);
130 }
131 }
132
133 debug!(
134 "Loaded annotations: {} file defs, {} file marks, {} symbol defs",
135 data.file_definitions.len(),
136 data.file_marks.len(),
137 data.symbol_definitions.len()
138 );
139
140 Ok(data)
141}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected