aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/completion/complete_keyword.rs14
-rw-r--r--crates/ra_ide/src/completion/test_utils.rs23
2 files changed, 17 insertions, 20 deletions
diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs
index b2f621a11..3b174f916 100644
--- a/crates/ra_ide/src/completion/complete_keyword.rs
+++ b/crates/ra_ide/src/completion/complete_keyword.rs
@@ -11,14 +11,14 @@ pub(super) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC
11 let source_range = ctx.source_range(); 11 let source_range = ctx.source_range();
12 match (ctx.use_item_syntax.as_ref(), ctx.path_prefix.as_ref()) { 12 match (ctx.use_item_syntax.as_ref(), ctx.path_prefix.as_ref()) {
13 (Some(_), None) => { 13 (Some(_), None) => {
14 CompletionItem::new(CompletionKind::Keyword, source_range, "crate") 14 CompletionItem::new(CompletionKind::Keyword, source_range, "crate::")
15 .kind(CompletionItemKind::Keyword) 15 .kind(CompletionItemKind::Keyword)
16 .insert_text("crate::") 16 .insert_text("crate::")
17 .add_to(acc); 17 .add_to(acc);
18 CompletionItem::new(CompletionKind::Keyword, source_range, "self") 18 CompletionItem::new(CompletionKind::Keyword, source_range, "self")
19 .kind(CompletionItemKind::Keyword) 19 .kind(CompletionItemKind::Keyword)
20 .add_to(acc); 20 .add_to(acc);
21 CompletionItem::new(CompletionKind::Keyword, source_range, "super") 21 CompletionItem::new(CompletionKind::Keyword, source_range, "super::")
22 .kind(CompletionItemKind::Keyword) 22 .kind(CompletionItemKind::Keyword)
23 .insert_text("super::") 23 .insert_text("super::")
24 .add_to(acc); 24 .add_to(acc);
@@ -27,7 +27,7 @@ pub(super) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC
27 CompletionItem::new(CompletionKind::Keyword, source_range, "self") 27 CompletionItem::new(CompletionKind::Keyword, source_range, "self")
28 .kind(CompletionItemKind::Keyword) 28 .kind(CompletionItemKind::Keyword)
29 .add_to(acc); 29 .add_to(acc);
30 CompletionItem::new(CompletionKind::Keyword, source_range, "super") 30 CompletionItem::new(CompletionKind::Keyword, source_range, "super::")
31 .kind(CompletionItemKind::Keyword) 31 .kind(CompletionItemKind::Keyword)
32 .insert_text("super::") 32 .insert_text("super::")
33 .add_to(acc); 33 .add_to(acc);
@@ -182,9 +182,9 @@ mod tests {
182 assert_snapshot!( 182 assert_snapshot!(
183 get_keyword_completions(r"use <|>"), 183 get_keyword_completions(r"use <|>"),
184 @r###" 184 @r###"
185 kw crate 185 kw crate::
186 kw self 186 kw self
187 kw super 187 kw super::
188 "### 188 "###
189 ); 189 );
190 190
@@ -192,7 +192,7 @@ mod tests {
192 get_keyword_completions(r"use a::<|>"), 192 get_keyword_completions(r"use a::<|>"),
193 @r###" 193 @r###"
194 kw self 194 kw self
195 kw super 195 kw super::
196 "### 196 "###
197 ); 197 );
198 198
@@ -200,7 +200,7 @@ mod tests {
200 get_keyword_completions(r"use a::{b, <|>}"), 200 get_keyword_completions(r"use a::{b, <|>}"),
201 @r###" 201 @r###"
202 kw self 202 kw self
203 kw super 203 kw super::
204 "### 204 "###
205 ); 205 );
206 } 206 }
diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs
index a1b7c1193..5c01654cc 100644
--- a/crates/ra_ide/src/completion/test_utils.rs
+++ b/crates/ra_ide/src/completion/test_utils.rs
@@ -1,21 +1,18 @@
1//! Runs completion for testing purposes. 1//! Runs completion for testing purposes.
2 2
3use hir::Semantics;
4use ra_syntax::{AstNode, NodeOrToken, SyntaxElement};
5
3use crate::{ 6use crate::{
4 completion::{completion_item::CompletionKind, CompletionConfig}, 7 completion::{completion_item::CompletionKind, CompletionConfig},
5 mock_analysis::analysis_and_position, 8 mock_analysis::analysis_and_position,
6 CompletionItem, 9 CompletionItem,
7}; 10};
8use hir::Semantics;
9use ra_syntax::{AstNode, NodeOrToken, SyntaxElement};
10 11
11pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> { 12pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> {
12 do_completion_with_options(code, kind, &CompletionConfig::default()) 13 do_completion_with_options(code, kind, &CompletionConfig::default())
13} 14}
14 15
15pub(crate) fn completion_list(code: &str, kind: CompletionKind) -> String {
16 completion_list_with_options(code, kind, &CompletionConfig::default())
17}
18
19pub(crate) fn do_completion_with_options( 16pub(crate) fn do_completion_with_options(
20 code: &str, 17 code: &str,
21 kind: CompletionKind, 18 kind: CompletionKind,
@@ -29,13 +26,8 @@ pub(crate) fn do_completion_with_options(
29 kind_completions 26 kind_completions
30} 27}
31 28
32fn get_all_completion_items(code: &str, options: &CompletionConfig) -> Vec<CompletionItem> { 29pub(crate) fn completion_list(code: &str, kind: CompletionKind) -> String {
33 let (analysis, position) = if code.contains("//-") { 30 completion_list_with_options(code, kind, &CompletionConfig::default())
34 analysis_and_position(code)
35 } else {
36 analysis_and_position(code)
37 };
38 analysis.completions(options, position).unwrap().unwrap().into()
39} 31}
40 32
41pub(crate) fn completion_list_with_options( 33pub(crate) fn completion_list_with_options(
@@ -65,3 +57,8 @@ pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -
65 }) 57 })
66 .unwrap(); 58 .unwrap();
67} 59}
60
61fn get_all_completion_items(code: &str, options: &CompletionConfig) -> Vec<CompletionItem> {
62 let (analysis, position) = analysis_and_position(code);
63 analysis.completions(options, position).unwrap().unwrap().into()
64}