mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Move FunctionSignature to display, remove write_joined
write_joined is replaced with `join_to_string::join` which provides the necessary functionality.
This commit is contained in:
parent
84fde47d00
commit
7ba22f1c19
2 changed files with 36 additions and 49 deletions
|
@ -1,5 +1,34 @@
|
|||
//! This module contains utilities for rendering turning things into something
|
||||
//! that may be used to render in UI.
|
||||
use super::*;
|
||||
use std::fmt::{self, Display};
|
||||
use join_to_string::join;
|
||||
|
||||
/// Contains information about a function signature
|
||||
#[derive(Debug)]
|
||||
pub struct FunctionSignature {
|
||||
/// Optional visibility
|
||||
pub visibility: Option<String>,
|
||||
/// Name of the function
|
||||
pub name: Option<String>,
|
||||
/// Documentation for the function
|
||||
pub doc: Option<Documentation>,
|
||||
/// Generic parameters
|
||||
pub generic_parameters: Vec<String>,
|
||||
/// Parameters of the function
|
||||
pub parameters: Vec<String>,
|
||||
/// Optional return type
|
||||
pub ret_type: Option<String>,
|
||||
/// Where predicates
|
||||
pub where_predicates: Vec<String>,
|
||||
}
|
||||
|
||||
impl FunctionSignature {
|
||||
pub(crate) fn with_doc_opt(mut self, doc: Option<Documentation>) -> Self {
|
||||
self.doc = doc;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for FunctionSignature {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
|
@ -12,14 +41,13 @@ impl Display for FunctionSignature {
|
|||
}
|
||||
|
||||
if !self.generic_parameters.is_empty() {
|
||||
write!(f, "<")?;
|
||||
write_joined(f, &self.generic_parameters, ", ")?;
|
||||
write!(f, ">")?;
|
||||
join(self.generic_parameters.iter())
|
||||
.separator(", ")
|
||||
.surround_with("<", ">")
|
||||
.to_fmt(f)?;
|
||||
}
|
||||
|
||||
write!(f, "(")?;
|
||||
write_joined(f, &self.parameters, ", ")?;
|
||||
write!(f, ")")?;
|
||||
join(self.parameters.iter()).separator(", ").surround_with("(", ")").to_fmt(f)?;
|
||||
|
||||
if let Some(t) = &self.ret_type {
|
||||
write!(f, " -> {}", t)?;
|
||||
|
@ -27,25 +55,9 @@ impl Display for FunctionSignature {
|
|||
|
||||
if !self.where_predicates.is_empty() {
|
||||
write!(f, "\nwhere ")?;
|
||||
write_joined(f, &self.where_predicates, ",\n ")?;
|
||||
join(self.where_predicates.iter()).separator(",\n ").to_fmt(f)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn write_joined<T: Display>(
|
||||
f: &mut fmt::Formatter,
|
||||
items: impl IntoIterator<Item = T>,
|
||||
sep: &str,
|
||||
) -> fmt::Result {
|
||||
let mut first = true;
|
||||
for e in items {
|
||||
if !first {
|
||||
write!(f, "{}", sep)?;
|
||||
}
|
||||
first = false;
|
||||
write!(f, "{}", e)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ pub use crate::{
|
|||
syntax_highlighting::HighlightedRange,
|
||||
structure::{StructureNode, file_structure},
|
||||
diagnostics::Severity,
|
||||
display::FunctionSignature,
|
||||
};
|
||||
|
||||
pub use ra_db::{
|
||||
|
@ -248,32 +249,6 @@ pub struct CallInfo {
|
|||
pub active_parameter: Option<usize>,
|
||||
}
|
||||
|
||||
/// Contains information about a function signature
|
||||
#[derive(Debug)]
|
||||
pub struct FunctionSignature {
|
||||
/// Optional visibility
|
||||
pub visibility: Option<String>,
|
||||
/// Name of the function
|
||||
pub name: Option<String>,
|
||||
/// Documentation for the function
|
||||
pub doc: Option<Documentation>,
|
||||
/// Generic parameters
|
||||
pub generic_parameters: Vec<String>,
|
||||
/// Parameters of the function
|
||||
pub parameters: Vec<String>,
|
||||
/// Optional return type
|
||||
pub ret_type: Option<String>,
|
||||
/// Where predicates
|
||||
pub where_predicates: Vec<String>,
|
||||
}
|
||||
|
||||
impl FunctionSignature {
|
||||
pub(crate) fn with_doc_opt(mut self, doc: Option<Documentation>) -> Self {
|
||||
self.doc = doc;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// `AnalysisHost` stores the current state of the world.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct AnalysisHost {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue