mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Don't complete paths after attributes
This commit is contained in:
parent
9ea6ee6b27
commit
11115ebad8
7 changed files with 151 additions and 163 deletions
|
@ -349,49 +349,6 @@ fn quux() -> i32 {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_keywords_in_trait_def() {
|
|
||||||
check(
|
|
||||||
r"trait My { $0 }",
|
|
||||||
expect![[r#"
|
|
||||||
kw unsafe
|
|
||||||
kw fn
|
|
||||||
kw const
|
|
||||||
kw type
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_keywords_in_impl_def() {
|
|
||||||
check(
|
|
||||||
r"impl My { $0 }",
|
|
||||||
expect![[r#"
|
|
||||||
kw pub(crate)
|
|
||||||
kw pub
|
|
||||||
kw unsafe
|
|
||||||
kw fn
|
|
||||||
kw const
|
|
||||||
kw type
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_keywords_in_impl_def_with_attr() {
|
|
||||||
check(
|
|
||||||
r"impl My { #[foo] $0 }",
|
|
||||||
expect![[r#"
|
|
||||||
kw pub(crate)
|
|
||||||
kw pub
|
|
||||||
kw unsafe
|
|
||||||
kw fn
|
|
||||||
kw const
|
|
||||||
kw type
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_keywords_in_loop() {
|
fn test_keywords_in_loop() {
|
||||||
check(
|
check(
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub(crate) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionConte
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) {
|
pub(crate) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
if !ctx.expects_item() || ctx.previous_token_is(T![unsafe]) {
|
if !ctx.expects_item() || ctx.previous_token_is(T![unsafe]) || ctx.path_qual().is_some() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ctx.has_visibility_prev_sibling() {
|
if ctx.has_visibility_prev_sibling() {
|
||||||
|
|
|
@ -500,18 +500,6 @@ fn f() {$0}
|
||||||
check(
|
check(
|
||||||
r#"
|
r#"
|
||||||
#[rustc_builtin_macro]
|
#[rustc_builtin_macro]
|
||||||
pub macro Clone {}
|
|
||||||
|
|
||||||
struct S;
|
|
||||||
impl S {
|
|
||||||
$0
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#""#]],
|
|
||||||
);
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
#[rustc_builtin_macro]
|
|
||||||
pub macro bench {}
|
pub macro bench {}
|
||||||
|
|
||||||
fn f() {$0}
|
fn f() {$0}
|
||||||
|
@ -772,42 +760,6 @@ impl My$0
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_in_assoc_item_list() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
macro_rules! foo {}
|
|
||||||
mod bar {}
|
|
||||||
|
|
||||||
struct MyStruct {}
|
|
||||||
impl MyStruct {
|
|
||||||
$0
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
md bar
|
|
||||||
ma foo!(…) macro_rules! foo
|
|
||||||
"#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_in_item_list() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
struct MyStruct {}
|
|
||||||
macro_rules! foo {}
|
|
||||||
mod bar {}
|
|
||||||
|
|
||||||
$0
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
md bar
|
|
||||||
ma foo!(…) macro_rules! foo
|
|
||||||
"#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_types_and_const_in_arg_list() {
|
fn completes_types_and_const_in_arg_list() {
|
||||||
check(
|
check(
|
||||||
|
|
|
@ -313,7 +313,10 @@ impl<'a> CompletionContext<'a> {
|
||||||
pub(crate) fn is_path_disallowed(&self) -> bool {
|
pub(crate) fn is_path_disallowed(&self) -> bool {
|
||||||
self.attribute_under_caret.is_some()
|
self.attribute_under_caret.is_some()
|
||||||
|| self.previous_token_is(T![unsafe])
|
|| self.previous_token_is(T![unsafe])
|
||||||
|| self.has_visibility_prev_sibling()
|
|| matches!(
|
||||||
|
self.prev_sibling,
|
||||||
|
Some(ImmediatePrevSibling::Attribute) | Some(ImmediatePrevSibling::Visibility)
|
||||||
|
)
|
||||||
|| matches!(
|
|| matches!(
|
||||||
self.completion_location,
|
self.completion_location,
|
||||||
Some(ImmediateLocation::Attribute(_))
|
Some(ImmediateLocation::Attribute(_))
|
||||||
|
|
|
@ -20,6 +20,7 @@ pub(crate) enum ImmediatePrevSibling {
|
||||||
TraitDefName,
|
TraitDefName,
|
||||||
ImplDefType,
|
ImplDefType,
|
||||||
Visibility,
|
Visibility,
|
||||||
|
Attribute,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Direct parent "thing" of what we are currently completing.
|
/// Direct parent "thing" of what we are currently completing.
|
||||||
|
@ -113,6 +114,7 @@ pub(crate) fn determine_prev_sibling(name_like: &ast::NameLike) -> Option<Immedi
|
||||||
} else {
|
} else {
|
||||||
return None
|
return None
|
||||||
},
|
},
|
||||||
|
ast::Attr(_it) => ImmediatePrevSibling::Attribute,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -438,4 +440,9 @@ mod tests {
|
||||||
fn test_vis_prev_sibling() {
|
fn test_vis_prev_sibling() {
|
||||||
check_prev_sibling(r"pub w$0", ImmediatePrevSibling::Visibility);
|
check_prev_sibling(r"pub w$0", ImmediatePrevSibling::Visibility);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_attr_prev_sibling() {
|
||||||
|
check_prev_sibling(r"#[attr] w$0", ImmediatePrevSibling::Attribute);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,17 @@ fn completion_list_with_config(config: CompletionConfig, code: &str) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check(ra_fixture: &str, expect: Expect) {
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
let actual = completion_list(ra_fixture);
|
let base = r#"#[rustc_builtin_macro]
|
||||||
|
pub macro Clone {}
|
||||||
|
enum Enum { Variant }
|
||||||
|
struct Struct {}
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! foo {}
|
||||||
|
mod bar {}
|
||||||
|
const CONST: () = ();
|
||||||
|
trait Trait {}
|
||||||
|
"#;
|
||||||
|
let actual = completion_list(&format!("{}{}", base, ra_fixture));
|
||||||
expect.assert_eq(&actual)
|
expect.assert_eq(&actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,64 @@ fn in_mod_item_list() {
|
||||||
$0
|
$0
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
expect![[r##"
|
||||||
|
kw pub(crate)
|
||||||
|
kw pub
|
||||||
|
kw unsafe
|
||||||
|
kw fn
|
||||||
|
kw const
|
||||||
|
kw type
|
||||||
|
kw impl
|
||||||
|
kw extern
|
||||||
|
kw use
|
||||||
|
kw trait
|
||||||
|
kw static
|
||||||
|
kw mod
|
||||||
|
kw enum
|
||||||
|
kw struct
|
||||||
|
kw union
|
||||||
|
sn tmod (Test module)
|
||||||
|
sn tfn (Test function)
|
||||||
|
sn macro_rules
|
||||||
|
ma foo!(…) #[macro_export] macro_rules! foo
|
||||||
|
"##]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_source_file_item_list() {
|
||||||
|
check(
|
||||||
|
r#"$0"#,
|
||||||
|
expect![[r##"
|
||||||
|
kw pub(crate)
|
||||||
|
kw pub
|
||||||
|
kw unsafe
|
||||||
|
kw fn
|
||||||
|
kw const
|
||||||
|
kw type
|
||||||
|
kw impl
|
||||||
|
kw extern
|
||||||
|
kw use
|
||||||
|
kw trait
|
||||||
|
kw static
|
||||||
|
kw mod
|
||||||
|
kw enum
|
||||||
|
kw struct
|
||||||
|
kw union
|
||||||
|
sn tmod (Test module)
|
||||||
|
sn tfn (Test function)
|
||||||
|
sn macro_rules
|
||||||
|
md bar
|
||||||
|
ma foo!(…) #[macro_export] macro_rules! foo
|
||||||
|
ma foo!(…) #[macro_export] macro_rules! foo
|
||||||
|
"##]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_item_list_after_attr() {
|
||||||
|
check(
|
||||||
|
r#"#[attr] $0"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
kw pub(crate)
|
kw pub(crate)
|
||||||
kw pub
|
kw pub
|
||||||
|
@ -32,56 +90,10 @@ fn in_mod_item_list() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn in_source_file_item_list() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
enum Enum { Variant }
|
|
||||||
struct MyStruct {}
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! foo {}
|
|
||||||
mod bar {}
|
|
||||||
const CONST: () = ();
|
|
||||||
|
|
||||||
$0"#,
|
|
||||||
expect![[r##"
|
|
||||||
kw pub(crate)
|
|
||||||
kw pub
|
|
||||||
kw unsafe
|
|
||||||
kw fn
|
|
||||||
kw const
|
|
||||||
kw type
|
|
||||||
kw impl
|
|
||||||
kw extern
|
|
||||||
kw use
|
|
||||||
kw trait
|
|
||||||
kw static
|
|
||||||
kw mod
|
|
||||||
kw enum
|
|
||||||
kw struct
|
|
||||||
kw union
|
|
||||||
sn tmod (Test module)
|
|
||||||
sn tfn (Test function)
|
|
||||||
sn macro_rules
|
|
||||||
md bar
|
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
|
||||||
"##]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn in_qualified_path() {
|
fn in_qualified_path() {
|
||||||
check(
|
check(
|
||||||
r#"
|
r#"crate::$0"#,
|
||||||
enum Enum { Variant }
|
|
||||||
struct MyStruct {}
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! foo {}
|
|
||||||
mod bar {}
|
|
||||||
const CONST: () = ();
|
|
||||||
|
|
||||||
crate::$0"#,
|
|
||||||
expect![[r##"
|
expect![[r##"
|
||||||
kw pub(crate)
|
kw pub(crate)
|
||||||
kw pub
|
kw pub
|
||||||
|
@ -98,11 +110,8 @@ crate::$0"#,
|
||||||
kw enum
|
kw enum
|
||||||
kw struct
|
kw struct
|
||||||
kw union
|
kw union
|
||||||
sn tmod (Test module)
|
|
||||||
sn tfn (Test function)
|
|
||||||
sn macro_rules
|
|
||||||
md bar
|
md bar
|
||||||
ma foo!(…) #[macro_export] macro_rules! foo
|
ma foo!(…) #[macro_export] macro_rules! foo
|
||||||
"##]],
|
"##]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -110,15 +119,7 @@ crate::$0"#,
|
||||||
#[test]
|
#[test]
|
||||||
fn after_unsafe_token() {
|
fn after_unsafe_token() {
|
||||||
check(
|
check(
|
||||||
r#"
|
r#"unsafe $0"#,
|
||||||
enum Enum { Variant }
|
|
||||||
struct MyStruct {}
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! foo {}
|
|
||||||
mod bar {}
|
|
||||||
const CONST: () = ();
|
|
||||||
|
|
||||||
unsafe $0"#,
|
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
kw fn
|
kw fn
|
||||||
kw trait
|
kw trait
|
||||||
|
@ -130,15 +131,7 @@ unsafe $0"#,
|
||||||
#[test]
|
#[test]
|
||||||
fn after_visibility() {
|
fn after_visibility() {
|
||||||
check(
|
check(
|
||||||
r#"
|
r#"pub $0"#,
|
||||||
enum Enum { Variant }
|
|
||||||
struct MyStruct {}
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! foo {}
|
|
||||||
mod bar {}
|
|
||||||
const CONST: () = ();
|
|
||||||
|
|
||||||
pub $0"#,
|
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
kw unsafe
|
kw unsafe
|
||||||
kw fn
|
kw fn
|
||||||
|
@ -154,3 +147,69 @@ pub $0"#,
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn after_visibility_unsafe() {
|
||||||
|
// FIXME this shouldn't show `impl`
|
||||||
|
check(
|
||||||
|
r#"pub unsafe $0"#,
|
||||||
|
expect![[r#"
|
||||||
|
kw fn
|
||||||
|
kw trait
|
||||||
|
kw impl
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_impl_assoc_item_list() {
|
||||||
|
check(
|
||||||
|
r#"impl Struct {
|
||||||
|
$0
|
||||||
|
}"#,
|
||||||
|
expect![[r##"
|
||||||
|
kw pub(crate)
|
||||||
|
kw pub
|
||||||
|
kw unsafe
|
||||||
|
kw fn
|
||||||
|
kw const
|
||||||
|
kw type
|
||||||
|
md bar
|
||||||
|
ma foo!(…) #[macro_export] macro_rules! foo
|
||||||
|
ma foo!(…) #[macro_export] macro_rules! foo
|
||||||
|
"##]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_impl_assoc_item_list_after_attr() {
|
||||||
|
check(
|
||||||
|
r#"impl Struct {
|
||||||
|
#[attr] $0
|
||||||
|
}"#,
|
||||||
|
expect![[r#"
|
||||||
|
kw pub(crate)
|
||||||
|
kw pub
|
||||||
|
kw unsafe
|
||||||
|
kw fn
|
||||||
|
kw const
|
||||||
|
kw type
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_trait_assoc_item_list() {
|
||||||
|
check(
|
||||||
|
r"trait Foo { $0 }",
|
||||||
|
expect![[r##"
|
||||||
|
kw unsafe
|
||||||
|
kw fn
|
||||||
|
kw const
|
||||||
|
kw type
|
||||||
|
md bar
|
||||||
|
ma foo!(…) #[macro_export] macro_rules! foo
|
||||||
|
ma foo!(…) #[macro_export] macro_rules! foo
|
||||||
|
"##]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue