- fn new(node: &ast::FnDef) -> Option<Self> {
- let label: String = if let Some(body) = node.body() {
- let body_range = body.syntax().range();
- let label: String = node
- .syntax()
- .children()
- .filter(|child| !child.range().is_subrange(&body_range)) // Filter out body
- .filter(|child| ast::Comment::cast(child).is_none()) // Filter out doc comments
- .map(|node| node.text().to_string())
- .collect();
- label
- } else {
- node.syntax().text().to_string()
- };
-
- let mut doc = None;
- if let Some(docs) = node.doc_comment_text() {
- // Massage markdown
- let mut processed_lines = Vec::new();
- let mut in_code_block = false;
- for line in docs.lines() {
- if line.starts_with("```") {
- in_code_block = !in_code_block;
- }
-
- let line = if in_code_block && line.starts_with("```") && !line.contains("rust") {
- "```rust".into()
- } else {
- line.to_string()
- };
-
- processed_lines.push(line);
- }
-
- doc = Some(processed_lines.join("\n"));
- }
+ fn new(db: &RootDatabase, function: hir::Function, node: &ast::FnDef) -> Option<Self> {
+ let label = crate::completion::function_label(node)?;
+ let doc = function.docs(db);