aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-14 10:38:20 +0100
committerAleksey Kladov <[email protected]>2018-08-14 10:38:20 +0100
commit5953a348bd6102a868f303d3f732a6ec7d465833 (patch)
tree8f4ca16180f850465d871d9b2959d4ae065dcfeb /crates/libeditor
parentde02d2891ec7f7b295e33887d49de954f677387a (diff)
Less hackish impl structure
Diffstat (limited to 'crates/libeditor')
-rw-r--r--crates/libeditor/src/symbols.rs26
-rw-r--r--crates/libeditor/tests/test.rs6
2 files changed, 14 insertions, 18 deletions
diff --git a/crates/libeditor/src/symbols.rs b/crates/libeditor/src/symbols.rs
index 43f4164da..8419f08e6 100644
--- a/crates/libeditor/src/symbols.rs
+++ b/crates/libeditor/src/symbols.rs
@@ -6,7 +6,6 @@ use libsyntax2::{
6 visit::{visitor, Visitor}, 6 visit::{visitor, Visitor},
7 walk::{walk, WalkEvent, preorder}, 7 walk::{walk, WalkEvent, preorder},
8 }, 8 },
9 SyntaxKind::*,
10}; 9};
11use TextRange; 10use TextRange;
12 11
@@ -104,24 +103,21 @@ fn structure_node(node: SyntaxNodeRef) -> Option<StructureNode> {
104 .visit(decl::<ast::ConstDef<_>>) 103 .visit(decl::<ast::ConstDef<_>>)
105 .visit(decl::<ast::StaticDef<_>>) 104 .visit(decl::<ast::StaticDef<_>>)
106 .visit(|im: ast::ImplItem<_>| { 105 .visit(|im: ast::ImplItem<_>| {
107 let mut label = String::new(); 106 let target_type = im.target_type()?;
108 let brace = im.syntax().children() 107 let target_trait = im.target_trait();
109 .find(|it| { 108 let label = match target_trait {
110 let stop = it.kind() == L_CURLY; 109 None => format!("impl {}", target_type.syntax().text()),
111 if !stop { 110 Some(t) => format!(
112 label.push_str(&it.text()); 111 "impl {} for {}",
113 } 112 t.syntax().text(),
114 stop 113 target_type.syntax().text(),
115 })?; 114 ),
116 let navigation_range = TextRange::from_to( 115 };
117 im.syntax().range().start(),
118 brace.range().start(),
119 );
120 116
121 let node = StructureNode { 117 let node = StructureNode {
122 parent: None, 118 parent: None,
123 label, 119 label,
124 navigation_range, 120 navigation_range: target_type.syntax().range(),
125 node_range: im.syntax().range(), 121 node_range: im.syntax().range(),
126 kind: im.syntax().kind(), 122 kind: im.syntax().kind(),
127 }; 123 };
diff --git a/crates/libeditor/tests/test.rs b/crates/libeditor/tests/test.rs
index 97fa30e1f..91df74bd6 100644
--- a/crates/libeditor/tests/test.rs
+++ b/crates/libeditor/tests/test.rs
@@ -66,7 +66,7 @@ fn test_foo() {}
66} 66}
67 67
68#[test] 68#[test]
69fn test_structure() { 69fn test_file_structure() {
70 let file = file(r#" 70 let file = file(r#"
71struct Foo { 71struct Foo {
72 x: i32 72 x: i32
@@ -94,8 +94,8 @@ impl fmt::Debug for E {}
94 StructureNode { parent: None, label: "T", navigation_range: [81; 82), node_range: [76; 88), kind: TYPE_DEF }, 94 StructureNode { parent: None, label: "T", navigation_range: [81; 82), node_range: [76; 88), kind: TYPE_DEF },
95 StructureNode { parent: None, label: "S", navigation_range: [96; 97), node_range: [89; 108), kind: STATIC_DEF }, 95 StructureNode { parent: None, label: "S", navigation_range: [96; 97), node_range: [89; 108), kind: STATIC_DEF },
96 StructureNode { parent: None, label: "C", navigation_range: [115; 116), node_range: [109; 127), kind: CONST_DEF }, 96 StructureNode { parent: None, label: "C", navigation_range: [115; 116), node_range: [109; 127), kind: CONST_DEF },
97 StructureNode { parent: None, label: "impl E ", navigation_range: [129; 136), node_range: [129; 138), kind: IMPL_ITEM }, 97 StructureNode { parent: None, label: "impl E", navigation_range: [134; 135), node_range: [129; 138), kind: IMPL_ITEM },
98 StructureNode { parent: None, label: "impl fmt::Debug for E ", navigation_range: [140; 162), node_range: [140; 164), kind: IMPL_ITEM }]"#, 98 StructureNode { parent: None, label: "impl fmt::Debug for E", navigation_range: [160; 161), node_range: [140; 164), kind: IMPL_ITEM }]"#,
99 &symbols, 99 &symbols,
100 ) 100 )
101} 101}