mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Add disciminant
This commit is contained in:
parent
5a59bc9fcb
commit
55d4b06a53
2 changed files with 17 additions and 7 deletions
|
@ -12,9 +12,16 @@ use crate::{
|
|||
display::{generic_parameters, where_predicates},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SigKind {
|
||||
Function,
|
||||
Struct,
|
||||
}
|
||||
|
||||
/// Contains information about a function signature
|
||||
#[derive(Debug)]
|
||||
pub struct FunctionSignature {
|
||||
pub kind: SigKind,
|
||||
/// Optional visibility
|
||||
pub visibility: Option<String>,
|
||||
/// Name of the function
|
||||
|
@ -59,6 +66,7 @@ impl FunctionSignature {
|
|||
.collect();
|
||||
|
||||
FunctionSignature {
|
||||
kind: SigKind::Struct,
|
||||
visibility: node.visibility().map(|n| n.syntax().text().to_string()),
|
||||
name: node.name().map(|n| n.text().to_string()),
|
||||
ret_type: node.name().map(|n| n.text().to_string()),
|
||||
|
@ -86,6 +94,7 @@ impl From<&'_ ast::FnDef> for FunctionSignature {
|
|||
}
|
||||
|
||||
FunctionSignature {
|
||||
kind: SigKind::Function,
|
||||
visibility: node.visibility().map(|n| n.syntax().text().to_string()),
|
||||
name: node.name().map(|n| n.text().to_string()),
|
||||
ret_type: node
|
||||
|
@ -108,7 +117,10 @@ impl Display for FunctionSignature {
|
|||
}
|
||||
|
||||
if let Some(name) = &self.name {
|
||||
write!(f, "fn {}", name)?;
|
||||
match self.kind {
|
||||
SigKind::Function => write!(f, "fn {}", name)?,
|
||||
SigKind::Struct => write!(f, "struct {}", name)?,
|
||||
}
|
||||
}
|
||||
|
||||
if !self.generic_parameters.is_empty() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue