clangd_parser/
refs.rs

1use crate::symbols::{SymbolId, SymbolLocation, SymbolKind};
2use crate::clangd::ClangdUtility;
3
4use griff::ChunkStream;
5
6#[derive(Debug, Clone, Default)]
7pub struct RefReferences {
8    pub kind: SymbolKind,
9    pub location: SymbolLocation,
10    pub container_id: SymbolId,
11}
12
13#[derive(Debug, Clone, Default)]
14pub struct Refs {
15    pub id: SymbolId,
16    pub cnt: usize,
17    pub refs: Vec<RefReferences>,
18}
19impl ClangdUtility for Refs{}
20
21impl Refs {
22    #[allow(dead_code)]
23    pub fn parse(buf: &ChunkStream, string_table: &Vec<String>) -> Vec<Refs> {
24        let mut refs: Vec<Refs> = vec![];
25        let mut cursor: usize = 0;
26        let data = buf.data.as_slice();
27        if data.len() == 0 {
28            return refs;
29        }
30
31        loop {
32            let mut r: Refs = Default::default();
33            r.id = data.get(cursor..cursor+8).unwrap().try_into().unwrap();
34            cursor += 8;
35            let (sz, content) = Self::get_varint(&data[cursor..]);
36            cursor += sz;
37            for _ in 0..content {
38                let mut rr: RefReferences = Default::default();
39                rr.kind = SymbolKind::from(data[cursor]);
40                cursor += 1;
41                let (sz, loc) = SymbolLocation::get_location(&data.get(cursor..).unwrap(), string_table);
42                rr.location = loc;
43                cursor += sz;
44                rr.container_id = data.get(cursor..cursor+8).unwrap().try_into().unwrap();
45                cursor += 8;
46
47                r.refs.push(rr);
48            }
49
50            refs.push(r);
51            if cursor >= data.len() {
52                break;
53            }
54        }
55        refs
56    }
57}