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_dot.rs57
-rw-r--r--crates/ra_ide/src/inlay_hints.rs37
2 files changed, 92 insertions, 2 deletions
diff --git a/crates/ra_ide/src/completion/complete_dot.rs b/crates/ra_ide/src/completion/complete_dot.rs
index 294964887..210a685e4 100644
--- a/crates/ra_ide/src/completion/complete_dot.rs
+++ b/crates/ra_ide/src/completion/complete_dot.rs
@@ -1,6 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::Type; 3use hir::{HasVisibility, Type};
4 4
5use crate::completion::completion_item::CompletionKind; 5use crate::completion::completion_item::CompletionKind;
6use crate::{ 6use crate::{
@@ -38,9 +38,15 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
38fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: &Type) { 38fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: &Type) {
39 for receiver in receiver.autoderef(ctx.db) { 39 for receiver in receiver.autoderef(ctx.db) {
40 for (field, ty) in receiver.fields(ctx.db) { 40 for (field, ty) in receiver.fields(ctx.db) {
41 if ctx.module.map_or(false, |m| !field.is_visible_from(ctx.db, m)) {
42 // Skip private field. FIXME: If the definition location of the
43 // field is editable, we should show the completion
44 continue;
45 }
41 acc.add_field(ctx, field, &ty); 46 acc.add_field(ctx, field, &ty);
42 } 47 }
43 for (i, ty) in receiver.tuple_fields(ctx.db).into_iter().enumerate() { 48 for (i, ty) in receiver.tuple_fields(ctx.db).into_iter().enumerate() {
49 // FIXME: Handle visibility
44 acc.add_tuple_field(ctx, i, &ty); 50 acc.add_tuple_field(ctx, i, &ty);
45 } 51 }
46 } 52 }
@@ -187,6 +193,55 @@ mod tests {
187 } 193 }
188 194
189 #[test] 195 #[test]
196 fn test_struct_field_visibility_private() {
197 assert_debug_snapshot!(
198 do_ref_completion(
199 r"
200 mod inner {
201 struct A {
202 private_field: u32,
203 pub pub_field: u32,
204 pub(crate) crate_field: u32,
205 pub(super) super_field: u32,
206 }
207 }
208 fn foo(a: inner::A) {
209 a.<|>
210 }
211 ",
212 ),
213 @r###"
214 [
215 CompletionItem {
216 label: "crate_field",
217 source_range: [313; 313),
218 delete: [313; 313),
219 insert: "crate_field",
220 kind: Field,
221 detail: "u32",
222 },
223 CompletionItem {
224 label: "pub_field",
225 source_range: [313; 313),
226 delete: [313; 313),
227 insert: "pub_field",
228 kind: Field,
229 detail: "u32",
230 },
231 CompletionItem {
232 label: "super_field",
233 source_range: [313; 313),
234 delete: [313; 313),
235 insert: "super_field",
236 kind: Field,
237 detail: "u32",
238 },
239 ]
240 "###
241 );
242 }
243
244 #[test]
190 fn test_method_completion() { 245 fn test_method_completion() {
191 assert_debug_snapshot!( 246 assert_debug_snapshot!(
192 do_ref_completion( 247 do_ref_completion(
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index c5e406977..977aafc51 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -293,7 +293,7 @@ fn main() {
293 } 293 }
294 294
295 #[test] 295 #[test]
296 fn closure_parameter() { 296 fn closure_parameters() {
297 let (analysis, file_id) = single_file( 297 let (analysis, file_id) = single_file(
298 r#" 298 r#"
299fn main() { 299fn main() {
@@ -301,6 +301,11 @@ fn main() {
301 (0..2).for_each(|increment| { 301 (0..2).for_each(|increment| {
302 start += increment; 302 start += increment;
303 }) 303 })
304
305 let multiply = |a, b, c, d| a * b * c * d;
306 let _: i32 = multiply(1, 2, 3, 4);
307
308 let return_42 = || 42;
304}"#, 309}"#,
305 ); 310 );
306 311
@@ -316,6 +321,36 @@ fn main() {
316 kind: TypeHint, 321 kind: TypeHint,
317 label: "i32", 322 label: "i32",
318 }, 323 },
324 InlayHint {
325 range: [114; 122),
326 kind: TypeHint,
327 label: "|…| -> i32",
328 },
329 InlayHint {
330 range: [126; 127),
331 kind: TypeHint,
332 label: "i32",
333 },
334 InlayHint {
335 range: [129; 130),
336 kind: TypeHint,
337 label: "i32",
338 },
339 InlayHint {
340 range: [132; 133),
341 kind: TypeHint,
342 label: "i32",
343 },
344 InlayHint {
345 range: [135; 136),
346 kind: TypeHint,
347 label: "i32",
348 },
349 InlayHint {
350 range: [201; 210),
351 kind: TypeHint,
352 label: "|| -> i32",
353 },
319 ] 354 ]
320 "### 355 "###
321 ); 356 );