Pass Documentation up to LSP and add "rust" to our codeblocks there

This commit is contained in:
Jeremy Kolb 2019-01-29 21:39:09 -05:00
parent 48d2acb297
commit b88ba007cc
8 changed files with 103 additions and 89 deletions

View file

@ -10,6 +10,7 @@ mod complete_scope;
mod complete_postfix;
use ra_db::SourceDatabase;
use ra_syntax::ast::{self, AstNode};
use crate::{
db,
@ -61,3 +62,21 @@ pub(crate) fn completions(db: &db::RootDatabase, position: FilePosition) -> Opti
complete_postfix::complete_postfix(&mut acc, &ctx);
Some(acc)
}
pub fn function_label(node: &ast::FnDef) -> Option<String> {
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 comments
.map(|node| node.text().to_string())
.collect();
label
} else {
node.syntax().text().to_string()
};
Some(label.trim().to_owned())
}