File tree Expand file tree Collapse file tree 2 files changed +54
-4
lines changed
crates/ra_ide/src/completion Expand file tree Collapse file tree 2 files changed +54
-4
lines changed Original file line number Diff line number Diff line change @@ -784,4 +784,55 @@ mod tests {
784
784
"###
785
785
) ;
786
786
}
787
+
788
+ #[ test]
789
+ fn completes_reexported_items_under_correct_name ( ) {
790
+ assert_debug_snapshot ! (
791
+ do_reference_completion(
792
+ r"
793
+ fn foo() {
794
+ self::m::<|>
795
+ }
796
+
797
+ mod m {
798
+ pub use super::p::wrong_fn as right_fn;
799
+ pub use super::p::WRONG_CONST as RIGHT_CONST;
800
+ pub use super::p::WrongType as RightType;
801
+ }
802
+ mod p {
803
+ fn wrong_fn() {}
804
+ const WRONG_CONST: u32 = 1;
805
+ struct WrongType {};
806
+ }
807
+ "
808
+ ) ,
809
+ @r###"
810
+ [
811
+ CompletionItem {
812
+ label: "RIGHT_CONST",
813
+ source_range: [57; 57),
814
+ delete: [57; 57),
815
+ insert: "RIGHT_CONST",
816
+ kind: Const,
817
+ },
818
+ CompletionItem {
819
+ label: "RightType",
820
+ source_range: [57; 57),
821
+ delete: [57; 57),
822
+ insert: "RightType",
823
+ kind: Struct,
824
+ },
825
+ CompletionItem {
826
+ label: "right_fn()",
827
+ source_range: [57; 57),
828
+ delete: [57; 57),
829
+ insert: "right_fn()$0",
830
+ kind: Function,
831
+ lookup: "right_fn",
832
+ detail: "fn wrong_fn()",
833
+ },
834
+ ]
835
+ "###
836
+ ) ;
837
+ }
787
838
}
Original file line number Diff line number Diff line change @@ -193,11 +193,10 @@ impl Completions {
193
193
name : Option < String > ,
194
194
func : hir:: Function ,
195
195
) {
196
- let func_name = func. name ( ctx. db ) ;
197
196
let has_self_param = func. has_self_param ( ctx. db ) ;
198
197
let params = func. params ( ctx. db ) ;
199
198
200
- let name = name. unwrap_or_else ( || func_name . to_string ( ) ) ;
199
+ let name = name. unwrap_or_else ( || func . name ( ctx . db ) . to_string ( ) ) ;
201
200
let ast_node = func. source ( ctx. db ) . value ;
202
201
let detail = function_label ( & ast_node) ;
203
202
@@ -219,9 +218,9 @@ impl Completions {
219
218
{
220
219
tested_by ! ( inserts_parens_for_function_calls) ;
221
220
let ( snippet, label) = if params. is_empty ( ) || has_self_param && params. len ( ) == 1 {
222
- ( format ! ( "{}()$0" , func_name ) , format ! ( "{}()" , name) )
221
+ ( format ! ( "{}()$0" , name ) , format ! ( "{}()" , name) )
223
222
} else {
224
- ( format ! ( "{}($0)" , func_name ) , format ! ( "{}(…)" , name) )
223
+ ( format ! ( "{}($0)" , name ) , format ! ( "{}(…)" , name) )
225
224
} ;
226
225
builder = builder. lookup_by ( name) . label ( label) . insert_snippet ( snippet) ;
227
226
}
You can’t perform that action at this time.
0 commit comments