diff options
author | Aleksey Kladov <[email protected]> | 2018-08-14 10:38:20 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-14 10:38:20 +0100 |
commit | 5953a348bd6102a868f303d3f732a6ec7d465833 (patch) | |
tree | 8f4ca16180f850465d871d9b2959d4ae065dcfeb /crates/libeditor/src | |
parent | de02d2891ec7f7b295e33887d49de954f677387a (diff) |
Less hackish impl structure
Diffstat (limited to 'crates/libeditor/src')
-rw-r--r-- | crates/libeditor/src/symbols.rs | 26 |
1 files changed, 11 insertions, 15 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 | }; |
11 | use TextRange; | 10 | use 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 | }; |