5220: Fix lookup in tests r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-07-04 13:06:04 +00:00 committed by GitHub
commit 1ee524bb42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 140 additions and 182 deletions

View file

@ -54,24 +54,24 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; use expect::{expect, Expect};
use insta::assert_debug_snapshot;
fn do_magic_completion(code: &str) -> Vec<CompletionItem> { use crate::completion::{test_utils::do_completion, CompletionKind};
do_completion(code, CompletionKind::Magic)
fn check(ra_fixture: &str, expect: Expect) {
let actual = do_completion(ra_fixture, CompletionKind::Magic);
expect.assert_debug_eq(&actual);
} }
#[test] #[test]
fn test_param_completion_last_param() { fn test_param_completion_last_param() {
assert_debug_snapshot!( check(
do_magic_completion( r#"
r" fn foo(file_id: FileId) {}
fn foo(file_id: FileId) {} fn bar(file_id: FileId) {}
fn bar(file_id: FileId) {} fn baz(file<|>) {}
fn baz(file<|>) {} "#,
", expect![[r#"
),
@r###"
[ [
CompletionItem { CompletionItem {
label: "file_id: FileId", label: "file_id: FileId",
@ -81,21 +81,19 @@ mod tests {
lookup: "file_id", lookup: "file_id",
}, },
] ]
"### "#]],
); );
} }
#[test] #[test]
fn test_param_completion_nth_param() { fn test_param_completion_nth_param() {
assert_debug_snapshot!( check(
do_magic_completion( r#"
r" fn foo(file_id: FileId) {}
fn foo(file_id: FileId) {} fn bar(file_id: FileId) {}
fn bar(file_id: FileId) {} fn baz(file<|>, x: i32) {}
fn baz(file<|>, x: i32) {} "#,
", expect![[r#"
),
@r###"
[ [
CompletionItem { CompletionItem {
label: "file_id: FileId", label: "file_id: FileId",
@ -105,24 +103,22 @@ mod tests {
lookup: "file_id", lookup: "file_id",
}, },
] ]
"### "#]],
); );
} }
#[test] #[test]
fn test_param_completion_trait_param() { fn test_param_completion_trait_param() {
assert_debug_snapshot!( check(
do_magic_completion( r#"
r" pub(crate) trait SourceRoot {
pub(crate) trait SourceRoot {
pub fn contains(&self, file_id: FileId) -> bool; pub fn contains(&self, file_id: FileId) -> bool;
pub fn module_map(&self) -> &ModuleMap; pub fn module_map(&self) -> &ModuleMap;
pub fn lines(&self, file_id: FileId) -> &LineIndex; pub fn lines(&self, file_id: FileId) -> &LineIndex;
pub fn syntax(&self, file<|>) pub fn syntax(&self, file<|>)
} }
", "#,
), expect![[r#"
@r###"
[ [
CompletionItem { CompletionItem {
label: "file_id: FileId", label: "file_id: FileId",
@ -132,7 +128,7 @@ mod tests {
lookup: "file_id", lookup: "file_id",
}, },
] ]
"### "#]],
); );
} }
} }

View file

@ -15,130 +15,27 @@ pub(super) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &Compl
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use insta::assert_debug_snapshot; use expect::{expect, Expect};
use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; use crate::completion::{test_utils::completion_list, CompletionKind};
fn do_reference_completion(code: &str) -> Vec<CompletionItem> { fn check(ra_fixture: &str, expect: Expect) {
do_completion(code, CompletionKind::Reference) let actual = completion_list(ra_fixture, CompletionKind::Reference);
expect.assert_eq(&actual)
} }
#[test] #[test]
fn completes_macros_as_item() { fn completes_macros_as_item() {
assert_debug_snapshot!( check(
do_reference_completion( r#"
" macro_rules! foo { () => {} }
//- /main.rs fn foo() {}
macro_rules! foo {
() => {}
}
fn foo() {} <|>
"#,
<|> expect![[r#"
" ma foo!() macro_rules! foo
), "#]],
@r###" )
[
CompletionItem {
label: "foo!(…)",
source_range: 48..48,
delete: 48..48,
insert: "foo!($0)",
kind: Macro,
detail: "macro_rules! foo",
},
]
"###
);
}
#[test]
fn completes_vec_macros_with_square_brackets() {
assert_debug_snapshot!(
do_reference_completion(
"
//- /main.rs
/// Creates a [`Vec`] containing the arguments.
///
/// - Create a [`Vec`] containing a given list of elements:
///
/// ```
/// let v = vec![1, 2, 3];
/// assert_eq!(v[0], 1);
/// assert_eq!(v[1], 2);
/// assert_eq!(v[2], 3);
/// ```
macro_rules! vec {
() => {}
}
fn foo() {}
<|>
"
),
@r###"
[
CompletionItem {
label: "vec![…]",
source_range: 282..282,
delete: 282..282,
insert: "vec![$0]",
kind: Macro,
detail: "macro_rules! vec",
documentation: Documentation(
"Creates a [`Vec`] containing the arguments.\n\n- Create a [`Vec`] containing a given list of elements:\n\n```\nlet v = vec![1, 2, 3];\nassert_eq!(v[0], 1);\nassert_eq!(v[1], 2);\nassert_eq!(v[2], 3);\n```",
),
},
]
"###
);
}
#[test]
fn completes_macros_braces_guessing() {
assert_debug_snapshot!(
do_reference_completion(
"
//- /main.rs
/// Foo
///
/// Not call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`.
/// Call as `let _=foo! { hello world };`
macro_rules! foo {
() => {}
}
fn main() {
<|>
}
"
),
@r###"
[
CompletionItem {
label: "foo! {…}",
source_range: 164..164,
delete: 164..164,
insert: "foo! {$0}",
kind: Macro,
detail: "macro_rules! foo",
documentation: Documentation(
"Foo\n\nNot call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`.\nCall as `let _=foo! { hello world };`",
),
},
CompletionItem {
label: "main()",
source_range: 164..164,
delete: 164..164,
insert: "main()$0",
kind: Function,
lookup: "main",
detail: "fn main()",
},
]
"###
);
} }
} }

View file

@ -130,6 +130,7 @@ mod tests {
delete: 90..90, delete: 90..90,
insert: "m!($0)", insert: "m!($0)",
kind: Macro, kind: Macro,
lookup: "m!",
detail: "macro_rules! m", detail: "macro_rules! m",
}, },
] ]

View file

@ -1189,6 +1189,7 @@ mod tests {
delete: 82..82, delete: 82..82,
insert: "foo!($0)", insert: "foo!($0)",
kind: Macro, kind: Macro,
lookup: "foo!",
detail: "#[macro_export]\nmacro_rules! foo", detail: "#[macro_export]\nmacro_rules! foo",
}, },
CompletionItem { CompletionItem {

View file

@ -785,6 +785,7 @@ mod tests {
delete: 256..256, delete: 256..256,
insert: "bar!($0)", insert: "bar!($0)",
kind: Macro, kind: Macro,
lookup: "bar!",
detail: "macro_rules! bar", detail: "macro_rules! bar",
}, },
CompletionItem { CompletionItem {
@ -793,6 +794,7 @@ mod tests {
delete: 256..256, delete: 256..256,
insert: "baz!($0)", insert: "baz!($0)",
kind: Macro, kind: Macro,
lookup: "baz!",
detail: "#[macro_export]\nmacro_rules! baz", detail: "#[macro_export]\nmacro_rules! baz",
}, },
CompletionItem { CompletionItem {
@ -801,6 +803,7 @@ mod tests {
delete: 256..256, delete: 256..256,
insert: "foo!($0)", insert: "foo!($0)",
kind: Macro, kind: Macro,
lookup: "foo!",
detail: "macro_rules! foo", detail: "macro_rules! foo",
}, },
CompletionItem { CompletionItem {
@ -854,6 +857,7 @@ mod tests {
delete: 50..50, delete: 50..50,
insert: "foo!($0)", insert: "foo!($0)",
kind: Macro, kind: Macro,
lookup: "foo!",
detail: "macro_rules! foo", detail: "macro_rules! foo",
}, },
CompletionItem { CompletionItem {
@ -893,6 +897,7 @@ mod tests {
delete: 58..58, delete: 58..58,
insert: "foo!($0)", insert: "foo!($0)",
kind: Macro, kind: Macro,
lookup: "foo!",
detail: "macro_rules! foo", detail: "macro_rules! foo",
}, },
CompletionItem { CompletionItem {
@ -932,6 +937,7 @@ mod tests {
delete: 51..51, delete: 51..51,
insert: "foo!($0)", insert: "foo!($0)",
kind: Macro, kind: Macro,
lookup: "foo!",
detail: "macro_rules! foo", detail: "macro_rules! foo",
}, },
CompletionItem { CompletionItem {
@ -1005,6 +1011,7 @@ mod tests {
delete: 80..80, delete: 80..80,
insert: "m!($0)", insert: "m!($0)",
kind: Macro, kind: Macro,
lookup: "m!",
detail: "macro_rules! m", detail: "macro_rules! m",
}, },
CompletionItem { CompletionItem {
@ -1058,6 +1065,7 @@ mod tests {
delete: 80..81, delete: 80..81,
insert: "m!($0)", insert: "m!($0)",
kind: Macro, kind: Macro,
lookup: "m!",
detail: "macro_rules! m", detail: "macro_rules! m",
}, },
CompletionItem { CompletionItem {
@ -1111,6 +1119,7 @@ mod tests {
delete: 80..81, delete: 80..81,
insert: "m!($0)", insert: "m!($0)",
kind: Macro, kind: Macro,
lookup: "m!",
detail: "macro_rules! m", detail: "macro_rules! m",
}, },
CompletionItem { CompletionItem {

View file

@ -174,6 +174,7 @@ impl Completions {
builder builder
.insert_snippet(cap, format!("{}!{}$0{}", name, bra, ket)) .insert_snippet(cap, format!("{}!{}$0{}", name, bra, ket))
.label(format!("{}!{}{}", name, bra, ket)) .label(format!("{}!{}{}", name, bra, ket))
.lookup_by(format!("{}!", name))
} }
None if needs_bang => builder.insert_text(format!("{}!", name)), None if needs_bang => builder.insert_text(format!("{}!", name)),
_ => { _ => {
@ -1079,4 +1080,57 @@ fn go(world: &WorldSnapshot) { go(w<|>) }
"#]], "#]],
); );
} }
#[test]
fn guesses_macro_braces() {
check_edit(
"vec!",
r#"
/// Creates a [`Vec`] containing the arguments.
///
/// ```
/// let v = vec![1, 2, 3];
/// assert_eq!(v[0], 1);
/// assert_eq!(v[1], 2);
/// assert_eq!(v[2], 3);
/// ```
macro_rules! vec { () => {} }
fn fn main() { v<|> }
"#,
r#"
/// Creates a [`Vec`] containing the arguments.
///
/// ```
/// let v = vec![1, 2, 3];
/// assert_eq!(v[0], 1);
/// assert_eq!(v[1], 2);
/// assert_eq!(v[2], 3);
/// ```
macro_rules! vec { () => {} }
fn fn main() { vec![$0] }
"#,
);
check_edit(
"foo!",
r#"
/// Foo
///
/// Don't call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`,
/// call as `let _=foo! { hello world };`
macro_rules! foo { () => {} }
fn main() { <|> }
"#,
r#"
/// Foo
///
/// Don't call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`,
/// call as `let _=foo! { hello world };`
macro_rules! foo { () => {} }
fn main() { foo! {$0} }
"#,
)
}
} }