aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions/keyword.rs
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-03-03 20:58:48 +0000
committerLukas Wirth <[email protected]>2021-03-03 20:58:48 +0000
commit1914b7723f2f77a7259c65c888107e95f00d0ba1 (patch)
tree203572db4c48694c2bdd00987edb9a4b412a0384 /crates/ide_completion/src/completions/keyword.rs
parentd0fa7abc5044471b951149aa35244620db847ff9 (diff)
Don't complete `super` unless its valid in paths
Diffstat (limited to 'crates/ide_completion/src/completions/keyword.rs')
-rw-r--r--crates/ide_completion/src/completions/keyword.rs27
1 files changed, 20 insertions, 7 deletions
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs
index eb81f9765..17bd19522 100644
--- a/crates/ide_completion/src/completions/keyword.rs
+++ b/crates/ide_completion/src/completions/keyword.rs
@@ -1,5 +1,7 @@
1//! Completes keywords. 1//! Completes keywords.
2 2
3use std::iter;
4
3use syntax::SyntaxKind; 5use syntax::SyntaxKind;
4use test_utils::mark; 6use test_utils::mark;
5 7
@@ -19,10 +21,14 @@ pub(crate) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC
19 CompletionItem::new(CompletionKind::Keyword, source_range, "self") 21 CompletionItem::new(CompletionKind::Keyword, source_range, "self")
20 .kind(CompletionItemKind::Keyword) 22 .kind(CompletionItemKind::Keyword)
21 .add_to(acc); 23 .add_to(acc);
22 CompletionItem::new(CompletionKind::Keyword, source_range, "super::") 24 if iter::successors(ctx.path_qual.clone(), |p| p.qualifier())
23 .kind(CompletionItemKind::Keyword) 25 .all(|p| p.segment().and_then(|s| s.super_token()).is_some())
24 .insert_text("super::") 26 {
25 .add_to(acc); 27 CompletionItem::new(CompletionKind::Keyword, source_range, "super::")
28 .kind(CompletionItemKind::Keyword)
29 .insert_text("super::")
30 .add_to(acc);
31 }
26 } 32 }
27 33
28 // Suggest .await syntax for types that implement Future trait 34 // Suggest .await syntax for types that implement Future trait
@@ -204,9 +210,17 @@ mod tests {
204 "#]], 210 "#]],
205 ); 211 );
206 212
213 // FIXME: `self` shouldn't be shown here and the check below
207 check( 214 check(
208 r"use a::$0", 215 r"use a::$0",
209 expect![[r#" 216 expect![[r#"
217 kw self
218 "#]],
219 );
220
221 check(
222 r"use super::$0",
223 expect![[r#"
210 kw self 224 kw self
211 kw super:: 225 kw super::
212 "#]], 226 "#]],
@@ -215,9 +229,8 @@ mod tests {
215 check( 229 check(
216 r"use a::{b, $0}", 230 r"use a::{b, $0}",
217 expect![[r#" 231 expect![[r#"
218 kw self 232 kw self
219 kw super:: 233 "#]],
220 "#]],
221 ); 234 );
222 } 235 }
223 236