aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion/complete_dot.rs
diff options
context:
space:
mode:
authorgfreezy <[email protected]>2019-01-19 14:02:50 +0000
committergfreezy <[email protected]>2019-01-19 14:02:50 +0000
commitd08e81cdd818dd3378c292767e15a38e6bbc6f6c (patch)
treee07b3363f21912ca7aaca4ae1dce482c0bcd6f85 /crates/ra_ide_api/src/completion/complete_dot.rs
parentfa43ef30f4f96fc8e4ea1f9c4492bcb07b3335ca (diff)
refactor completions to use TextEdit instead of InsertText
Diffstat (limited to 'crates/ra_ide_api/src/completion/complete_dot.rs')
-rw-r--r--crates/ra_ide_api/src/completion/complete_dot.rs27
1 files changed, 14 insertions, 13 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs
index 473edc50e..aaf739500 100644
--- a/crates/ra_ide_api/src/completion/complete_dot.rs
+++ b/crates/ra_ide_api/src/completion/complete_dot.rs
@@ -1,6 +1,7 @@
1use hir::{Ty, Def}; 1use hir::{Ty, Def};
2 2
3use crate::completion::{CompletionContext, Completions, CompletionKind, CompletionItem, CompletionItemKind}; 3use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionItemKind};
4use crate::completion::completion_item::CompletionKind;
4 5
5/// Complete dot accesses, i.e. fields or methods (currently only fields). 6/// Complete dot accesses, i.e. fields or methods (currently only fields).
6pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { 7pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
@@ -30,6 +31,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
30 for field in s.fields(ctx.db) { 31 for field in s.fields(ctx.db) {
31 CompletionItem::new( 32 CompletionItem::new(
32 CompletionKind::Reference, 33 CompletionKind::Reference,
34 ctx,
33 field.name().to_string(), 35 field.name().to_string(),
34 ) 36 )
35 .kind(CompletionItemKind::Field) 37 .kind(CompletionItemKind::Field)
@@ -43,7 +45,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
43 } 45 }
44 Ty::Tuple(fields) => { 46 Ty::Tuple(fields) => {
45 for (i, _ty) in fields.iter().enumerate() { 47 for (i, _ty) in fields.iter().enumerate() {
46 CompletionItem::new(CompletionKind::Reference, i.to_string()) 48 CompletionItem::new(CompletionKind::Reference, ctx, i.to_string())
47 .kind(CompletionItemKind::Field) 49 .kind(CompletionItemKind::Field)
48 .add_to(acc); 50 .add_to(acc);
49 } 51 }
@@ -57,7 +59,7 @@ fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty
57 receiver.iterate_methods(ctx.db, |func| { 59 receiver.iterate_methods(ctx.db, |func| {
58 let sig = func.signature(ctx.db); 60 let sig = func.signature(ctx.db);
59 if sig.has_self_param() { 61 if sig.has_self_param() {
60 CompletionItem::new(CompletionKind::Reference, sig.name().to_string()) 62 CompletionItem::new(CompletionKind::Reference, ctx, sig.name().to_string())
61 .from_function(ctx, func) 63 .from_function(ctx, func)
62 .kind(CompletionItemKind::Method) 64 .kind(CompletionItemKind::Method)
63 .add_to(acc); 65 .add_to(acc);
@@ -69,27 +71,29 @@ fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty
69#[cfg(test)] 71#[cfg(test)]
70mod tests { 72mod tests {
71 use crate::completion::*; 73 use crate::completion::*;
74 use crate::completion::completion_item::check_completion;
72 75
73 fn check_ref_completion(code: &str, expected_completions: &str) { 76 fn check_ref_completion(name: &str, code: &str) {
74 check_completion(code, expected_completions, CompletionKind::Reference); 77 check_completion(name, code, CompletionKind::Reference);
75 } 78 }
76 79
77 #[test] 80 #[test]
78 fn test_struct_field_completion() { 81 fn test_struct_field_completion() {
79 check_ref_completion( 82 check_ref_completion(
83 "struct_field_completion",
80 r" 84 r"
81 struct A { the_field: u32 } 85 struct A { the_field: u32 }
82 fn foo(a: A) { 86 fn foo(a: A) {
83 a.<|> 87 a.<|>
84 } 88 }
85 ", 89 ",
86 r#"the_field "u32""#,
87 ); 90 );
88 } 91 }
89 92
90 #[test] 93 #[test]
91 fn test_struct_field_completion_self() { 94 fn test_struct_field_completion_self() {
92 check_ref_completion( 95 check_ref_completion(
96 "struct_field_completion_self",
93 r" 97 r"
94 struct A { the_field: (u32,) } 98 struct A { the_field: (u32,) }
95 impl A { 99 impl A {
@@ -98,14 +102,13 @@ mod tests {
98 } 102 }
99 } 103 }
100 ", 104 ",
101 r#"the_field "(u32,)"
102 foo "foo($0)""#,
103 ); 105 );
104 } 106 }
105 107
106 #[test] 108 #[test]
107 fn test_struct_field_completion_autoderef() { 109 fn test_struct_field_completion_autoderef() {
108 check_ref_completion( 110 check_ref_completion(
111 "struct_field_completion_autoderef",
109 r" 112 r"
110 struct A { the_field: (u32, i32) } 113 struct A { the_field: (u32, i32) }
111 impl A { 114 impl A {
@@ -114,27 +117,26 @@ mod tests {
114 } 117 }
115 } 118 }
116 ", 119 ",
117 r#"the_field "(u32, i32)"
118 foo "foo($0)""#,
119 ); 120 );
120 } 121 }
121 122
122 #[test] 123 #[test]
123 fn test_no_struct_field_completion_for_method_call() { 124 fn test_no_struct_field_completion_for_method_call() {
124 check_ref_completion( 125 check_ref_completion(
126 "no_struct_field_completion_for_method_call",
125 r" 127 r"
126 struct A { the_field: u32 } 128 struct A { the_field: u32 }
127 fn foo(a: A) { 129 fn foo(a: A) {
128 a.<|>() 130 a.<|>()
129 } 131 }
130 ", 132 ",
131 r#""#,
132 ); 133 );
133 } 134 }
134 135
135 #[test] 136 #[test]
136 fn test_method_completion() { 137 fn test_method_completion() {
137 check_ref_completion( 138 check_ref_completion(
139 "method_completion",
138 r" 140 r"
139 struct A {} 141 struct A {}
140 impl A { 142 impl A {
@@ -144,13 +146,13 @@ mod tests {
144 a.<|> 146 a.<|>
145 } 147 }
146 ", 148 ",
147 r#"the_method "the_method($0)""#,
148 ); 149 );
149 } 150 }
150 151
151 #[test] 152 #[test]
152 fn test_no_non_self_method() { 153 fn test_no_non_self_method() {
153 check_ref_completion( 154 check_ref_completion(
155 "no_non_self_method",
154 r" 156 r"
155 struct A {} 157 struct A {}
156 impl A { 158 impl A {
@@ -160,7 +162,6 @@ mod tests {
160 a.<|> 162 a.<|>
161 } 163 }
162 ", 164 ",
163 r#""#,
164 ); 165 );
165 } 166 }
166} 167}