From 0265778e86f7e130a921ab6307cfdcc0ad953fe0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Jul 2020 21:32:20 +0200 Subject: Don't use function signature for Display --- crates/ra_ide/src/display.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide/src/display.rs') diff --git a/crates/ra_ide/src/display.rs b/crates/ra_ide/src/display.rs index 1ec946369..9d413cf0a 100644 --- a/crates/ra_ide/src/display.rs +++ b/crates/ra_ide/src/display.rs @@ -13,10 +13,46 @@ use ra_syntax::{ pub(crate) use navigation_target::{ToNav, TryToNav}; pub(crate) use short_label::ShortLabel; +use ast::VisibilityOwner; pub use navigation_target::NavigationTarget; +use stdx::format_to; pub(crate) fn function_label(node: &ast::FnDef) -> String { - function_signature::FunctionSignature::from(node).to_string() + let mut buf = String::new(); + if let Some(vis) = node.visibility() { + format_to!(buf, "{} ", vis); + } + if node.async_token().is_some() { + format_to!(buf, "async "); + } + if node.const_token().is_some() { + format_to!(buf, "const "); + } + if node.unsafe_token().is_some() { + format_to!(buf, "unsafe "); + } + if let Some(abi) = node.abi() { + // Keyword `extern` is included in the string. + format_to!(buf, "{} ", abi); + } + if let Some(name) = node.name() { + format_to!(buf, "fn {}", name) + } + if let Some(type_params) = node.type_param_list() { + format_to!(buf, "{}", type_params); + } + if let Some(param_list) = node.param_list() { + format_to!(buf, "{}", param_list); + } + if let Some(ret_type) = node.ret_type() { + if ret_type.type_ref().is_some() { + format_to!(buf, " {}", ret_type); + } + } + if let Some(where_clause) = node.where_clause() { + format_to!(buf, "\n{}", where_clause); + } + buf } pub(crate) fn const_label(node: &ast::ConstDef) -> String { -- cgit v1.2.3 From edc0190f7a2a701ef7c8534b053070212798cd8b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Jul 2020 21:33:11 +0200 Subject: Rename --- crates/ra_ide/src/display.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_ide/src/display.rs') diff --git a/crates/ra_ide/src/display.rs b/crates/ra_ide/src/display.rs index 9d413cf0a..34ce32e81 100644 --- a/crates/ra_ide/src/display.rs +++ b/crates/ra_ide/src/display.rs @@ -10,14 +10,14 @@ use ra_syntax::{ SyntaxKind::{ATTR, COMMENT}, }; -pub(crate) use navigation_target::{ToNav, TryToNav}; -pub(crate) use short_label::ShortLabel; - use ast::VisibilityOwner; -pub use navigation_target::NavigationTarget; use stdx::format_to; -pub(crate) fn function_label(node: &ast::FnDef) -> String { +pub use navigation_target::NavigationTarget; +pub(crate) use navigation_target::{ToNav, TryToNav}; +pub(crate) use short_label::ShortLabel; + +pub(crate) fn function_declaration(node: &ast::FnDef) -> String { let mut buf = String::new(); if let Some(vis) = node.visibility() { format_to!(buf, "{} ", vis); -- cgit v1.2.3 From 3823c2dc1995ec261e36435662b8802c714e23d4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Jul 2020 22:05:43 +0200 Subject: Remove FunctionSignature --- crates/ra_ide/src/display.rs | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'crates/ra_ide/src/display.rs') diff --git a/crates/ra_ide/src/display.rs b/crates/ra_ide/src/display.rs index 34ce32e81..6d4151dd8 100644 --- a/crates/ra_ide/src/display.rs +++ b/crates/ra_ide/src/display.rs @@ -1,7 +1,6 @@ //! This module contains utilities for turning SyntaxNodes and HIR types //! into types that may be used to render in a UI. -pub(crate) mod function_signature; mod navigation_target; mod short_label; @@ -77,23 +76,6 @@ pub(crate) fn type_label(node: &ast::TypeAliasDef) -> String { label.trim().to_owned() } -pub(crate) fn generic_parameters(node: &N) -> Vec { - let mut res = vec![]; - if let Some(type_params) = node.type_param_list() { - res.extend(type_params.lifetime_params().map(|p| p.syntax().text().to_string())); - res.extend(type_params.type_params().map(|p| p.syntax().text().to_string())); - } - res -} - -pub(crate) fn where_predicates(node: &N) -> Vec { - let mut res = vec![]; - if let Some(clause) = node.where_clause() { - res.extend(clause.predicates().map(|p| p.syntax().text().to_string())); - } - res -} - pub(crate) fn macro_label(node: &ast::MacroCall) -> String { let name = node.name().map(|name| name.syntax().text().to_string()).unwrap_or_default(); let vis = if node.has_atom_attr("macro_export") { "#[macro_export]\n" } else { "" }; -- cgit v1.2.3