aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_db/src/helpers')
-rw-r--r--crates/ide_db/src/helpers/insert_use.rs32
1 files changed, 1 insertions, 31 deletions
diff --git a/crates/ide_db/src/helpers/insert_use.rs b/crates/ide_db/src/helpers/insert_use.rs
index 0dae9a541..040843990 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, SyntaxNodePtr, SyntaxToken, 14 AstToken, InsertPosition, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxToken,
15}; 15};
16use test_utils::mark; 16use test_utils::mark;
17 17
@@ -22,36 +22,6 @@ 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 {
55 pub fn from(syntax: SyntaxNode) -> Option<Self> { 25 pub fn from(syntax: SyntaxNode) -> Option<Self> {
56 if let Some(module) = ast::Module::cast(syntax.clone()) { 26 if let Some(module) = ast::Module::cast(syntax.clone()) {
57 module.item_list().map(ImportScope::Module) 27 module.item_list().map(ImportScope::Module)