From 397c235086cfaf5247d971c1867a38640895e014 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 7 Nov 2018 21:08:11 +0300 Subject: Use cached module scopes for completion --- crates/ra_analysis/src/descriptors/module/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'crates/ra_analysis/src/descriptors/module/mod.rs') diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index 58d6abed3..bc1148b22 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs @@ -3,7 +3,7 @@ pub(crate) mod scope; use ra_syntax::{ ast::{self, AstNode, NameOwner}, - SmolStr, SyntaxNode, + SmolStr, SyntaxNode, SyntaxNodeRef, }; use relative_path::RelativePathBuf; @@ -154,6 +154,16 @@ struct ModuleData { } impl ModuleSource { + pub(crate) fn for_node(file_id: FileId, node: SyntaxNodeRef) -> ModuleSource { + for node in node.ancestors() { + if let Some(m) = ast::Module::cast(node) { + if !m.has_semi() { + return ModuleSource::new_inline(file_id, m); + } + } + } + ModuleSource::SourceFile(file_id) + } pub(crate) fn new_inline(file_id: FileId, module: ast::Module) -> ModuleSource { assert!(!module.has_semi()); let ptr = SyntaxPtr::new(file_id, module.syntax()); -- cgit v1.2.3