diff options
author | Aleksey Kladov <[email protected]> | 2019-02-24 16:37:22 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-24 16:37:22 +0000 |
commit | 3c7c5a7354760a12b38c7186193232d68056a76e (patch) | |
tree | 304b7e193c12a3d33ef8347608912ea3c767b637 /crates/ra_ide_api/src/completion/presentation.rs | |
parent | b04cadc02c72055ed97eb5b3c1318f1c3b5602dc (diff) |
move presentaion completion to presentation
Diffstat (limited to 'crates/ra_ide_api/src/completion/presentation.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/presentation.rs | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 9c31a3801..057dbc21a 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -70,3 +70,83 @@ fn function_item_label(ctx: &CompletionContext, function: hir::Function) -> Opti | |||
70 | let node = function.source(ctx.db).1; | 70 | let node = function.source(ctx.db).1; |
71 | function_label(&node) | 71 | function_label(&node) |
72 | } | 72 | } |
73 | |||
74 | #[cfg(test)] | ||
75 | mod tests { | ||
76 | use test_utils::covers; | ||
77 | |||
78 | use crate::completion::{CompletionKind, completion_item::check_completion}; | ||
79 | |||
80 | fn check_reference_completion(code: &str, expected_completions: &str) { | ||
81 | check_completion(code, expected_completions, CompletionKind::Reference); | ||
82 | } | ||
83 | |||
84 | #[test] | ||
85 | fn inserts_parens_for_function_calls() { | ||
86 | covers!(inserts_parens_for_function_calls); | ||
87 | check_reference_completion( | ||
88 | "inserts_parens_for_function_calls1", | ||
89 | r" | ||
90 | fn no_args() {} | ||
91 | fn main() { no_<|> } | ||
92 | ", | ||
93 | ); | ||
94 | check_reference_completion( | ||
95 | "inserts_parens_for_function_calls2", | ||
96 | r" | ||
97 | fn with_args(x: i32, y: String) {} | ||
98 | fn main() { with_<|> } | ||
99 | ", | ||
100 | ); | ||
101 | check_reference_completion( | ||
102 | "inserts_parens_for_function_calls3", | ||
103 | r" | ||
104 | struct S {} | ||
105 | impl S { | ||
106 | fn foo(&self) {} | ||
107 | } | ||
108 | fn bar(s: &S) { | ||
109 | s.f<|> | ||
110 | } | ||
111 | ", | ||
112 | ) | ||
113 | } | ||
114 | |||
115 | #[test] | ||
116 | fn dont_render_function_parens_in_use_item() { | ||
117 | check_reference_completion( | ||
118 | "dont_render_function_parens_in_use_item", | ||
119 | " | ||
120 | //- /lib.rs | ||
121 | mod m { pub fn foo() {} } | ||
122 | use crate::m::f<|>; | ||
123 | ", | ||
124 | ) | ||
125 | } | ||
126 | |||
127 | #[test] | ||
128 | fn dont_render_function_parens_if_already_call() { | ||
129 | check_reference_completion( | ||
130 | "dont_render_function_parens_if_already_call", | ||
131 | " | ||
132 | //- /lib.rs | ||
133 | fn frobnicate() {} | ||
134 | fn main() { | ||
135 | frob<|>(); | ||
136 | } | ||
137 | ", | ||
138 | ); | ||
139 | check_reference_completion( | ||
140 | "dont_render_function_parens_if_already_call_assoc_fn", | ||
141 | " | ||
142 | //- /lib.rs | ||
143 | struct Foo {} | ||
144 | impl Foo { fn new() -> Foo {} } | ||
145 | fn main() { | ||
146 | Foo::ne<|>(); | ||
147 | } | ||
148 | ", | ||
149 | ) | ||
150 | } | ||
151 | |||
152 | } | ||