aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-06-16 16:56:04 +0100
committerLukas Wirth <[email protected]>2021-06-16 20:51:20 +0100
commit9ea6ee6b2785da02ff1963fbbc2eea340450905c (patch)
tree6ee0a69dc2e44eb04c1f7e3841a423da4b2bf4ca /crates/ide_completion/src/completions
parent1a8f76a224aff472cf29bab828f313c19e31eb02 (diff)
Don't show incorrect completions after unsafe or visiblity node
Diffstat (limited to 'crates/ide_completion/src/completions')
-rw-r--r--crates/ide_completion/src/completions/keyword.rs22
-rw-r--r--crates/ide_completion/src/completions/snippet.rs7
2 files changed, 18 insertions, 11 deletions
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs
index 0bfdf9603..7970e75c7 100644
--- a/crates/ide_completion/src/completions/keyword.rs
+++ b/crates/ide_completion/src/completions/keyword.rs
@@ -90,11 +90,13 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
90 } 90 }
91 91
92 if expects_item || has_block_expr_parent { 92 if expects_item || has_block_expr_parent {
93 if !ctx.has_visibility_prev_sibling() {
94 add_keyword("impl", "impl $1 {\n $0\n}");
95 add_keyword("extern", "extern $0");
96 }
93 add_keyword("use", "use $0"); 97 add_keyword("use", "use $0");
94 add_keyword("impl", "impl $1 {\n $0\n}");
95 add_keyword("trait", "trait $1 {\n $0\n}"); 98 add_keyword("trait", "trait $1 {\n $0\n}");
96 add_keyword("static", "static $0"); 99 add_keyword("static", "static $0");
97 add_keyword("extern", "extern $0");
98 add_keyword("mod", "mod $0"); 100 add_keyword("mod", "mod $0");
99 } 101 }
100 102
@@ -241,11 +243,11 @@ mod tests {
241 kw fn 243 kw fn
242 kw const 244 kw const
243 kw type 245 kw type
244 kw use
245 kw impl 246 kw impl
247 kw extern
248 kw use
246 kw trait 249 kw trait
247 kw static 250 kw static
248 kw extern
249 kw mod 251 kw mod
250 kw match 252 kw match
251 kw while 253 kw while
@@ -269,11 +271,11 @@ mod tests {
269 kw fn 271 kw fn
270 kw const 272 kw const
271 kw type 273 kw type
272 kw use
273 kw impl 274 kw impl
275 kw extern
276 kw use
274 kw trait 277 kw trait
275 kw static 278 kw static
276 kw extern
277 kw mod 279 kw mod
278 kw match 280 kw match
279 kw while 281 kw while
@@ -297,11 +299,11 @@ mod tests {
297 kw fn 299 kw fn
298 kw const 300 kw const
299 kw type 301 kw type
300 kw use
301 kw impl 302 kw impl
303 kw extern
304 kw use
302 kw trait 305 kw trait
303 kw static 306 kw static
304 kw extern
305 kw mod 307 kw mod
306 kw match 308 kw match
307 kw while 309 kw while
@@ -399,11 +401,11 @@ fn quux() -> i32 {
399 kw fn 401 kw fn
400 kw const 402 kw const
401 kw type 403 kw type
402 kw use
403 kw impl 404 kw impl
405 kw extern
406 kw use
404 kw trait 407 kw trait
405 kw static 408 kw static
406 kw extern
407 kw mod 409 kw mod
408 kw match 410 kw match
409 kw while 411 kw while
diff --git a/crates/ide_completion/src/completions/snippet.rs b/crates/ide_completion/src/completions/snippet.rs
index 5560f1acf..4e64a0090 100644
--- a/crates/ide_completion/src/completions/snippet.rs
+++ b/crates/ide_completion/src/completions/snippet.rs
@@ -1,6 +1,7 @@
1//! This file provides snippet completions, like `pd` => `eprintln!(...)`. 1//! This file provides snippet completions, like `pd` => `eprintln!(...)`.
2 2
3use ide_db::helpers::SnippetCap; 3use ide_db::helpers::SnippetCap;
4use syntax::T;
4 5
5use crate::{ 6use crate::{
6 context::PathCompletionContext, item::Builder, CompletionContext, CompletionItem, 7 context::PathCompletionContext, item::Builder, CompletionContext, CompletionItem,
@@ -35,9 +36,13 @@ pub(crate) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionConte
35} 36}
36 37
37pub(crate) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) { 38pub(crate) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) {
38 if !ctx.expects_item() { 39 if !ctx.expects_item() || ctx.previous_token_is(T![unsafe]) {
39 return; 40 return;
40 } 41 }
42 if ctx.has_visibility_prev_sibling() {
43 return; // technically we could do some of these snippet completions if we were to put the
44 // attributes before the vis node.
45 }
41 let cap = match ctx.config.snippet_cap { 46 let cap = match ctx.config.snippet_cap {
42 Some(it) => it, 47 Some(it) => it,
43 None => return, 48 None => return,