Support completion for macros

This commit is contained in:
uHOOCCOOHu 2019-09-10 13:32:47 +08:00
parent e2ebb467bd
commit 7de9537ccc
No known key found for this signature in database
GPG key ID: CED392DE0C483D00
4 changed files with 295 additions and 2 deletions

View file

@ -7,7 +7,7 @@ mod structure;
mod short_label;
use ra_syntax::{
ast::{self, AstNode, TypeParamsOwner},
ast::{self, AstNode, AttrsOwner, NameOwner, TypeParamsOwner},
SyntaxKind::{ATTR, COMMENT},
};
@ -61,6 +61,12 @@ pub(crate) fn where_predicates<N: TypeParamsOwner>(node: &N) -> Vec<String> {
res
}
pub(crate) fn macro_label(node: &ast::MacroCall) -> String {
let name = node.name().map(|name| name.syntax().text().to_string()).unwrap_or_default();
let vis = if node.has_atom_attr("macro_export") { "#[macro_export]\n" } else { "" };
format!("{}macro_rules! {}", vis, name)
}
pub(crate) fn rust_code_markup<CODE: AsRef<str>>(val: CODE) -> String {
rust_code_markup_with_doc::<_, &str>(val, None)
}