makepad_live_compiler/
live_document.rs

1//use makepad_id_macros2::*;
2use {
3    std::collections::{BTreeSet, BTreeMap},
4    crate::{
5        span::{TextPos, TextSpan},
6        live_token::{ TokenWithSpan,LiveTokenId},
7        live_node::{LiveNode,LiveNodeOrigin,LiveImport},
8        LiveId,
9        LiveFileId,
10    }
11};
12
13#[derive(Default)]
14pub struct LiveOriginal {
15    pub link: Option<LiveId>,
16    pub identifiers: BTreeSet<LiveId>,
17    pub raw_imports: Vec<(LiveNodeOrigin, LiveImport)>,
18    pub type_imports: BTreeSet<LiveFileId>,
19    pub resolved_imports: Option<BTreeMap<LiveId, LiveFileId>>,
20    pub exports: BTreeMap<LiveId, LiveNodeOrigin>,
21    pub nodes: Vec<LiveNode >,
22    pub edit_info: Vec<LiveNode>,
23    pub tokens: Vec<TokenWithSpan>,
24}
25
26
27#[derive(Default)]
28pub struct LiveExpanded {
29    pub nodes: Vec<LiveNode >,
30}
31
32impl LiveExpanded {
33    pub fn new() -> Self {
34        Self {
35            nodes: Vec::new(),
36        }
37    }
38
39    pub fn resolve_ptr(&self, index: usize) -> &LiveNode {
40        &self.nodes[index]
41    }
42
43}
44
45impl LiveOriginal {
46    pub fn new() -> Self {
47        Self::default()
48    }
49    
50    pub fn resolve_ptr(&self, index: usize) -> &LiveNode {
51        &self.nodes[index]
52    }
53    
54    pub fn get_tokens(&self, token_start: usize, token_count: usize) -> &[TokenWithSpan] {
55        &self.tokens[token_start..(token_start + token_count)]
56    }
57    
58    pub fn find_token_by_pos(&self, pos:TextPos) -> Option<usize> {
59        for (token_index, token) in self.tokens.iter().enumerate() {
60            if pos.line  == token.span.start.line
61                && pos.column >= token.span.start.column
62                && pos.column < token.span.end.column {
63                    return Some(token_index)
64            }
65        }
66        None
67    }
68    
69    
70/*
71    pub fn get_string(&self, string_start: usize, string_count: usize, out:&mut String) {
72        let chunk = &self.strings[string_start..(string_start + string_count)];
73        out.clear();
74        for chr in chunk {
75            out.push(*chr);
76        }
77    }*/
78    
79    pub fn token_id_to_span(&self, token_id: LiveTokenId) -> TextSpan {
80        self.tokens[token_id.token_index()].span
81    }
82}
83
84