aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-12-03 13:58:18 +0000
committerKirill Bulatov <[email protected]>2020-12-07 21:41:08 +0000
commit74c3bbacc9b352057f2fc7ab69bd13e53022beb0 (patch)
tree32f3407cfb6851539e7ebf6b1c4d77a78c364efa /crates/ide_db
parentf6d2540df09bc0dcd8a748ec0ed7cb33ac76d9f2 (diff)
Make completion resolve async
Diffstat (limited to 'crates/ide_db')
-rw-r--r--crates/ide_db/src/helpers/insert_use.rs32
1 files changed, 31 insertions, 1 deletions
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::{
11 edit::{AstNodeEdit, IndentLevel}, 11 edit::{AstNodeEdit, IndentLevel},
12 make, AstNode, PathSegmentKind, VisibilityOwner, 12 make, AstNode, PathSegmentKind, VisibilityOwner,
13 }, 13 },
14 AstToken, InsertPosition, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxToken, 14 AstToken, InsertPosition, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxNodePtr, SyntaxToken,
15}; 15};
16use test_utils::mark; 16use test_utils::mark;
17 17
@@ -22,6 +22,36 @@ pub enum ImportScope {
22} 22}
23 23
24impl ImportScope { 24impl ImportScope {
25 pub fn get_ptr(&self) -> ImportScopePtr {
26 match self {
27 ImportScope::File(file) => ImportScopePtr::File(SyntaxNodePtr::new(file.syntax())),
28 ImportScope::Module(module) => {
29 ImportScopePtr::Module(SyntaxNodePtr::new(module.syntax()))
30 }
31 }
32 }
33}
34
35#[derive(Debug, Clone)]
36pub enum ImportScopePtr {
37 File(SyntaxNodePtr),
38 Module(SyntaxNodePtr),
39}
40
41impl ImportScopePtr {
42 pub fn into_scope(self, root: &SyntaxNode) -> Option<ImportScope> {
43 Some(match self {
44 ImportScopePtr::File(file_ptr) => {
45 ImportScope::File(ast::SourceFile::cast(file_ptr.to_node(root))?)
46 }
47 ImportScopePtr::Module(module_ptr) => {
48 ImportScope::File(ast::SourceFile::cast(module_ptr.to_node(root))?)
49 }
50 })
51 }
52}
53
54impl ImportScope {
25 pub fn from(syntax: SyntaxNode) -> Option<Self> { 55 pub fn from(syntax: SyntaxNode) -> Option<Self> {
26 if let Some(module) = ast::Module::cast(syntax.clone()) { 56 if let Some(module) = ast::Module::cast(syntax.clone()) {
27 module.item_list().map(ImportScope::Module) 57 module.item_list().map(ImportScope::Module)