Use cached module scopes for completion

This commit is contained in:
Aleksey Kladov 2018-11-07 21:08:11 +03:00
parent 9b88ec488b
commit 397c235086
5 changed files with 71 additions and 51 deletions

View file

@ -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());