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 +++++++++++--------------- crates/libeditor/tests/test.rs | 6 +++--- 2 files changed, 14 insertions(+), 18 deletions(-) (limited to 'crates/libeditor') 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(), }; 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() {} } #[test] -fn test_structure() { +fn test_file_structure() { let file = file(r#" struct Foo { x: i32 @@ -94,8 +94,8 @@ impl fmt::Debug for E {} StructureNode { parent: None, label: "T", navigation_range: [81; 82), node_range: [76; 88), kind: TYPE_DEF }, StructureNode { parent: None, label: "S", navigation_range: [96; 97), node_range: [89; 108), kind: STATIC_DEF }, StructureNode { parent: None, label: "C", navigation_range: [115; 116), node_range: [109; 127), kind: CONST_DEF }, - StructureNode { parent: None, label: "impl E ", navigation_range: [129; 136), node_range: [129; 138), kind: IMPL_ITEM }, - StructureNode { parent: None, label: "impl fmt::Debug for E ", navigation_range: [140; 162), node_range: [140; 164), kind: IMPL_ITEM }]"#, + StructureNode { parent: None, label: "impl E", navigation_range: [134; 135), node_range: [129; 138), kind: IMPL_ITEM }, + StructureNode { parent: None, label: "impl fmt::Debug for E", navigation_range: [160; 161), node_range: [140; 164), kind: IMPL_ITEM }]"#, &symbols, ) } -- cgit v1.2.3