diff options
author | Jeremy A. Kolb <[email protected]> | 2018-10-15 22:44:23 +0100 |
---|---|---|
committer | Jeremy A. Kolb <[email protected]> | 2018-10-16 14:41:10 +0100 |
commit | 61f3a438d3a729a6be941bca1ff4c6a97a33f221 (patch) | |
tree | 6551967cc8c6e921b66071453ad7888a9121d326 /crates/ra_analysis/src/roots.rs | |
parent | 39cb6c6d3f78b193f5873c3492e530bbd24d5dd2 (diff) |
Cargo Format
Run `cargo fmt` and ignore generated files
Diffstat (limited to 'crates/ra_analysis/src/roots.rs')
-rw-r--r-- | crates/ra_analysis/src/roots.rs | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/crates/ra_analysis/src/roots.rs b/crates/ra_analysis/src/roots.rs index 76bcecd38..1f2b21b27 100644 --- a/crates/ra_analysis/src/roots.rs +++ b/crates/ra_analysis/src/roots.rs | |||
@@ -1,22 +1,19 @@ | |||
1 | use std::{ | 1 | use std::{panic, sync::Arc}; |
2 | sync::Arc, | ||
3 | panic, | ||
4 | }; | ||
5 | 2 | ||
6 | use once_cell::sync::OnceCell; | 3 | use once_cell::sync::OnceCell; |
7 | use rayon::prelude::*; | ||
8 | use salsa::Database; | ||
9 | use rustc_hash::{FxHashMap, FxHashSet}; | ||
10 | use ra_editor::LineIndex; | 4 | use ra_editor::LineIndex; |
11 | use ra_syntax::File; | 5 | use ra_syntax::File; |
6 | use rayon::prelude::*; | ||
7 | use rustc_hash::{FxHashMap, FxHashSet}; | ||
8 | use salsa::Database; | ||
12 | 9 | ||
13 | use crate::{ | 10 | use crate::{ |
14 | FileId, | ||
15 | imp::FileResolverImp, | ||
16 | symbol_index::SymbolIndex, | ||
17 | descriptors::{ModuleDescriptor, ModuleTreeDescriptor}, | ||
18 | db::{self, FilesDatabase, SyntaxDatabase}, | 11 | db::{self, FilesDatabase, SyntaxDatabase}, |
12 | descriptors::{ModuleDescriptor, ModuleTreeDescriptor}, | ||
13 | imp::FileResolverImp, | ||
19 | module_map::ModulesDatabase, | 14 | module_map::ModulesDatabase, |
15 | symbol_index::SymbolIndex, | ||
16 | FileId, | ||
20 | }; | 17 | }; |
21 | 18 | ||
22 | pub(crate) trait SourceRoot { | 19 | pub(crate) trait SourceRoot { |
@@ -35,7 +32,7 @@ pub(crate) struct WritableSourceRoot { | |||
35 | impl WritableSourceRoot { | 32 | impl WritableSourceRoot { |
36 | pub fn apply_changes( | 33 | pub fn apply_changes( |
37 | &mut self, | 34 | &mut self, |
38 | changes: &mut dyn Iterator<Item=(FileId, Option<String>)>, | 35 | changes: &mut dyn Iterator<Item = (FileId, Option<String>)>, |
39 | file_resolver: Option<FileResolverImp>, | 36 | file_resolver: Option<FileResolverImp>, |
40 | ) { | 37 | ) { |
41 | let mut changed = FxHashSet::default(); | 38 | let mut changed = FxHashSet::default(); |
@@ -46,22 +43,22 @@ impl WritableSourceRoot { | |||
46 | removed.insert(file_id); | 43 | removed.insert(file_id); |
47 | } | 44 | } |
48 | Some(text) => { | 45 | Some(text) => { |
49 | self.db.query(db::FileTextQuery) | 46 | self.db |
47 | .query(db::FileTextQuery) | ||
50 | .set(file_id, Arc::new(text)); | 48 | .set(file_id, Arc::new(text)); |
51 | changed.insert(file_id); | 49 | changed.insert(file_id); |
52 | } | 50 | } |
53 | } | 51 | } |
54 | } | 52 | } |
55 | let file_set = self.db.file_set(()); | 53 | let file_set = self.db.file_set(()); |
56 | let mut files: FxHashSet<FileId> = file_set | 54 | let mut files: FxHashSet<FileId> = file_set.files.clone(); |
57 | .files | ||
58 | .clone(); | ||
59 | for file_id in removed { | 55 | for file_id in removed { |
60 | files.remove(&file_id); | 56 | files.remove(&file_id); |
61 | } | 57 | } |
62 | files.extend(changed); | 58 | files.extend(changed); |
63 | let resolver = file_resolver.unwrap_or_else(|| file_set.resolver.clone()); | 59 | let resolver = file_resolver.unwrap_or_else(|| file_set.resolver.clone()); |
64 | self.db.query(db::FileSetQuery) | 60 | self.db |
61 | .query(db::FileSetQuery) | ||
65 | .set((), Arc::new(db::FileSet { files, resolver })); | 62 | .set((), Arc::new(db::FileSet { files, resolver })); |
66 | } | 63 | } |
67 | } | 64 | } |
@@ -71,9 +68,7 @@ impl SourceRoot for WritableSourceRoot { | |||
71 | self.db.module_tree(()) | 68 | self.db.module_tree(()) |
72 | } | 69 | } |
73 | fn contains(&self, file_id: FileId) -> bool { | 70 | fn contains(&self, file_id: FileId) -> bool { |
74 | self.db.file_set(()) | 71 | self.db.file_set(()).files.contains(&file_id) |
75 | .files | ||
76 | .contains(&file_id) | ||
77 | } | 72 | } |
78 | fn lines(&self, file_id: FileId) -> Arc<LineIndex> { | 73 | fn lines(&self, file_id: FileId) -> Arc<LineIndex> { |
79 | self.db.file_lines(file_id) | 74 | self.db.file_lines(file_id) |
@@ -83,7 +78,7 @@ impl SourceRoot for WritableSourceRoot { | |||
83 | } | 78 | } |
84 | fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) { | 79 | fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) { |
85 | let db = &self.db; | 80 | let db = &self.db; |
86 | let symbols = db.file_set(()); | 81 | let symbols = db.file_set(()); |
87 | let symbols = symbols | 82 | let symbols = symbols |
88 | .files | 83 | .files |
89 | .iter() | 84 | .iter() |
@@ -108,12 +103,15 @@ impl FileData { | |||
108 | } | 103 | } |
109 | } | 104 | } |
110 | fn lines(&self) -> &Arc<LineIndex> { | 105 | fn lines(&self) -> &Arc<LineIndex> { |
111 | self.lines.get_or_init(|| Arc::new(LineIndex::new(&self.text))) | 106 | self.lines |
107 | .get_or_init(|| Arc::new(LineIndex::new(&self.text))) | ||
112 | } | 108 | } |
113 | fn syntax(&self) -> &File { | 109 | fn syntax(&self) -> &File { |
114 | let text = &self.text; | 110 | let text = &self.text; |
115 | let syntax = &self.syntax; | 111 | let syntax = &self.syntax; |
116 | match panic::catch_unwind(panic::AssertUnwindSafe(|| syntax.get_or_init(|| File::parse(text)))) { | 112 | match panic::catch_unwind(panic::AssertUnwindSafe(|| { |
113 | syntax.get_or_init(|| File::parse(text)) | ||
114 | })) { | ||
117 | Ok(file) => file, | 115 | Ok(file) => file, |
118 | Err(err) => { | 116 | Err(err) => { |
119 | error!("Parser paniced on:\n------\n{}\n------\n", text); | 117 | error!("Parser paniced on:\n------\n{}\n------\n", text); |
@@ -131,22 +129,23 @@ pub(crate) struct ReadonlySourceRoot { | |||
131 | } | 129 | } |
132 | 130 | ||
133 | impl ReadonlySourceRoot { | 131 | impl ReadonlySourceRoot { |
134 | pub(crate) fn new(files: Vec<(FileId, String)>, file_resolver: FileResolverImp) -> ReadonlySourceRoot { | 132 | pub(crate) fn new( |
135 | let modules = files.par_iter() | 133 | files: Vec<(FileId, String)>, |
134 | file_resolver: FileResolverImp, | ||
135 | ) -> ReadonlySourceRoot { | ||
136 | let modules = files | ||
137 | .par_iter() | ||
136 | .map(|(file_id, text)| { | 138 | .map(|(file_id, text)| { |
137 | let syntax = File::parse(text); | 139 | let syntax = File::parse(text); |
138 | let mod_descr = ModuleDescriptor::new(syntax.ast()); | 140 | let mod_descr = ModuleDescriptor::new(syntax.ast()); |
139 | (*file_id, syntax, mod_descr) | 141 | (*file_id, syntax, mod_descr) |
140 | }) | 142 | }) |
141 | .collect::<Vec<_>>(); | 143 | .collect::<Vec<_>>(); |
142 | let module_tree = ModuleTreeDescriptor::new( | 144 | let module_tree = |
143 | modules.iter().map(|it| (it.0, &it.2)), | 145 | ModuleTreeDescriptor::new(modules.iter().map(|it| (it.0, &it.2)), &file_resolver); |
144 | &file_resolver, | ||
145 | ); | ||
146 | 146 | ||
147 | let symbol_index = SymbolIndex::for_files( | 147 | let symbol_index = |
148 | modules.par_iter().map(|it| (it.0, it.1.clone())) | 148 | SymbolIndex::for_files(modules.par_iter().map(|it| (it.0, it.1.clone()))); |
149 | ); | ||
150 | let file_map: FxHashMap<FileId, FileData> = files | 149 | let file_map: FxHashMap<FileId, FileData> = files |
151 | .into_iter() | 150 | .into_iter() |
152 | .map(|(id, text)| (id, FileData::new(text))) | 151 | .map(|(id, text)| (id, FileData::new(text))) |