mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
WIP: Expand signature help
This is hacky but works for tuple structs. Proof of concept.
This commit is contained in:
parent
02828520a7
commit
5a59bc9fcb
2 changed files with 60 additions and 8 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
use hir::{Docs, Documentation, HasSource};
|
||||
use hir::{Docs, Documentation, HasSource, HirDisplay};
|
||||
use join_to_string::join;
|
||||
use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner};
|
||||
use std::convert::From;
|
||||
|
@ -42,6 +42,33 @@ impl FunctionSignature {
|
|||
let ast_node = function.source(db).ast;
|
||||
FunctionSignature::from(&ast_node).with_doc_opt(doc)
|
||||
}
|
||||
|
||||
pub(crate) fn from_struct(db: &db::RootDatabase, st: hir::Struct) -> Self {
|
||||
let doc = st.docs(db);
|
||||
|
||||
let node: ast::StructDef = st.source(db).ast;
|
||||
|
||||
let params = st
|
||||
.fields(db)
|
||||
.into_iter()
|
||||
.map(|field: hir::StructField| {
|
||||
let name = field.name(db);
|
||||
let ty = field.ty(db);
|
||||
format!("{}: {}", name, ty.display(db))
|
||||
})
|
||||
.collect();
|
||||
|
||||
FunctionSignature {
|
||||
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()),
|
||||
parameters: /*param_list(node)*/ params,
|
||||
generic_parameters: generic_parameters(&node),
|
||||
where_predicates: where_predicates(&node),
|
||||
doc: None,
|
||||
}
|
||||
.with_doc_opt(doc)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'_ ast::FnDef> for FunctionSignature {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue