2019-09-30 11:58:53 +03:00
|
|
|
//! FIXME: write short doc here
|
|
|
|
|
2019-02-24 23:49:47 +03:00
|
|
|
use crate::completion::{CompletionContext, Completions};
|
|
|
|
|
|
|
|
/// Completes constats and paths in patterns.
|
|
|
|
pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
|
2020-04-03 19:59:28 +02:00
|
|
|
if !ctx.is_pat_binding_or_const {
|
2019-02-24 23:49:47 +03:00
|
|
|
return;
|
|
|
|
}
|
2020-04-11 23:33:17 +02:00
|
|
|
if ctx.record_pat_syntax.is_some() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-23 10:53:48 +03:00
|
|
|
// FIXME: ideally, we should look at the type we are matching against and
|
2019-02-24 23:49:47 +03:00
|
|
|
// suggest variants + auto-imports
|
2020-02-18 18:35:10 +01:00
|
|
|
ctx.scope().process_all_names(&mut |name, res| {
|
2020-04-03 19:59:28 +02:00
|
|
|
match &res {
|
|
|
|
hir::ScopeDef::ModuleDef(def) => match def {
|
|
|
|
hir::ModuleDef::Adt(hir::Adt::Enum(..))
|
|
|
|
| hir::ModuleDef::Adt(hir::Adt::Struct(..))
|
|
|
|
| hir::ModuleDef::EnumVariant(..)
|
|
|
|
| hir::ModuleDef::Const(..)
|
|
|
|
| hir::ModuleDef::Module(..) => (),
|
|
|
|
_ => return,
|
|
|
|
},
|
|
|
|
hir::ScopeDef::MacroDef(_) => (),
|
2019-09-12 23:35:53 +03:00
|
|
|
_ => return,
|
2019-02-24 23:49:47 +03:00
|
|
|
};
|
2020-04-03 19:59:28 +02:00
|
|
|
|
2019-02-24 23:49:47 +03:00
|
|
|
acc.add_resolution(ctx, name.to_string(), &res)
|
2019-09-12 23:35:53 +03:00
|
|
|
});
|
2019-02-24 23:49:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-07-04 15:10:55 +02:00
|
|
|
use expect::{expect, Expect};
|
2019-02-24 23:49:47 +03:00
|
|
|
|
2020-07-04 15:10:55 +02:00
|
|
|
use crate::completion::{test_utils::completion_list, CompletionKind};
|
|
|
|
|
|
|
|
fn check(ra_fixture: &str, expect: Expect) {
|
|
|
|
let actual = completion_list(ra_fixture, CompletionKind::Reference);
|
|
|
|
expect.assert_eq(&actual)
|
2019-02-24 23:49:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn completes_enum_variants_and_modules() {
|
2020-07-04 15:10:55 +02:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
enum E { X }
|
|
|
|
use self::E::X;
|
|
|
|
const Z: E = E::X;
|
|
|
|
mod m {}
|
2019-02-24 23:49:47 +03:00
|
|
|
|
2020-07-04 15:10:55 +02:00
|
|
|
static FOO: E = E::X;
|
|
|
|
struct Bar { f: u32 }
|
2019-02-24 23:49:47 +03:00
|
|
|
|
2020-07-04 15:10:55 +02:00
|
|
|
fn foo() {
|
|
|
|
match E::X { <|> }
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
st Bar
|
|
|
|
en E
|
2020-07-04 19:03:58 +02:00
|
|
|
ev X ()
|
2020-07-04 15:10:55 +02:00
|
|
|
ct Z
|
|
|
|
md m
|
|
|
|
"#]],
|
2019-02-24 23:49:47 +03:00
|
|
|
);
|
|
|
|
}
|
2020-03-07 15:47:10 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn completes_in_simple_macro_call() {
|
2020-07-04 15:10:55 +02:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
macro_rules! m { ($e:expr) => { $e } }
|
|
|
|
enum E { X }
|
2020-03-07 15:47:10 +01:00
|
|
|
|
2020-07-04 15:10:55 +02:00
|
|
|
fn foo() {
|
|
|
|
m!(match E::X { <|> })
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
en E
|
|
|
|
ma m!(…) macro_rules! m
|
|
|
|
"#]],
|
2020-03-07 15:47:10 +01:00
|
|
|
);
|
|
|
|
}
|
2019-02-24 23:49:47 +03:00
|
|
|
}
|