From 5953a348bd6102a868f303d3f732a6ec7d465833 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 14 Aug 2018 12:38:20 +0300 Subject: Less hackish impl structure --- crates/libeditor/src/symbols.rs | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'crates/libeditor/src') 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::{ visit::{visitor, Visitor}, walk::{walk, WalkEvent, preorder}, }, - SyntaxKind::*, }; use TextRange; @@ -104,24 +103,21 @@ fn structure_node(node: SyntaxNodeRef) -> Option { .visit(decl::>) .visit(decl::>) .visit(|im: ast::ImplItem<_>| { - let mut label = String::new(); - let brace = im.syntax().children() - .find(|it| { - let stop = it.kind() == L_CURLY; - if !stop { - label.push_str(&it.text()); - } - stop - })?; - let navigation_range = TextRange::from_to( - im.syntax().range().start(), - brace.range().start(), - ); + let target_type = im.target_type()?; + let target_trait = im.target_trait(); + let label = match target_trait { + None => format!("impl {}", target_type.syntax().text()), + Some(t) => format!( + "impl {} for {}", + t.syntax().text(), + target_type.syntax().text(), + ), + }; let node = StructureNode { parent: None, label, - navigation_range, + navigation_range: target_type.syntax().range(), node_range: im.syntax().range(), kind: im.syntax().kind(), }; -- cgit v1.2.3