From 070a9802246123c79709271c9ba6fddd6f888813 Mon Sep 17 00:00:00 2001 From: "Jeremy A. Kolb" Date: Tue, 22 Jan 2019 10:54:50 -0500 Subject: Add function signature to CompletionItem detail --- crates/ra_hir/src/code_model_api.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 9ae620efd..21ca36265 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -366,6 +366,28 @@ impl Function { Some(comments) } } + + pub fn label(&self, db: &impl HirDatabase) -> Option { + let def_loc = self.def_id.loc(db); + let syntax = db.file_item(def_loc.source_item_id); + let node = ast::FnDef::cast(&syntax).expect("fn def should point to FnDef node"); + + let label: String = if let Some(body) = node.body() { + let body_range = body.syntax().range(); + let label: String = node + .syntax() + .children() + .filter(|child| !child.range().is_subrange(&body_range)) // Filter out body + .filter(|child| ast::Comment::cast(child).is_none()) // Filter out comments + .map(|node| node.text().to_string()) + .collect(); + label + } else { + node.syntax().text().to_string() + }; + + Some(label.trim().to_owned()) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -- cgit v1.2.3