From 74c3bbacc9b352057f2fc7ab69bd13e53022beb0 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 3 Dec 2020 15:58:18 +0200 Subject: Make completion resolve async --- crates/ide_db/src/helpers/insert_use.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'crates/ide_db') diff --git a/crates/ide_db/src/helpers/insert_use.rs b/crates/ide_db/src/helpers/insert_use.rs index 040843990..0dae9a541 100644 --- a/crates/ide_db/src/helpers/insert_use.rs +++ b/crates/ide_db/src/helpers/insert_use.rs @@ -11,7 +11,7 @@ use syntax::{ edit::{AstNodeEdit, IndentLevel}, make, AstNode, PathSegmentKind, VisibilityOwner, }, - AstToken, InsertPosition, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxToken, + AstToken, InsertPosition, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxNodePtr, SyntaxToken, }; use test_utils::mark; @@ -21,6 +21,36 @@ pub enum ImportScope { Module(ast::ItemList), } +impl ImportScope { + pub fn get_ptr(&self) -> ImportScopePtr { + match self { + ImportScope::File(file) => ImportScopePtr::File(SyntaxNodePtr::new(file.syntax())), + ImportScope::Module(module) => { + ImportScopePtr::Module(SyntaxNodePtr::new(module.syntax())) + } + } + } +} + +#[derive(Debug, Clone)] +pub enum ImportScopePtr { + File(SyntaxNodePtr), + Module(SyntaxNodePtr), +} + +impl ImportScopePtr { + pub fn into_scope(self, root: &SyntaxNode) -> Option { + Some(match self { + ImportScopePtr::File(file_ptr) => { + ImportScope::File(ast::SourceFile::cast(file_ptr.to_node(root))?) + } + ImportScopePtr::Module(module_ptr) => { + ImportScope::File(ast::SourceFile::cast(module_ptr.to_node(root))?) + } + }) + } +} + impl ImportScope { pub fn from(syntax: SyntaxNode) -> Option { if let Some(module) = ast::Module::cast(syntax.clone()) { -- cgit v1.2.3