Remove possible multiline details in completions

This commit is contained in:
Lukas Wirth 2021-11-24 16:01:33 +01:00
parent 3e4ac8a2c9
commit 0c98a01b3e
10 changed files with 81 additions and 63 deletions

View file

@ -1,10 +1,6 @@
//! This module contains utilities for turning SyntaxNodes and HIR types
//! into types that may be used to render in a UI.
//! This module contains utilities for rendering syntax nodes into a string representing their signature.
use crate::{
ast::{self, AstNode, HasAttrs, HasGenericParams, HasName},
SyntaxKind::{ATTR, COMMENT},
};
use crate::ast::{self, HasAttrs, HasGenericParams, HasName};
use ast::HasVisibility;
use stdx::format_to;
@ -55,25 +51,39 @@ pub fn function_declaration(node: &ast::Fn) -> String {
}
pub fn const_label(node: &ast::Const) -> 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()
let mut s = String::new();
if let Some(vis) = node.visibility() {
format_to!(s, "{} ", vis);
}
format_to!(s, "const ");
if let Some(name) = node.name() {
format_to!(s, "{}", name);
} else {
format_to!(s, "?");
}
format_to!(s, ": ");
if let Some(ty) = node.ty() {
format_to!(s, "{}", ty);
} else {
format_to!(s, "?");
}
format_to!(s, ";");
s
}
pub fn type_label(node: &ast::TypeAlias) -> 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()
let mut s = String::new();
if let Some(vis) = node.visibility() {
format_to!(s, "{} ", vis);
}
format_to!(s, "type ");
if let Some(name) = node.name() {
format_to!(s, "{}", name);
} else {
format_to!(s, "?");
}
format_to!(s, ";");
s
}
pub fn macro_label(node: &ast::Macro) -> String {