makepad_live_compiler/
live_document.rs

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