feat: parse commmand ids from comments

This commit is contained in:
amizing25
2026-01-11 10:08:21 +07:00
parent a6cb0a3502
commit 0f69c0508e
3 changed files with 103 additions and 6 deletions

27
src/generator/utils.rs Normal file
View File

@@ -0,0 +1,27 @@
use protobuf::descriptor::{FileDescriptorProto, source_code_info::Location};
pub struct SourceContext<'a> {
location_map: std::collections::HashMap<Vec<i32>, &'a Location>,
}
impl<'a> SourceContext<'a> {
pub fn new(file: &'a FileDescriptorProto) -> Self {
let mut map = std::collections::HashMap::new();
for loc in &file.source_code_info.location {
map.insert(loc.path.clone(), loc);
}
Self { location_map: map }
}
pub fn get_message_loc(&self, msg_index: usize) -> Option<&Location> {
self.location_map.get(&vec![4, msg_index as i32]).copied()
}
#[expect(unused)]
pub fn get_nested_loc(&self, parent_path: &[i32], nested_index: usize) -> Option<&Location> {
let mut path = parent_path.to_vec();
path.push(3);
path.push(nested_index as i32);
self.location_map.get(&path).copied()
}
}