From a7f4f7bfcc524a55ba559e0141a70aa799a8686d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 6 Jan 2019 15:58:45 +0300 Subject: split module source into decl/defin --- crates/ra_hir/src/code_model_api.rs | 40 ++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir/src/code_model_api.rs') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index eca7d0225..0c7f743d4 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -1,6 +1,7 @@ -use ra_db::{CrateId, Cancelable}; +use ra_db::{CrateId, Cancelable, FileId}; +use ra_syntax::{ast, SyntaxNode}; -use crate::{Name, db::HirDatabase, DefId, Path, PerNs, module::{ModuleSource, ModuleScope}}; +use crate::{Name, db::HirDatabase, DefId, Path, PerNs, module::{Problem, ModuleScope}}; /// hir::Crate describes a single crate. It's the main inteface with which /// crate's dependencies interact. Mostly, it should be just a proxy for the @@ -33,10 +34,27 @@ pub struct Module { pub(crate) def_id: DefId, } +/// An owned syntax node for a module. Unlike `ModuleSource`, +/// this holds onto the AST for the whole file. +pub enum ModuleSource { + SourceFile(ast::SourceFileNode), + Module(ast::ModuleNode), +} + impl Module { - // FIXME: what is a module source exactly? It should contain two nodes - pub fn source(&self, db: &impl HirDatabase) -> Cancelable { - Ok(self.source_impl(db)) + pub fn name(&self, db: &impl HirDatabase) -> Cancelable> { + self.name_impl(db) + } + + pub fn defenition_source(&self, db: &impl HirDatabase) -> Cancelable<(FileId, ModuleSource)> { + self.defenition_source_impl(db) + } + + pub fn declaration_source( + &self, + db: &impl HirDatabase, + ) -> Cancelable> { + self.declaration_source_impl(db) } /// Returns the crate this module is part of. @@ -56,6 +74,15 @@ impl Module { pub fn parent(&self, db: &impl HirDatabase) -> Cancelable> { self.parent_impl(db) } + pub fn path_to_root(&self, db: &impl HirDatabase) -> Cancelable> { + let mut res = vec![self.clone()]; + let mut curr = self.clone(); + while let Some(next) = curr.parent(db)? { + res.push(next.clone()); + curr = next + } + Ok(res) + } /// Returns a `ModuleScope`: a set of items, visible in this module. pub fn scope(&self, db: &impl HirDatabase) -> Cancelable { self.scope_impl(db) @@ -63,4 +90,7 @@ impl Module { pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> Cancelable> { self.resolve_path_impl(db, path) } + pub fn problems(&self, db: &impl HirDatabase) -> Cancelable> { + self.problems_impl(db) + } } -- cgit v1.2.3