mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-22 19:34:16 +00:00
Don't show incorrect completions after unsafe or visiblity node
This commit is contained in:
parent
1a8f76a224
commit
9ea6ee6b27
4 changed files with 38 additions and 42 deletions
|
@ -90,11 +90,13 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
|
||||||
}
|
}
|
||||||
|
|
||||||
if expects_item || has_block_expr_parent {
|
if expects_item || has_block_expr_parent {
|
||||||
add_keyword("use", "use $0");
|
if !ctx.has_visibility_prev_sibling() {
|
||||||
add_keyword("impl", "impl $1 {\n $0\n}");
|
add_keyword("impl", "impl $1 {\n $0\n}");
|
||||||
|
add_keyword("extern", "extern $0");
|
||||||
|
}
|
||||||
|
add_keyword("use", "use $0");
|
||||||
add_keyword("trait", "trait $1 {\n $0\n}");
|
add_keyword("trait", "trait $1 {\n $0\n}");
|
||||||
add_keyword("static", "static $0");
|
add_keyword("static", "static $0");
|
||||||
add_keyword("extern", "extern $0");
|
|
||||||
add_keyword("mod", "mod $0");
|
add_keyword("mod", "mod $0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,11 +243,11 @@ mod tests {
|
||||||
kw fn
|
kw fn
|
||||||
kw const
|
kw const
|
||||||
kw type
|
kw type
|
||||||
kw use
|
|
||||||
kw impl
|
kw impl
|
||||||
|
kw extern
|
||||||
|
kw use
|
||||||
kw trait
|
kw trait
|
||||||
kw static
|
kw static
|
||||||
kw extern
|
|
||||||
kw mod
|
kw mod
|
||||||
kw match
|
kw match
|
||||||
kw while
|
kw while
|
||||||
|
@ -269,11 +271,11 @@ mod tests {
|
||||||
kw fn
|
kw fn
|
||||||
kw const
|
kw const
|
||||||
kw type
|
kw type
|
||||||
kw use
|
|
||||||
kw impl
|
kw impl
|
||||||
|
kw extern
|
||||||
|
kw use
|
||||||
kw trait
|
kw trait
|
||||||
kw static
|
kw static
|
||||||
kw extern
|
|
||||||
kw mod
|
kw mod
|
||||||
kw match
|
kw match
|
||||||
kw while
|
kw while
|
||||||
|
@ -297,11 +299,11 @@ mod tests {
|
||||||
kw fn
|
kw fn
|
||||||
kw const
|
kw const
|
||||||
kw type
|
kw type
|
||||||
kw use
|
|
||||||
kw impl
|
kw impl
|
||||||
|
kw extern
|
||||||
|
kw use
|
||||||
kw trait
|
kw trait
|
||||||
kw static
|
kw static
|
||||||
kw extern
|
|
||||||
kw mod
|
kw mod
|
||||||
kw match
|
kw match
|
||||||
kw while
|
kw while
|
||||||
|
@ -399,11 +401,11 @@ fn quux() -> i32 {
|
||||||
kw fn
|
kw fn
|
||||||
kw const
|
kw const
|
||||||
kw type
|
kw type
|
||||||
kw use
|
|
||||||
kw impl
|
kw impl
|
||||||
|
kw extern
|
||||||
|
kw use
|
||||||
kw trait
|
kw trait
|
||||||
kw static
|
kw static
|
||||||
kw extern
|
|
||||||
kw mod
|
kw mod
|
||||||
kw match
|
kw match
|
||||||
kw while
|
kw while
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! This file provides snippet completions, like `pd` => `eprintln!(...)`.
|
//! This file provides snippet completions, like `pd` => `eprintln!(...)`.
|
||||||
|
|
||||||
use ide_db::helpers::SnippetCap;
|
use ide_db::helpers::SnippetCap;
|
||||||
|
use syntax::T;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
context::PathCompletionContext, item::Builder, CompletionContext, CompletionItem,
|
context::PathCompletionContext, item::Builder, CompletionContext, CompletionItem,
|
||||||
|
@ -35,9 +36,13 @@ 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() {
|
if !ctx.expects_item() || ctx.previous_token_is(T![unsafe]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ctx.has_visibility_prev_sibling() {
|
||||||
|
return; // technically we could do some of these snippet completions if we were to put the
|
||||||
|
// attributes before the vis node.
|
||||||
|
}
|
||||||
let cap = match ctx.config.snippet_cap {
|
let cap = match ctx.config.snippet_cap {
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
None => return,
|
None => return,
|
||||||
|
|
|
@ -311,13 +311,16 @@ impl<'a> CompletionContext<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn is_path_disallowed(&self) -> bool {
|
pub(crate) fn is_path_disallowed(&self) -> bool {
|
||||||
matches!(
|
self.attribute_under_caret.is_some()
|
||||||
|
|| self.previous_token_is(T![unsafe])
|
||||||
|
|| self.has_visibility_prev_sibling()
|
||||||
|
|| matches!(
|
||||||
self.completion_location,
|
self.completion_location,
|
||||||
Some(ImmediateLocation::Attribute(_))
|
Some(ImmediateLocation::Attribute(_))
|
||||||
| Some(ImmediateLocation::ModDeclaration(_))
|
| Some(ImmediateLocation::ModDeclaration(_))
|
||||||
| Some(ImmediateLocation::RecordPat(_))
|
| Some(ImmediateLocation::RecordPat(_))
|
||||||
| Some(ImmediateLocation::RecordExpr(_))
|
| Some(ImmediateLocation::RecordExpr(_))
|
||||||
) || self.attribute_under_caret.is_some()
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn expects_expression(&self) -> bool {
|
pub(crate) fn expects_expression(&self) -> bool {
|
||||||
|
|
|
@ -16,11 +16,11 @@ fn in_mod_item_list() {
|
||||||
kw fn
|
kw fn
|
||||||
kw const
|
kw const
|
||||||
kw type
|
kw type
|
||||||
kw use
|
|
||||||
kw impl
|
kw impl
|
||||||
|
kw extern
|
||||||
|
kw use
|
||||||
kw trait
|
kw trait
|
||||||
kw static
|
kw static
|
||||||
kw extern
|
|
||||||
kw mod
|
kw mod
|
||||||
kw enum
|
kw enum
|
||||||
kw struct
|
kw struct
|
||||||
|
@ -51,11 +51,11 @@ $0"#,
|
||||||
kw fn
|
kw fn
|
||||||
kw const
|
kw const
|
||||||
kw type
|
kw type
|
||||||
kw use
|
|
||||||
kw impl
|
kw impl
|
||||||
|
kw extern
|
||||||
|
kw use
|
||||||
kw trait
|
kw trait
|
||||||
kw static
|
kw static
|
||||||
kw extern
|
|
||||||
kw mod
|
kw mod
|
||||||
kw enum
|
kw enum
|
||||||
kw struct
|
kw struct
|
||||||
|
@ -89,11 +89,11 @@ crate::$0"#,
|
||||||
kw fn
|
kw fn
|
||||||
kw const
|
kw const
|
||||||
kw type
|
kw type
|
||||||
kw use
|
|
||||||
kw impl
|
kw impl
|
||||||
|
kw extern
|
||||||
|
kw use
|
||||||
kw trait
|
kw trait
|
||||||
kw static
|
kw static
|
||||||
kw extern
|
|
||||||
kw mod
|
kw mod
|
||||||
kw enum
|
kw enum
|
||||||
kw struct
|
kw struct
|
||||||
|
@ -119,17 +119,11 @@ mod bar {}
|
||||||
const CONST: () = ();
|
const CONST: () = ();
|
||||||
|
|
||||||
unsafe $0"#,
|
unsafe $0"#,
|
||||||
expect![[r##"
|
expect![[r#"
|
||||||
kw fn
|
kw fn
|
||||||
kw trait
|
kw trait
|
||||||
kw impl
|
kw impl
|
||||||
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
|
|
||||||
"##]],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,26 +139,18 @@ mod bar {}
|
||||||
const CONST: () = ();
|
const CONST: () = ();
|
||||||
|
|
||||||
pub $0"#,
|
pub $0"#,
|
||||||
expect![[r##"
|
expect![[r#"
|
||||||
kw unsafe
|
kw unsafe
|
||||||
kw fn
|
kw fn
|
||||||
kw const
|
kw const
|
||||||
kw type
|
kw type
|
||||||
kw use
|
kw use
|
||||||
kw impl
|
|
||||||
kw trait
|
kw trait
|
||||||
kw static
|
kw static
|
||||||
kw extern
|
|
||||||
kw mod
|
kw mod
|
||||||
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
|
|
||||||
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