From 22949dab267bf7b8b3da73fe7745a12daca21a52 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 7 Nov 2018 18:42:30 +0300 Subject: rename module source --- crates/ra_analysis/src/descriptors/module/imp.rs | 16 ++++++------ crates/ra_analysis/src/descriptors/module/mod.rs | 31 ++++++++++++------------ 2 files changed, 23 insertions(+), 24 deletions(-) (limited to 'crates/ra_analysis/src/descriptors/module') 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( db::check_canceled(db)?; let file_id = source.file_id(); let submodules = match source.resolve(db) { - ModuleSourceNode::Root(it) => collect_submodules(file_id, it.borrowed()), - ModuleSourceNode::Inline(it) => it + ModuleSourceNode::SourceFile(it) => collect_submodules(file_id, it.borrowed()), + ModuleSourceNode::Module(it) => it .borrowed() .item_list() .map(|it| collect_submodules(file_id, it)) @@ -89,8 +89,8 @@ pub(crate) fn module_scope( let tree = db.module_tree(source_root_id)?; let source = module_id.source(&tree).resolve(db); let res = match source { - ModuleSourceNode::Root(root) => ModuleScope::new(root.borrowed().items()), - ModuleSourceNode::Inline(inline) => match inline.borrowed().item_list() { + ModuleSourceNode::SourceFile(it) => ModuleScope::new(it.borrowed().items()), + ModuleSourceNode::Module(it) => match it.borrowed().item_list() { Some(items) => ModuleScope::new(items.items()), None => ModuleScope::new(std::iter::empty()), }, @@ -121,7 +121,7 @@ fn create_module_tree<'a>( let source_root = db.source_root(source_root); for &file_id in source_root.files.iter() { - let source = ModuleSource::File(file_id); + let source = ModuleSource::SourceFile(file_id); if visited.contains(&source) { continue; // TODO: use explicit crate_roots here } @@ -181,7 +181,7 @@ fn build_subtree( visited, roots, Some(link), - ModuleSource::File(file_id), + ModuleSource::SourceFile(file_id), ), }) .collect::>>()?; @@ -213,8 +213,8 @@ fn resolve_submodule( file_resolver: &FileResolverImp, ) -> (Vec, Option) { let file_id = match source { - ModuleSource::File(it) => it, - ModuleSource::Inline(..) => { + ModuleSource::SourceFile(it) => it, + ModuleSource::Module(..) => { // TODO return (Vec::new(), None); } 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 { /// `ModuleSource` is the syntax tree element that produced this module: /// either a file, or an inlinde module. -/// TODO: we don't produce Inline modules yet #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub(crate) enum ModuleSource { - File(FileId), + SourceFile(FileId), #[allow(dead_code)] - Inline(SyntaxPtr), + Module(SyntaxPtr), } /// An owned syntax node for a module. Unlike `ModuleSource`, /// this holds onto the AST for the whole file. enum ModuleSourceNode { - Root(ast::SourceFileNode), - Inline(ast::ModuleNode), + SourceFile(ast::SourceFileNode), + Module(ast::ModuleNode), } #[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] @@ -135,14 +134,14 @@ impl LinkId { ) -> ast::ModuleNode { let owner = self.owner(tree); match owner.source(tree).resolve(db) { - ModuleSourceNode::Root(root) => { + ModuleSourceNode::SourceFile(root) => { let ast = imp::modules(root.borrowed()) .find(|(name, _)| name == &tree.link(self).name) .unwrap() .1; ast.owned() } - ModuleSourceNode::Inline(it) => it, + ModuleSourceNode::Module(it) => it, } } } @@ -158,34 +157,34 @@ impl ModuleSource { pub(crate) fn new_inline(file_id: FileId, module: ast::Module) -> ModuleSource { assert!(!module.has_semi()); let ptr = SyntaxPtr::new(file_id, module.syntax()); - ModuleSource::Inline(ptr) + ModuleSource::Module(ptr) } pub(crate) fn as_file(self) -> Option { match self { - ModuleSource::File(f) => Some(f), - ModuleSource::Inline(..) => None, + ModuleSource::SourceFile(f) => Some(f), + ModuleSource::Module(..) => None, } } pub(crate) fn file_id(self) -> FileId { match self { - ModuleSource::File(f) => f, - ModuleSource::Inline(ptr) => ptr.file_id(), + ModuleSource::SourceFile(f) => f, + ModuleSource::Module(ptr) => ptr.file_id(), } } fn resolve(self, db: &impl SyntaxDatabase) -> ModuleSourceNode { match self { - ModuleSource::File(file_id) => { + ModuleSource::SourceFile(file_id) => { let syntax = db.file_syntax(file_id); - ModuleSourceNode::Root(syntax.ast().owned()) + ModuleSourceNode::SourceFile(syntax.ast().owned()) } - ModuleSource::Inline(ptr) => { + ModuleSource::Module(ptr) => { let syntax = db.resolve_syntax_ptr(ptr); let syntax = syntax.borrowed(); let module = ast::Module::cast(syntax).unwrap(); - ModuleSourceNode::Inline(module.owned()) + ModuleSourceNode::Module(module.owned()) } } } -- cgit v1.2.3