feat: parse commmand ids from comments
This commit is contained in:
27
src/generator/utils.rs
Normal file
27
src/generator/utils.rs
Normal 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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user