2019-01-08 22:33:36 +03:00
|
|
|
use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionItemKind, CompletionContext, completion_item::Builder};
|
|
|
|
|
2019-01-20 00:38:34 +08:00
|
|
|
fn snippet(ctx: &CompletionContext, label: &str, snippet: &str) -> Builder {
|
|
|
|
CompletionItem::new(CompletionKind::Snippet, ctx.leaf_range(), label)
|
2019-01-08 22:33:36 +03:00
|
|
|
.snippet(snippet)
|
|
|
|
.kind(CompletionItemKind::Snippet)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) {
|
|
|
|
if !(ctx.is_trivial_path && ctx.function_syntax.is_some()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-19 22:02:50 +08:00
|
|
|
snippet(ctx, "pd", "eprintln!(\"$0 = {:?}\", $0);").add_to(acc);
|
|
|
|
snippet(ctx, "ppd", "eprintln!(\"$0 = {:#?}\", $0);").add_to(acc);
|
2019-01-08 22:33:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) {
|
|
|
|
if !ctx.is_new_item {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
snippet(
|
2019-01-19 22:02:50 +08:00
|
|
|
ctx,
|
2019-01-08 22:33:36 +03:00
|
|
|
"Test function",
|
|
|
|
"\
|
|
|
|
#[test]
|
|
|
|
fn ${1:feature}() {
|
|
|
|
$0
|
|
|
|
}",
|
|
|
|
)
|
|
|
|
.lookup_by("tfn")
|
|
|
|
.add_to(acc);
|
|
|
|
|
2019-01-19 22:02:50 +08:00
|
|
|
snippet(ctx, "pub(crate)", "pub(crate) $0").add_to(acc);
|
2019-01-08 22:33:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2019-01-19 22:02:50 +08:00
|
|
|
use crate::completion::CompletionKind;
|
|
|
|
use crate::completion::completion_item::check_completion;
|
|
|
|
|
|
|
|
fn check_snippet_completion(name: &str, code: &str) {
|
|
|
|
check_completion(name, code, CompletionKind::Snippet);
|
2019-01-08 22:33:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn completes_snippets_in_expressions() {
|
2019-01-19 22:02:50 +08:00
|
|
|
check_snippet_completion("snippets_in_expressions", r"fn foo(x: i32) { <|> }");
|
2019-01-08 22:33:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn completes_snippets_in_items() {
|
|
|
|
check_snippet_completion(
|
2019-01-19 22:02:50 +08:00
|
|
|
"snippets_in_items",
|
2019-01-08 22:33:36 +03:00
|
|
|
r"
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
<|>
|
|
|
|
}
|
|
|
|
",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|