diff options
Diffstat (limited to 'crates/libanalysis/src')
-rw-r--r-- | crates/libanalysis/src/roots.rs | 23 | ||||
-rw-r--r-- | crates/libanalysis/src/symbol_index.rs | 18 |
2 files changed, 27 insertions, 14 deletions
diff --git a/crates/libanalysis/src/roots.rs b/crates/libanalysis/src/roots.rs index eb14e7567..01de3e128 100644 --- a/crates/libanalysis/src/roots.rs +++ b/crates/libanalysis/src/roots.rs | |||
@@ -59,18 +59,18 @@ impl SourceRoot { | |||
59 | } | 59 | } |
60 | } | 60 | } |
61 | } | 61 | } |
62 | pub(crate) fn symbols(&self) -> Vec<(FileId, &FileSymbols)> { | 62 | pub(crate) fn symbols(&self) -> Vec<&FileSymbols> { |
63 | self.file_map | 63 | self.file_map |
64 | .iter() | 64 | .iter() |
65 | .map(|(&file_id, data)| (file_id, symbols(data))) | 65 | .map(|(&file_id, data)| symbols(file_id, data)) |
66 | .collect() | 66 | .collect() |
67 | } | 67 | } |
68 | pub fn reindex(&self) { | 68 | pub fn reindex(&self) { |
69 | let now = Instant::now(); | 69 | let now = Instant::now(); |
70 | self.file_map | 70 | self.file_map |
71 | .par_iter() | 71 | .par_iter() |
72 | .for_each(|(_, data)| { | 72 | .for_each(|(&file_id, data)| { |
73 | symbols(data); | 73 | symbols(file_id, data); |
74 | }); | 74 | }); |
75 | info!("parallel indexing took {:?}", now.elapsed()); | 75 | info!("parallel indexing took {:?}", now.elapsed()); |
76 | 76 | ||
@@ -83,9 +83,9 @@ impl SourceRoot { | |||
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
86 | fn symbols((data, symbols): &(FileData, OnceCell<FileSymbols>)) -> &FileSymbols { | 86 | fn symbols(file_id: FileId, (data, symbols): &(FileData, OnceCell<FileSymbols>)) -> &FileSymbols { |
87 | let syntax = data.syntax_transient(); | 87 | let syntax = data.syntax_transient(); |
88 | symbols.get_or_init(|| FileSymbols::new(&syntax)) | 88 | symbols.get_or_init(|| FileSymbols::new(file_id, &syntax)) |
89 | } | 89 | } |
90 | 90 | ||
91 | #[derive(Debug)] | 91 | #[derive(Debug)] |
@@ -108,3 +108,14 @@ impl FileData { | |||
108 | .unwrap_or_else(|| File::parse(&self.text)) | 108 | .unwrap_or_else(|| File::parse(&self.text)) |
109 | } | 109 | } |
110 | } | 110 | } |
111 | |||
112 | // #[derive(Clone, Default, Debug)] | ||
113 | // pub(crate) struct ReadonlySourceRoot { | ||
114 | // data: Arc<ReadonlySourceRoot> | ||
115 | // } | ||
116 | |||
117 | // #[derive(Clone, Default, Debug)] | ||
118 | // pub(crate) struct ReadonlySourceRootInner { | ||
119 | // file_map: HashMap<FileId, FileData>, | ||
120 | // module_map: ModuleMap, | ||
121 | // } | ||
diff --git a/crates/libanalysis/src/symbol_index.rs b/crates/libanalysis/src/symbol_index.rs index 2cad3f6eb..54952cb94 100644 --- a/crates/libanalysis/src/symbol_index.rs +++ b/crates/libanalysis/src/symbol_index.rs | |||
@@ -8,12 +8,12 @@ use {Query, FileId, JobToken}; | |||
8 | 8 | ||
9 | #[derive(Debug)] | 9 | #[derive(Debug)] |
10 | pub(crate) struct FileSymbols { | 10 | pub(crate) struct FileSymbols { |
11 | symbols: Vec<FileSymbol>, | 11 | symbols: Vec<(FileId, FileSymbol)>, |
12 | map: fst::Map, | 12 | map: fst::Map, |
13 | } | 13 | } |
14 | 14 | ||
15 | impl FileSymbols { | 15 | impl FileSymbols { |
16 | pub(crate) fn new(file: &File) -> FileSymbols { | 16 | pub(crate) fn new(file_id: FileId, file: &File) -> FileSymbols { |
17 | let mut symbols = file_symbols(file) | 17 | let mut symbols = file_symbols(file) |
18 | .into_iter() | 18 | .into_iter() |
19 | .map(|s| (s.name.as_str().to_lowercase(), s)) | 19 | .map(|s| (s.name.as_str().to_lowercase(), s)) |
@@ -21,8 +21,10 @@ impl FileSymbols { | |||
21 | 21 | ||
22 | symbols.sort_by(|s1, s2| s1.0.cmp(&s2.0)); | 22 | symbols.sort_by(|s1, s2| s1.0.cmp(&s2.0)); |
23 | symbols.dedup_by(|s1, s2| s1.0 == s2.0); | 23 | symbols.dedup_by(|s1, s2| s1.0 == s2.0); |
24 | let (names, symbols): (Vec<String>, Vec<FileSymbol>) = | 24 | let (names, symbols): (Vec<String>, Vec<(FileId, FileSymbol)>) = |
25 | symbols.into_iter().unzip(); | 25 | symbols.into_iter() |
26 | .map(|(name, symbol)| (name, (file_id, symbol))) | ||
27 | .unzip(); | ||
26 | 28 | ||
27 | let map = fst::Map::from_iter( | 29 | let map = fst::Map::from_iter( |
28 | names.into_iter().zip(0u64..) | 30 | names.into_iter().zip(0u64..) |
@@ -34,12 +36,12 @@ impl FileSymbols { | |||
34 | impl Query { | 36 | impl Query { |
35 | pub(crate) fn search( | 37 | pub(crate) fn search( |
36 | mut self, | 38 | mut self, |
37 | indices: &[(FileId, &FileSymbols)], | 39 | indices: &[&FileSymbols], |
38 | token: &JobToken, | 40 | token: &JobToken, |
39 | ) -> Vec<(FileId, FileSymbol)> { | 41 | ) -> Vec<(FileId, FileSymbol)> { |
40 | 42 | ||
41 | let mut op = fst::map::OpBuilder::new(); | 43 | let mut op = fst::map::OpBuilder::new(); |
42 | for (_, file_symbols) in indices.iter() { | 44 | for file_symbols in indices.iter() { |
43 | let automaton = fst::automaton::Subsequence::new(&self.lowercased); | 45 | let automaton = fst::automaton::Subsequence::new(&self.lowercased); |
44 | op = op.add(file_symbols.map.search(automaton)) | 46 | op = op.add(file_symbols.map.search(automaton)) |
45 | } | 47 | } |
@@ -50,10 +52,10 @@ impl Query { | |||
50 | break; | 52 | break; |
51 | } | 53 | } |
52 | for indexed_value in indexed_values { | 54 | for indexed_value in indexed_values { |
53 | let (file_id, file_symbols) = &indices[indexed_value.index]; | 55 | let file_symbols = &indices[indexed_value.index]; |
54 | let idx = indexed_value.value as usize; | 56 | let idx = indexed_value.value as usize; |
55 | 57 | ||
56 | let symbol = &file_symbols.symbols[idx]; | 58 | let (file_id, symbol) = &file_symbols.symbols[idx]; |
57 | if self.only_types && !is_type(symbol.kind) { | 59 | if self.only_types && !is_type(symbol.kind) { |
58 | continue; | 60 | continue; |
59 | } | 61 | } |