mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Remove possible multiline details in completions
This commit is contained in:
parent
3e4ac8a2c9
commit
0c98a01b3e
10 changed files with 81 additions and 63 deletions
|
@ -1,10 +1,10 @@
|
|||
//! Renderer for `enum` variants.
|
||||
|
||||
use std::iter;
|
||||
use std::{iter, mem};
|
||||
|
||||
use hir::{HasAttrs, HirDisplay};
|
||||
use ide_db::SymbolKind;
|
||||
use itertools::Itertools;
|
||||
use stdx::format_to;
|
||||
|
||||
use crate::{
|
||||
item::{CompletionItem, ImportEdit},
|
||||
|
@ -105,18 +105,31 @@ impl<'a> EnumRender<'a> {
|
|||
.into_iter()
|
||||
.map(|field| (field.name(self.ctx.db()), field.ty(self.ctx.db())));
|
||||
|
||||
let mut b = String::new();
|
||||
let mut first_run = true;
|
||||
match self.variant_kind {
|
||||
hir::StructKind::Tuple | hir::StructKind::Unit => format!(
|
||||
"({})",
|
||||
detail_types.map(|(_, t)| t.display(self.ctx.db()).to_string()).format(", ")
|
||||
),
|
||||
hir::StructKind::Record => format!(
|
||||
"{{ {} }}",
|
||||
detail_types
|
||||
.map(|(n, t)| format!("{}: {}", n, t.display(self.ctx.db()).to_string()))
|
||||
.format(", ")
|
||||
),
|
||||
hir::StructKind::Tuple | hir::StructKind::Unit => {
|
||||
format_to!(b, "(");
|
||||
for (_, t) in detail_types {
|
||||
if !mem::take(&mut first_run) {
|
||||
format_to!(b, ", ");
|
||||
}
|
||||
format_to!(b, "{}", t.display(self.ctx.db()));
|
||||
}
|
||||
format_to!(b, ")");
|
||||
}
|
||||
hir::StructKind::Record => {
|
||||
format_to!(b, "{{");
|
||||
for (n, t) in detail_types {
|
||||
if !mem::take(&mut first_run) {
|
||||
format_to!(b, ", ");
|
||||
}
|
||||
format_to!(b, "{}: {}", n, t.display(self.ctx.db()));
|
||||
}
|
||||
format_to!(b, "}}");
|
||||
}
|
||||
}
|
||||
b
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ use either::Either;
|
|||
use hir::{AsAssocItem, HasSource, HirDisplay};
|
||||
use ide_db::SymbolKind;
|
||||
use itertools::Itertools;
|
||||
use stdx::format_to;
|
||||
use syntax::ast;
|
||||
|
||||
use crate::{
|
||||
|
@ -122,14 +123,11 @@ impl<'a> FunctionRender<'a> {
|
|||
|
||||
fn detail(&self) -> String {
|
||||
let ret_ty = self.func.ret_type(self.ctx.db());
|
||||
let ret = if ret_ty.is_unit() {
|
||||
// Omit the return type if it is the unit type
|
||||
String::new()
|
||||
} else {
|
||||
format!(" {}", self.ty_display())
|
||||
};
|
||||
|
||||
format!("fn({}){}", self.params_display(), ret)
|
||||
let mut detail = format!("fn({})", self.params_display());
|
||||
if !ret_ty.is_unit() {
|
||||
format_to!(detail, " -> {}", ret_ty.display(self.ctx.db()));
|
||||
}
|
||||
detail
|
||||
}
|
||||
|
||||
fn params_display(&self) -> String {
|
||||
|
@ -153,12 +151,6 @@ impl<'a> FunctionRender<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn ty_display(&self) -> String {
|
||||
let ret_ty = self.func.ret_type(self.ctx.db());
|
||||
|
||||
format!("-> {}", ret_ty.display(self.ctx.db()))
|
||||
}
|
||||
|
||||
fn params(&self) -> Params {
|
||||
let ast_params = match self.ast_node.param_list() {
|
||||
Some(it) => it,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue