diff options
author | Aleksey Kladov <[email protected]> | 2018-11-07 15:42:30 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-11-07 15:42:36 +0000 |
commit | 22949dab267bf7b8b3da73fe7745a12daca21a52 (patch) | |
tree | 7a55032e56163968e68f2aaff28c8f4aef477422 /crates | |
parent | 2ed1514df3f8837ccebdbbfdadbe89e79b4a4365 (diff) |
rename module source
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_analysis/src/completion.rs | 9 | ||||
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/imp.rs | 16 | ||||
-rw-r--r-- | crates/ra_analysis/src/descriptors/module/mod.rs | 31 | ||||
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 8 |
4 files changed, 32 insertions, 32 deletions
diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs index ea15f239c..6fd30aaee 100644 --- a/crates/ra_analysis/src/completion.rs +++ b/crates/ra_analysis/src/completion.rs | |||
@@ -34,10 +34,11 @@ pub(crate) fn resolve_based_completion( | |||
34 | let source_root_id = db.file_source_root(position.file_id); | 34 | let source_root_id = db.file_source_root(position.file_id); |
35 | let file = db.file_syntax(position.file_id); | 35 | let file = db.file_syntax(position.file_id); |
36 | let module_tree = db.module_tree(source_root_id)?; | 36 | let module_tree = db.module_tree(source_root_id)?; |
37 | let module_id = match module_tree.any_module_for_source(ModuleSource::File(position.file_id)) { | 37 | let module_id = |
38 | None => return Ok(None), | 38 | match module_tree.any_module_for_source(ModuleSource::SourceFile(position.file_id)) { |
39 | Some(it) => it, | 39 | None => return Ok(None), |
40 | }; | 40 | Some(it) => it, |
41 | }; | ||
41 | let file = { | 42 | let file = { |
42 | let edit = AtomEdit::insert(position.offset, "intellijRulezz".to_string()); | 43 | let edit = AtomEdit::insert(position.offset, "intellijRulezz".to_string()); |
43 | file.reparse(&edit) | 44 | file.reparse(&edit) |
diff --git a/crates/ra_analysis/src/descriptors/module/imp.rs b/crates/ra_analysis/src/descriptors/module/imp.rs index b5c232ea4..ade96ddc0 100644 --- a/crates/ra_analysis/src/descriptors/module/imp.rs +++ b/crates/ra_analysis/src/descriptors/module/imp.rs | |||
@@ -41,8 +41,8 @@ pub(crate) fn submodules( | |||
41 | db::check_canceled(db)?; | 41 | db::check_canceled(db)?; |
42 | let file_id = source.file_id(); | 42 | let file_id = source.file_id(); |
43 | let submodules = match source.resolve(db) { | 43 | let submodules = match source.resolve(db) { |
44 | ModuleSourceNode::Root(it) => collect_submodules(file_id, it.borrowed()), | 44 | ModuleSourceNode::SourceFile(it) => collect_submodules(file_id, it.borrowed()), |
45 | ModuleSourceNode::Inline(it) => it | 45 | ModuleSourceNode::Module(it) => it |
46 | .borrowed() | 46 | .borrowed() |
47 | .item_list() | 47 | .item_list() |
48 | .map(|it| collect_submodules(file_id, it)) | 48 | .map(|it| collect_submodules(file_id, it)) |
@@ -89,8 +89,8 @@ pub(crate) fn module_scope( | |||
89 | let tree = db.module_tree(source_root_id)?; | 89 | let tree = db.module_tree(source_root_id)?; |
90 | let source = module_id.source(&tree).resolve(db); | 90 | let source = module_id.source(&tree).resolve(db); |
91 | let res = match source { | 91 | let res = match source { |
92 | ModuleSourceNode::Root(root) => ModuleScope::new(root.borrowed().items()), | 92 | ModuleSourceNode::SourceFile(it) => ModuleScope::new(it.borrowed().items()), |
93 | ModuleSourceNode::Inline(inline) => match inline.borrowed().item_list() { | 93 | ModuleSourceNode::Module(it) => match it.borrowed().item_list() { |
94 | Some(items) => ModuleScope::new(items.items()), | 94 | Some(items) => ModuleScope::new(items.items()), |
95 | None => ModuleScope::new(std::iter::empty()), | 95 | None => ModuleScope::new(std::iter::empty()), |
96 | }, | 96 | }, |
@@ -121,7 +121,7 @@ fn create_module_tree<'a>( | |||
121 | 121 | ||
122 | let source_root = db.source_root(source_root); | 122 | let source_root = db.source_root(source_root); |
123 | for &file_id in source_root.files.iter() { | 123 | for &file_id in source_root.files.iter() { |
124 | let source = ModuleSource::File(file_id); | 124 | let source = ModuleSource::SourceFile(file_id); |
125 | if visited.contains(&source) { | 125 | if visited.contains(&source) { |
126 | continue; // TODO: use explicit crate_roots here | 126 | continue; // TODO: use explicit crate_roots here |
127 | } | 127 | } |
@@ -181,7 +181,7 @@ fn build_subtree( | |||
181 | visited, | 181 | visited, |
182 | roots, | 182 | roots, |
183 | Some(link), | 183 | Some(link), |
184 | ModuleSource::File(file_id), | 184 | ModuleSource::SourceFile(file_id), |
185 | ), | 185 | ), |
186 | }) | 186 | }) |
187 | .collect::<Cancelable<Vec<_>>>()?; | 187 | .collect::<Cancelable<Vec<_>>>()?; |
@@ -213,8 +213,8 @@ fn resolve_submodule( | |||
213 | file_resolver: &FileResolverImp, | 213 | file_resolver: &FileResolverImp, |
214 | ) -> (Vec<FileId>, Option<Problem>) { | 214 | ) -> (Vec<FileId>, Option<Problem>) { |
215 | let file_id = match source { | 215 | let file_id = match source { |
216 | ModuleSource::File(it) => it, | 216 | ModuleSource::SourceFile(it) => it, |
217 | ModuleSource::Inline(..) => { | 217 | ModuleSource::Module(..) => { |
218 | // TODO | 218 | // TODO |
219 | return (Vec::new(), None); | 219 | return (Vec::new(), None); |
220 | } | 220 | } |
diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index 5301f44ab..58d6abed3 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs | |||
@@ -41,19 +41,18 @@ impl ModuleTree { | |||
41 | 41 | ||
42 | /// `ModuleSource` is the syntax tree element that produced this module: | 42 | /// `ModuleSource` is the syntax tree element that produced this module: |
43 | /// either a file, or an inlinde module. | 43 | /// either a file, or an inlinde module. |
44 | /// TODO: we don't produce Inline modules yet | ||
45 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 44 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
46 | pub(crate) enum ModuleSource { | 45 | pub(crate) enum ModuleSource { |
47 | File(FileId), | 46 | SourceFile(FileId), |
48 | #[allow(dead_code)] | 47 | #[allow(dead_code)] |
49 | Inline(SyntaxPtr), | 48 | Module(SyntaxPtr), |
50 | } | 49 | } |
51 | 50 | ||
52 | /// An owned syntax node for a module. Unlike `ModuleSource`, | 51 | /// An owned syntax node for a module. Unlike `ModuleSource`, |
53 | /// this holds onto the AST for the whole file. | 52 | /// this holds onto the AST for the whole file. |
54 | enum ModuleSourceNode { | 53 | enum ModuleSourceNode { |
55 | Root(ast::SourceFileNode), | 54 | SourceFile(ast::SourceFileNode), |
56 | Inline(ast::ModuleNode), | 55 | Module(ast::ModuleNode), |
57 | } | 56 | } |
58 | 57 | ||
59 | #[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] | 58 | #[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] |
@@ -135,14 +134,14 @@ impl LinkId { | |||
135 | ) -> ast::ModuleNode { | 134 | ) -> ast::ModuleNode { |
136 | let owner = self.owner(tree); | 135 | let owner = self.owner(tree); |
137 | match owner.source(tree).resolve(db) { | 136 | match owner.source(tree).resolve(db) { |
138 | ModuleSourceNode::Root(root) => { | 137 | ModuleSourceNode::SourceFile(root) => { |
139 | let ast = imp::modules(root.borrowed()) | 138 | let ast = imp::modules(root.borrowed()) |
140 | .find(|(name, _)| name == &tree.link(self).name) | 139 | .find(|(name, _)| name == &tree.link(self).name) |
141 | .unwrap() | 140 | .unwrap() |
142 | .1; | 141 | .1; |
143 | ast.owned() | 142 | ast.owned() |
144 | } | 143 | } |
145 | ModuleSourceNode::Inline(it) => it, | 144 | ModuleSourceNode::Module(it) => it, |
146 | } | 145 | } |
147 | } | 146 | } |
148 | } | 147 | } |
@@ -158,34 +157,34 @@ impl ModuleSource { | |||
158 | pub(crate) fn new_inline(file_id: FileId, module: ast::Module) -> ModuleSource { | 157 | pub(crate) fn new_inline(file_id: FileId, module: ast::Module) -> ModuleSource { |
159 | assert!(!module.has_semi()); | 158 | assert!(!module.has_semi()); |
160 | let ptr = SyntaxPtr::new(file_id, module.syntax()); | 159 | let ptr = SyntaxPtr::new(file_id, module.syntax()); |
161 | ModuleSource::Inline(ptr) | 160 | ModuleSource::Module(ptr) |
162 | } | 161 | } |
163 | 162 | ||
164 | pub(crate) fn as_file(self) -> Option<FileId> { | 163 | pub(crate) fn as_file(self) -> Option<FileId> { |
165 | match self { | 164 | match self { |
166 | ModuleSource::File(f) => Some(f), | 165 | ModuleSource::SourceFile(f) => Some(f), |
167 | ModuleSource::Inline(..) => None, | 166 | ModuleSource::Module(..) => None, |
168 | } | 167 | } |
169 | } | 168 | } |
170 | 169 | ||
171 | pub(crate) fn file_id(self) -> FileId { | 170 | pub(crate) fn file_id(self) -> FileId { |
172 | match self { | 171 | match self { |
173 | ModuleSource::File(f) => f, | 172 | ModuleSource::SourceFile(f) => f, |
174 | ModuleSource::Inline(ptr) => ptr.file_id(), | 173 | ModuleSource::Module(ptr) => ptr.file_id(), |
175 | } | 174 | } |
176 | } | 175 | } |
177 | 176 | ||
178 | fn resolve(self, db: &impl SyntaxDatabase) -> ModuleSourceNode { | 177 | fn resolve(self, db: &impl SyntaxDatabase) -> ModuleSourceNode { |
179 | match self { | 178 | match self { |
180 | ModuleSource::File(file_id) => { | 179 | ModuleSource::SourceFile(file_id) => { |
181 | let syntax = db.file_syntax(file_id); | 180 | let syntax = db.file_syntax(file_id); |
182 | ModuleSourceNode::Root(syntax.ast().owned()) | 181 | ModuleSourceNode::SourceFile(syntax.ast().owned()) |
183 | } | 182 | } |
184 | ModuleSource::Inline(ptr) => { | 183 | ModuleSource::Module(ptr) => { |
185 | let syntax = db.resolve_syntax_ptr(ptr); | 184 | let syntax = db.resolve_syntax_ptr(ptr); |
186 | let syntax = syntax.borrowed(); | 185 | let syntax = syntax.borrowed(); |
187 | let module = ast::Module::cast(syntax).unwrap(); | 186 | let module = ast::Module::cast(syntax).unwrap(); |
188 | ModuleSourceNode::Inline(module.owned()) | 187 | ModuleSourceNode::Module(module.owned()) |
189 | } | 188 | } |
190 | } | 189 | } |
191 | } | 190 | } |
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 00c4a08bd..614a6e9be 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -226,7 +226,7 @@ impl AnalysisImpl { | |||
226 | let module_source = match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) | 226 | let module_source = match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) |
227 | { | 227 | { |
228 | Some(m) if !m.has_semi() => ModuleSource::new_inline(position.file_id, m), | 228 | Some(m) if !m.has_semi() => ModuleSource::new_inline(position.file_id, m), |
229 | _ => ModuleSource::File(position.file_id), | 229 | _ => ModuleSource::SourceFile(position.file_id), |
230 | }; | 230 | }; |
231 | 231 | ||
232 | let res = module_tree | 232 | let res = module_tree |
@@ -254,7 +254,7 @@ impl AnalysisImpl { | |||
254 | let module_tree = self.module_tree(file_id)?; | 254 | let module_tree = self.module_tree(file_id)?; |
255 | let crate_graph = self.db.crate_graph(); | 255 | let crate_graph = self.db.crate_graph(); |
256 | let res = module_tree | 256 | let res = module_tree |
257 | .modules_for_source(ModuleSource::File(file_id)) | 257 | .modules_for_source(ModuleSource::SourceFile(file_id)) |
258 | .into_iter() | 258 | .into_iter() |
259 | .map(|it| it.root(&module_tree)) | 259 | .map(|it| it.root(&module_tree)) |
260 | .filter_map(|it| it.source(&module_tree).as_file()) | 260 | .filter_map(|it| it.source(&module_tree).as_file()) |
@@ -386,7 +386,7 @@ impl AnalysisImpl { | |||
386 | fix: None, | 386 | fix: None, |
387 | }) | 387 | }) |
388 | .collect::<Vec<_>>(); | 388 | .collect::<Vec<_>>(); |
389 | if let Some(m) = module_tree.any_module_for_source(ModuleSource::File(file_id)) { | 389 | if let Some(m) = module_tree.any_module_for_source(ModuleSource::SourceFile(file_id)) { |
390 | for (name_node, problem) in m.problems(&module_tree, &*self.db) { | 390 | for (name_node, problem) in m.problems(&module_tree, &*self.db) { |
391 | let diag = match problem { | 391 | let diag = match problem { |
392 | Problem::UnresolvedModule { candidate } => { | 392 | Problem::UnresolvedModule { candidate } => { |
@@ -548,7 +548,7 @@ impl AnalysisImpl { | |||
548 | Some(name) => name.text(), | 548 | Some(name) => name.text(), |
549 | None => return Vec::new(), | 549 | None => return Vec::new(), |
550 | }; | 550 | }; |
551 | let module_id = match module_tree.any_module_for_source(ModuleSource::File(file_id)) { | 551 | let module_id = match module_tree.any_module_for_source(ModuleSource::SourceFile(file_id)) { |
552 | Some(id) => id, | 552 | Some(id) => id, |
553 | None => return Vec::new(), | 553 | None => return Vec::new(), |
554 | }; | 554 | }; |