File tree Expand file tree Collapse file tree 5 files changed +16
-4
lines changed Expand file tree Collapse file tree 5 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ authors = ["rust-analyzer team"]
1212[profile .dev ]
1313# Disabling debug info speeds up builds a bunch,
1414# and we don't rely on it for debugging that much.
15- debug = 0
15+ debug = 2
1616
1717[profile .dev .package ]
1818# These speed up local tests.
Original file line number Diff line number Diff line change @@ -610,6 +610,14 @@ impl Completions {
610610 . map ( |_| false )
611611 }
612612
613+ for item in self . buf . iter_mut ( ) {
614+ if creates_self ( & item) == Some ( true ) {
615+ item. sort_text = Some ( format ! ( "{0:08x}" , 0 ) ) ;
616+ } else if creates_self_given_args ( & item) == Some ( true ) {
617+ item. sort_text = Some ( format ! ( "{0:08x}" , 1 ) ) ;
618+ }
619+ }
620+
613621 self . buf . sort_by ( |a, b| {
614622 creates_self ( b)
615623 . cmp ( & creates_self ( a) )
Original file line number Diff line number Diff line change @@ -278,8 +278,8 @@ fn foo(a: A) { a.$0() }
278278struct A;
279279impl A {
280280 fn foo(&self) {}
281- fn new_1(input: u32) -> Self { A }
282- fn new_2() -> A { A }
281+ fn new_1(input: u32) -> A { A }
282+ fn new_2() -> Self { A }
283283}
284284
285285fn test() {
Original file line number Diff line number Diff line change @@ -85,6 +85,8 @@ pub struct CompletionItem {
8585 /// The import data to add to completion's edits.
8686 /// (ImportPath, LastSegment)
8787 pub import_to_add : SmallVec < [ ( String , String ) ; 1 ] > ,
88+
89+ pub sort_text : Option < String > ,
8890}
8991
9092// We use custom debug for CompletionItem to make snapshot tests more readable.
@@ -503,6 +505,7 @@ impl Builder {
503505 relevance : self . relevance ,
504506 ref_match : self . ref_match ,
505507 import_to_add,
508+ sort_text : None ,
506509 }
507510 }
508511 pub ( crate ) fn lookup_by ( & mut self , lookup : impl Into < SmolStr > ) -> & mut Builder {
Original file line number Diff line number Diff line change @@ -308,7 +308,7 @@ fn completion_item(
308308 lsp_item. label . push_str ( label_detail. as_str ( ) ) ;
309309 }
310310
311- set_score ( & mut lsp_item, max_relevance, item. relevance ) ;
311+ set_score ( & mut lsp_item, max_relevance, item. relevance ) ; // TODO: copy sort_text from CompletionItem if present (+1 instance below)
312312
313313 if config. completion ( ) . enable_imports_on_the_fly {
314314 if !item. import_to_add . is_empty ( ) {
@@ -349,6 +349,7 @@ fn completion_item(
349349 if relevance. is_relevant ( ) && relevance. score ( ) == max_relevance {
350350 res. preselect = Some ( true ) ;
351351 }
352+
352353 // The relevance needs to be inverted to come up with a sort score
353354 // because the client will sort ascending.
354355 let sort_score = relevance. score ( ) ^ 0xFF_FF_FF_FF ;
You can’t perform that action at this time.
0 commit comments