]> git.lizzy.rs Git - rust.git/commitdiff
Properly reacto to keywords
authorKirill Bulatov <mail4score@gmail.com>
Mon, 7 Sep 2020 21:54:58 +0000 (00:54 +0300)
committerKirill Bulatov <mail4score@gmail.com>
Wed, 9 Sep 2020 22:42:20 +0000 (01:42 +0300)
crates/ide/src/completion/complete_attribute.rs
crates/ide/src/completion/complete_mod.rs
crates/ide/src/completion/complete_qualified_path.rs
crates/ide/src/completion/complete_unqualified_path.rs
crates/ide/src/completion/completion_context.rs
crates/ide/src/completion/patterns.rs

index 0abfaebcbc669f4b887d9f33560c8a6f3d2567f9..6394189f00c1904495cca004f57d6adbf32f7a2d 100644 (file)
 };
 
 pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
+    if ctx.mod_is_prev {
+        return None;
+    }
+
     let attribute = ctx.attribute_under_caret.as_ref()?;
     match (attribute.path(), attribute.token_tree()) {
         (Some(path), Some(token_tree)) if path.to_string() == "derive" => {
index c5757a31097d7dc74cfe234a87777f7a9d981d5e..5d41d0f69b1cd58210f763fac43075c22a56c2e9 100644 (file)
@@ -9,6 +9,12 @@
 
 /// Complete mod declaration, i.e. `mod <|> ;`
 pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
+    let _p = profile::span("completion::complete_mod");
+
+    if !ctx.mod_is_prev {
+        return None;
+    }
+
     let current_module = ctx.scope.module()?;
 
     let module_definition_file =
@@ -63,7 +69,7 @@ pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op
         .collect::<Vec<_>>();
     dbg!(mod_declaration_candidates);
 
-    // TODO kb exlude existing children from the candidates
+    // TODO kb actually add the results
 
     Some(())
 }
index accb09f7e8c874cbc646a0ddde2a5ccc51f33c60..351461351767bbeecb1eace55b64924b58c8c47a 100644 (file)
@@ -13,7 +13,7 @@ pub(super) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
         None => return,
     };
 
-    if ctx.attribute_under_caret.is_some() {
+    if ctx.attribute_under_caret.is_some() || ctx.mod_is_prev {
         return;
     }
 
index 1f1b682a78c98a7ccba16447d0571441eeda82e7..9f2dc16ab9e9b46d4400bbcf68673def285db191 100644 (file)
@@ -13,6 +13,7 @@ pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
     if ctx.record_lit_syntax.is_some()
         || ctx.record_pat_syntax.is_some()
         || ctx.attribute_under_caret.is_some()
+        || ctx.mod_is_prev
     {
         return;
     }
index 47355d5dcba3ae91d1d99e32bf89576e5f721624..d289aac2738956505ea47460d15ab65ccd785105 100644 (file)
@@ -19,7 +19,7 @@
             has_bind_pat_parent, has_block_expr_parent, has_field_list_parent,
             has_impl_as_prev_sibling, has_impl_parent, has_item_list_or_source_file_parent,
             has_ref_parent, has_trait_as_prev_sibling, has_trait_parent, if_is_prev,
-            is_in_loop_body, is_match_arm, unsafe_is_prev,
+            is_in_loop_body, is_match_arm, mod_is_prev, unsafe_is_prev,
         },
         CompletionConfig,
     },
@@ -77,6 +77,7 @@ pub(crate) struct CompletionContext<'a> {
     pub(super) is_path_type: bool,
     pub(super) has_type_args: bool,
     pub(super) attribute_under_caret: Option<ast::Attr>,
+    pub(super) mod_is_prev: bool,
     pub(super) unsafe_is_prev: bool,
     pub(super) if_is_prev: bool,
     pub(super) block_expr_parent: bool,
@@ -152,6 +153,7 @@ pub(super) fn new(
             has_type_args: false,
             dot_receiver_is_ambiguous_float_literal: false,
             attribute_under_caret: None,
+            mod_is_prev: false,
             unsafe_is_prev: false,
             in_loop_body: false,
             ref_pat_parent: false,
@@ -238,7 +240,8 @@ fn fill_keyword_patterns(&mut self, file_with_fake_ident: &SyntaxNode, offset: T
         self.trait_as_prev_sibling = has_trait_as_prev_sibling(syntax_element.clone());
         self.is_match_arm = is_match_arm(syntax_element.clone());
         self.has_item_list_or_source_file_parent =
-            has_item_list_or_source_file_parent(syntax_element);
+            has_item_list_or_source_file_parent(syntax_element.clone());
+        self.mod_is_prev = mod_is_prev(syntax_element);
     }
 
     fn fill(
index c6ae589db0de4d8c608f4a0f3c0d2bfb5985b699..bc4ce4d6f41ce3360eda41e026df637aaa236836 100644 (file)
@@ -115,6 +115,16 @@ pub(crate) fn if_is_prev(element: SyntaxElement) -> bool {
         .filter(|it| it.kind() == IF_KW)
         .is_some()
 }
+
+// TODO kb generify?
+pub(crate) fn mod_is_prev(element: SyntaxElement) -> bool {
+    element
+        .into_token()
+        .and_then(|it| previous_non_trivia_token(it))
+        .filter(|it| it.kind() == MOD_KW)
+        .is_some()
+}
+
 #[test]
 fn test_if_is_prev() {
     check_pattern_is_applicable(r"if l<|>", if_is_prev);