-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathmod.rs
More file actions
101 lines (86 loc) · 2.63 KB
/
Copy pathmod.rs
File metadata and controls
101 lines (86 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
mod analyzer;
mod test;
use std::sync::Arc;
use crate::{
CacheOptions, Emmyrc, FileId, InFiled, InferFailReason, LuaIndex, LuaInferCache, LuaType,
db_index::DbIndex, semantic::SemanticModel,
};
use emmylua_parser::{LuaBlock, LuaExpr};
pub(crate) fn analyze_func_body_missing_return_flags_with<F>(
body: LuaBlock,
infer_expr_type: &mut F,
) -> Result<(bool, bool), InferFailReason>
where
F: FnMut(&LuaExpr) -> Result<LuaType, InferFailReason>,
{
analyzer::analyze_func_body_missing_return_flags_with(body, infer_expr_type)
}
#[derive(Debug)]
pub struct LuaCompilation {
db: DbIndex,
emmyrc: Arc<Emmyrc>,
cache_options: CacheOptions,
}
impl LuaCompilation {
pub fn new(emmyrc: Arc<Emmyrc>) -> Self {
let mut compilation = Self {
db: DbIndex::new(),
emmyrc: emmyrc.clone(),
cache_options: CacheOptions::default(),
};
compilation.db.update_config(emmyrc.clone());
compilation
}
pub fn get_semantic_model(&'_ self, file_id: FileId) -> Option<SemanticModel<'_>> {
let cache = LuaInferCache::new(file_id, self.cache_options);
let tree = self.db.get_vfs().get_syntax_tree(&file_id)?;
Some(SemanticModel::new(
file_id,
&self.db,
cache,
self.emmyrc.clone(),
tree.get_chunk_node(),
))
}
pub fn update_index(&mut self, file_ids: Vec<FileId>) {
let mut need_analyzed_files = vec![];
for file_id in file_ids {
let tree = match self.db.get_vfs().get_syntax_tree(&file_id) {
Some(tree) => tree,
None => {
log::warn!("file_id {:?} not found in vfs", file_id);
continue;
}
};
need_analyzed_files.push(InFiled {
file_id,
value: tree.get_chunk_node(),
});
}
analyzer::analyze(
&mut self.db,
need_analyzed_files,
self.emmyrc.clone(),
self.cache_options,
);
}
pub fn remove_index(&mut self, file_ids: Vec<FileId>) {
self.db.remove_index(file_ids);
}
pub fn clear_index(&mut self) {
self.db.clear();
}
pub fn get_db(&self) -> &DbIndex {
&self.db
}
pub fn get_db_mut(&mut self) -> &mut DbIndex {
&mut self.db
}
pub fn get_cache_options_mut(&mut self) -> &mut CacheOptions {
&mut self.cache_options
}
pub fn update_config(&mut self, config: Arc<Emmyrc>) {
self.emmyrc = config.clone();
self.db.update_config(config);
}
}