2019-04-08 13:04:58 +00:00
|
|
|
//! This module contains utilities for turning SyntaxNodes and HIR types
|
|
|
|
//! into things that may be used to render in a UI.
|
2019-04-08 13:07:50 +00:00
|
|
|
|
2019-04-08 13:34:59 +00:00
|
|
|
mod function_signature;
|
2019-04-08 13:07:50 +00:00
|
|
|
mod navigation_target;
|
|
|
|
mod structure;
|
|
|
|
|
2019-04-08 13:34:59 +00:00
|
|
|
use ra_syntax::{ast::{self, AstNode, TypeParamsOwner}, SyntaxKind::{ATTR, COMMENT}};
|
2019-04-08 07:25:35 +00:00
|
|
|
|
2019-04-08 09:20:28 +00:00
|
|
|
pub use navigation_target::NavigationTarget;
|
2019-04-08 13:07:50 +00:00
|
|
|
pub use structure::{StructureNode, file_structure};
|
2019-04-08 13:34:59 +00:00
|
|
|
pub use function_signature::FunctionSignature;
|
2019-04-08 09:20:28 +00:00
|
|
|
|
2019-04-08 08:44:23 +00:00
|
|
|
pub(crate) fn function_label(node: &ast::FnDef) -> String {
|
|
|
|
FunctionSignature::from(node).to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn const_label(node: &ast::ConstDef) -> String {
|
|
|
|
let label: String = node
|
|
|
|
.syntax()
|
|
|
|
.children_with_tokens()
|
|
|
|
.filter(|child| !(child.kind() == COMMENT || child.kind() == ATTR))
|
|
|
|
.map(|node| node.to_string())
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
label.trim().to_owned()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn type_label(node: &ast::TypeAliasDef) -> String {
|
|
|
|
let label: String = node
|
|
|
|
.syntax()
|
|
|
|
.children_with_tokens()
|
|
|
|
.filter(|child| !(child.kind() == COMMENT || child.kind() == ATTR))
|
|
|
|
.map(|node| node.to_string())
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
label.trim().to_owned()
|
|
|
|
}
|
|
|
|
|
2019-04-08 07:25:35 +00:00
|
|
|
pub(crate) fn generic_parameters<N: TypeParamsOwner>(node: &N) -> Vec<String> {
|
|
|
|
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<N: TypeParamsOwner>(node: &N) -> Vec<String> {
|
|
|
|
let mut res = vec![];
|
|
|
|
if let Some(clause) = node.where_clause() {
|
|
|
|
res.extend(clause.predicates().map(|p| p.syntax().text().to_string()));
|
|
|
|
}
|
|
|
|
res
|
|
|
|
}
|