Compress attribute completion tests

This commit is contained in:
Aleksey Kladov 2020-07-03 15:38:20 +02:00
parent ef6a6d75d5
commit f1671f460b

View file

@ -46,7 +46,7 @@ fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attr
_ => {} _ => {}
} }
if attribute.kind() == ast::AttrKind::Inner || !attr_completion.should_be_inner { if attribute.kind() == ast::AttrKind::Inner || !attr_completion.prefer_inner {
acc.add(item); acc.add(item);
} }
} }
@ -56,159 +56,72 @@ struct AttrCompletion {
label: &'static str, label: &'static str,
lookup: Option<&'static str>, lookup: Option<&'static str>,
snippet: Option<&'static str>, snippet: Option<&'static str>,
should_be_inner: bool, prefer_inner: bool,
}
impl AttrCompletion {
const fn prefer_inner(self) -> AttrCompletion {
AttrCompletion { prefer_inner: true, ..self }
}
}
const fn attr(
label: &'static str,
lookup: Option<&'static str>,
snippet: Option<&'static str>,
) -> AttrCompletion {
AttrCompletion { label, lookup, snippet, prefer_inner: false }
} }
const ATTRIBUTES: &[AttrCompletion] = &[ const ATTRIBUTES: &[AttrCompletion] = &[
AttrCompletion { attr("allow(…)", Some("allow"), Some("allow(${0:lint})")),
label: "allow(…)", attr("cfg_attr(…)", Some("cfg_attr"), Some("cfg_attr(${1:predicate}, ${0:attr})")),
snippet: Some("allow(${0:lint})"), attr("cfg(…)", Some("cfg"), Some("cfg(${0:predicate})")),
should_be_inner: false, attr("deny(…)", Some("deny"), Some("deny(${0:lint})")),
lookup: Some("allow"), attr(r#"deprecated = "…""#, Some("deprecated"), Some(r#"deprecated = "${0:reason}""#)),
}, attr("derive(…)", Some("derive"), Some(r#"derive(${0:Debug})"#)),
AttrCompletion { attr(r#"doc = "…""#, Some("doc"), Some(r#"doc = "${0:docs}""#)),
label: "cfg_attr(…)", attr("feature(…)", Some("feature"), Some("feature(${0:flag})")).prefer_inner(),
snippet: Some("cfg_attr(${1:predicate}, ${0:attr})"), attr("forbid(…)", Some("forbid"), Some("forbid(${0:lint})")),
should_be_inner: false,
lookup: Some("cfg_attr"),
},
AttrCompletion {
label: "cfg(…)",
snippet: Some("cfg(${0:predicate})"),
should_be_inner: false,
lookup: Some("cfg"),
},
AttrCompletion {
label: "deny(…)",
snippet: Some("deny(${0:lint})"),
should_be_inner: false,
lookup: Some("deny"),
},
AttrCompletion {
label: r#"deprecated = """#,
snippet: Some(r#"deprecated = "${0:reason}""#),
should_be_inner: false,
lookup: Some("deprecated"),
},
AttrCompletion {
label: "derive(…)",
snippet: Some(r#"derive(${0:Debug})"#),
should_be_inner: false,
lookup: Some("derive"),
},
AttrCompletion {
label: r#"doc = """#,
snippet: Some(r#"doc = "${0:docs}""#),
should_be_inner: false,
lookup: Some("doc"),
},
AttrCompletion {
label: "feature(…)",
snippet: Some("feature(${0:flag})"),
should_be_inner: true,
lookup: Some("feature"),
},
AttrCompletion {
label: "forbid(…)",
snippet: Some("forbid(${0:lint})"),
should_be_inner: false,
lookup: Some("forbid"),
},
// FIXME: resolve through macro resolution? // FIXME: resolve through macro resolution?
AttrCompletion { attr("global_allocator", None, None).prefer_inner(),
label: "global_allocator", attr("ignore(…)", Some("ignore"), Some("ignore(${0:lint})")),
snippet: None, attr("inline(…)", Some("inline"), Some("inline(${0:lint})")),
should_be_inner: true, attr(r#"link_name = "…""#, Some("link_name"), Some(r#"link_name = "${0:symbol_name}""#)),
lookup: None, attr("link", None, None),
}, attr("macro_export", None, None),
AttrCompletion { attr("macro_use", None, None),
label: "ignore(…)", attr(r#"must_use = "…""#, Some("must_use"), Some(r#"must_use = "${0:reason}""#)),
snippet: Some("ignore(${0:lint})"), attr("no_mangle", None, None),
should_be_inner: false, attr("no_std", None, None).prefer_inner(),
lookup: Some("ignore"), attr("non_exhaustive", None, None),
}, attr("panic_handler", None, None).prefer_inner(),
AttrCompletion { attr("path = \"\"", Some("path"), Some("path =\"${0:path}\"")),
label: "inline(…)", attr("proc_macro", None, None),
snippet: Some("inline(${0:lint})"), attr("proc_macro_attribute", None, None),
should_be_inner: false, attr("proc_macro_derive(…)", Some("proc_macro_derive"), Some("proc_macro_derive(${0:Trait})")),
lookup: Some("inline"), attr("recursion_limit = …", Some("recursion_limit"), Some("recursion_limit = ${0:128}"))
}, .prefer_inner(),
AttrCompletion { attr("repr(…)", Some("repr"), Some("repr(${0:C})")),
label: r#"link_name = """#, attr(
snippet: Some(r#"link_name = "${0:symbol_name}""#), "should_panic(…)",
should_be_inner: false, Some("should_panic"),
lookup: Some("link_name"), Some(r#"should_panic(expected = "${0:reason}")"#),
}, ),
AttrCompletion { label: "link", snippet: None, should_be_inner: false, lookup: None }, attr(
AttrCompletion { label: "macro_export", snippet: None, should_be_inner: false, lookup: None }, r#"target_feature = "…""#,
AttrCompletion { label: "macro_use", snippet: None, should_be_inner: false, lookup: None }, Some("target_feature"),
AttrCompletion { Some("target_feature = \"${0:feature}\""),
label: r#"must_use = """#, ),
snippet: Some(r#"must_use = "${0:reason}""#), attr("test", None, None),
should_be_inner: false, attr("used", None, None),
lookup: Some("must_use"), attr("warn(…)", Some("warn"), Some("warn(${0:lint})")),
}, attr(
AttrCompletion { label: "no_mangle", snippet: None, should_be_inner: false, lookup: None }, r#"windows_subsystem = "…""#,
AttrCompletion { label: "no_std", snippet: None, should_be_inner: true, lookup: None }, Some("windows_subsystem"),
AttrCompletion { label: "non_exhaustive", snippet: None, should_be_inner: false, lookup: None }, Some(r#"windows_subsystem = "${0:subsystem}""#),
AttrCompletion { label: "panic_handler", snippet: None, should_be_inner: true, lookup: None }, )
AttrCompletion { .prefer_inner(),
label: "path = \"\"",
snippet: Some("path =\"${0:path}\""),
should_be_inner: false,
lookup: Some("path"),
},
AttrCompletion { label: "proc_macro", snippet: None, should_be_inner: false, lookup: None },
AttrCompletion {
label: "proc_macro_attribute",
snippet: None,
should_be_inner: false,
lookup: None,
},
AttrCompletion {
label: "proc_macro_derive(…)",
snippet: Some("proc_macro_derive(${0:Trait})"),
should_be_inner: false,
lookup: Some("proc_macro_derive"),
},
AttrCompletion {
label: "recursion_limit = …",
snippet: Some("recursion_limit = ${0:128}"),
should_be_inner: true,
lookup: Some("recursion_limit"),
},
AttrCompletion {
label: "repr(…)",
snippet: Some("repr(${0:C})"),
should_be_inner: false,
lookup: Some("repr"),
},
AttrCompletion {
label: "should_panic(…)",
snippet: Some(r#"should_panic(expected = "${0:reason}")"#),
should_be_inner: false,
lookup: Some("should_panic"),
},
AttrCompletion {
label: r#"target_feature = """#,
snippet: Some("target_feature = \"${0:feature}\""),
should_be_inner: false,
lookup: Some("target_feature"),
},
AttrCompletion { label: "test", snippet: None, should_be_inner: false, lookup: None },
AttrCompletion { label: "used", snippet: None, should_be_inner: false, lookup: None },
AttrCompletion {
label: "warn(…)",
snippet: Some("warn(${0:lint})"),
should_be_inner: false,
lookup: Some("warn"),
},
AttrCompletion {
label: r#"windows_subsystem = """#,
snippet: Some(r#"windows_subsystem = "${0:subsystem}""#),
should_be_inner: true,
lookup: Some("windows_subsystem"),
},
]; ];
fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree) { fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree) {