mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Normalize line-endings in display.rs
This changes from CRLF to LF
This commit is contained in:
parent
f4aa15c16b
commit
2fe075f56e
1 changed files with 112 additions and 112 deletions
|
@ -1,112 +1,112 @@
|
||||||
//! This module contains utilities for rendering turning things into something
|
//! This module contains utilities for rendering turning things into something
|
||||||
//! that may be used to render in UI.
|
//! that may be used to render in UI.
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::fmt::{self, Display};
|
use std::fmt::{self, Display};
|
||||||
use join_to_string::join;
|
use join_to_string::join;
|
||||||
use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner, TypeParamsOwner};
|
use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner, TypeParamsOwner};
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
|
|
||||||
/// Contains information about a function signature
|
/// Contains information about a function signature
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FunctionSignature {
|
pub struct FunctionSignature {
|
||||||
/// Optional visibility
|
/// Optional visibility
|
||||||
pub visibility: Option<String>,
|
pub visibility: Option<String>,
|
||||||
/// Name of the function
|
/// Name of the function
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
/// Documentation for the function
|
/// Documentation for the function
|
||||||
pub doc: Option<Documentation>,
|
pub doc: Option<Documentation>,
|
||||||
/// Generic parameters
|
/// Generic parameters
|
||||||
pub generic_parameters: Vec<String>,
|
pub generic_parameters: Vec<String>,
|
||||||
/// Parameters of the function
|
/// Parameters of the function
|
||||||
pub parameters: Vec<String>,
|
pub parameters: Vec<String>,
|
||||||
/// Optional return type
|
/// Optional return type
|
||||||
pub ret_type: Option<String>,
|
pub ret_type: Option<String>,
|
||||||
/// Where predicates
|
/// Where predicates
|
||||||
pub where_predicates: Vec<String>,
|
pub where_predicates: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FunctionSignature {
|
impl FunctionSignature {
|
||||||
pub(crate) fn with_doc_opt(mut self, doc: Option<Documentation>) -> Self {
|
pub(crate) fn with_doc_opt(mut self, doc: Option<Documentation>) -> Self {
|
||||||
self.doc = doc;
|
self.doc = doc;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&'_ ast::FnDef> for FunctionSignature {
|
impl From<&'_ ast::FnDef> for FunctionSignature {
|
||||||
fn from(node: &ast::FnDef) -> FunctionSignature {
|
fn from(node: &ast::FnDef) -> FunctionSignature {
|
||||||
fn param_list(node: &ast::FnDef) -> Vec<String> {
|
fn param_list(node: &ast::FnDef) -> Vec<String> {
|
||||||
let mut res = vec![];
|
let mut res = vec![];
|
||||||
if let Some(param_list) = node.param_list() {
|
if let Some(param_list) = node.param_list() {
|
||||||
if let Some(self_param) = param_list.self_param() {
|
if let Some(self_param) = param_list.self_param() {
|
||||||
res.push(self_param.syntax().text().to_string())
|
res.push(self_param.syntax().text().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
res.extend(param_list.params().map(|param| param.syntax().text().to_string()));
|
res.extend(param_list.params().map(|param| param.syntax().text().to_string()));
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionSignature {
|
FunctionSignature {
|
||||||
visibility: node.visibility().map(|n| n.syntax().text().to_string()),
|
visibility: node.visibility().map(|n| n.syntax().text().to_string()),
|
||||||
name: node.name().map(|n| n.text().to_string()),
|
name: node.name().map(|n| n.text().to_string()),
|
||||||
ret_type: node
|
ret_type: node
|
||||||
.ret_type()
|
.ret_type()
|
||||||
.and_then(|r| r.type_ref())
|
.and_then(|r| r.type_ref())
|
||||||
.map(|n| n.syntax().text().to_string()),
|
.map(|n| n.syntax().text().to_string()),
|
||||||
parameters: param_list(node),
|
parameters: param_list(node),
|
||||||
generic_parameters: generic_parameters(node),
|
generic_parameters: generic_parameters(node),
|
||||||
where_predicates: where_predicates(node),
|
where_predicates: where_predicates(node),
|
||||||
// docs are processed separately
|
// docs are processed separately
|
||||||
doc: None,
|
doc: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for FunctionSignature {
|
impl Display for FunctionSignature {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
if let Some(t) = &self.visibility {
|
if let Some(t) = &self.visibility {
|
||||||
write!(f, "{} ", t)?;
|
write!(f, "{} ", t)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(name) = &self.name {
|
if let Some(name) = &self.name {
|
||||||
write!(f, "fn {}", name)?;
|
write!(f, "fn {}", name)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.generic_parameters.is_empty() {
|
if !self.generic_parameters.is_empty() {
|
||||||
join(self.generic_parameters.iter())
|
join(self.generic_parameters.iter())
|
||||||
.separator(", ")
|
.separator(", ")
|
||||||
.surround_with("<", ">")
|
.surround_with("<", ">")
|
||||||
.to_fmt(f)?;
|
.to_fmt(f)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
join(self.parameters.iter()).separator(", ").surround_with("(", ")").to_fmt(f)?;
|
join(self.parameters.iter()).separator(", ").surround_with("(", ")").to_fmt(f)?;
|
||||||
|
|
||||||
if let Some(t) = &self.ret_type {
|
if let Some(t) = &self.ret_type {
|
||||||
write!(f, " -> {}", t)?;
|
write!(f, " -> {}", t)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.where_predicates.is_empty() {
|
if !self.where_predicates.is_empty() {
|
||||||
write!(f, "\nwhere ")?;
|
write!(f, "\nwhere ")?;
|
||||||
join(self.where_predicates.iter()).separator(",\n ").to_fmt(f)?;
|
join(self.where_predicates.iter()).separator(",\n ").to_fmt(f)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn generic_parameters<N: TypeParamsOwner>(node: &N) -> Vec<String> {
|
pub(crate) fn generic_parameters<N: TypeParamsOwner>(node: &N) -> Vec<String> {
|
||||||
let mut res = vec![];
|
let mut res = vec![];
|
||||||
if let Some(type_params) = node.type_param_list() {
|
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.lifetime_params().map(|p| p.syntax().text().to_string()));
|
||||||
res.extend(type_params.type_params().map(|p| p.syntax().text().to_string()));
|
res.extend(type_params.type_params().map(|p| p.syntax().text().to_string()));
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn where_predicates<N: TypeParamsOwner>(node: &N) -> Vec<String> {
|
pub(crate) fn where_predicates<N: TypeParamsOwner>(node: &N) -> Vec<String> {
|
||||||
let mut res = vec![];
|
let mut res = vec![];
|
||||||
if let Some(clause) = node.where_clause() {
|
if let Some(clause) = node.where_clause() {
|
||||||
res.extend(clause.predicates().map(|p| p.syntax().text().to_string()));
|
res.extend(clause.predicates().map(|p| p.syntax().text().to_string()));
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue