Skip to content

Commit f4db9f1

Browse files
committed
ops new in this codebase!
1 parent d48763e commit f4db9f1

File tree

6 files changed

+48
-58
lines changed

6 files changed

+48
-58
lines changed

crates/ide-completion/src/completions.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use crate::{
4545
union_literal::render_union_literal,
4646
RenderContext,
4747
},
48-
CompletionContext, CompletionItem, CompletionItemKind,
48+
CompletionContext, CompletionItem, CompletionItemKind, CompletionRelevance,
4949
};
5050

5151
/// Represents an in-progress set of completions being built.
@@ -600,29 +600,33 @@ impl Completions {
600600
/// fn with param that returns itself
601601
pub(crate) fn sort_new_first(&mut self) {
602602
// ToDo: Ensure these fn returns Self
603-
fn creates_self(item: &CompletionItem) -> Option<bool> {
604-
item.detail.as_ref().filter(|d| d.starts_with("fn() -> ")).map(|_| false)
603+
fn creates_self(item: &CompletionItem) -> bool {
604+
item.detail.as_ref().map(|d| d.starts_with("fn() -> ")).unwrap_or_default()
605605
}
606-
fn creates_self_given_args(item: &CompletionItem) -> Option<bool> {
606+
fn creates_self_given_args(item: &CompletionItem) -> bool {
607607
item.detail
608608
.as_ref()
609-
.filter(|d| d.starts_with("fn(") && d.contains("->") && !d.contains("&self"))
610-
.map(|_| false)
609+
.map(|d| d.starts_with("fn(") && d.contains("->") && !d.contains("&self"))
610+
.unwrap_or_default()
611611
}
612612

613613
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));
614+
if creates_self(&item) {
615+
//item.sort_text = Some(format!("{0:08x}", 0));
616+
item.relevance = CompletionRelevance {
617+
exact_name_match: true,
618+
is_definite: true,
619+
..Default::default()
620+
};
621+
} else if creates_self_given_args(&item) {
622+
//item.sort_text = Some(format!("{0:08x}", 1));
623+
item.relevance = CompletionRelevance {
624+
exact_name_match: true,
625+
is_local: true,
626+
..Default::default()
627+
};
618628
}
619629
}
620-
621-
self.buf.sort_by(|a, b| {
622-
creates_self(b)
623-
.cmp(&creates_self(a))
624-
.then(creates_self_given_args(b).cmp(&creates_self_given_args(a)))
625-
});
626630
}
627631
}
628632

crates/ide-completion/src/completions/dot.rs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,14 @@ mod tests {
155155
use expect_test::{expect, Expect};
156156

157157
use crate::tests::{
158-
check_edit, completion_list_exact_order, completion_list_no_kw,
159-
completion_list_no_kw_with_private_editable,
158+
check_edit, completion_list_no_kw, completion_list_no_kw_with_private_editable,
160159
};
161160

162161
fn check(ra_fixture: &str, expect: Expect) {
163162
let actual = completion_list_no_kw(ra_fixture);
164163
expect.assert_eq(&actual);
165164
}
166165

167-
fn check_exact_order(ra_fixture: &str, expect: Expect) {
168-
let actual = completion_list_exact_order(ra_fixture);
169-
expect.assert_eq(&actual);
170-
}
171-
172166
fn check_with_private_editable(ra_fixture: &str, expect: Expect) {
173167
let actual = completion_list_no_kw_with_private_editable(ra_fixture);
174168
expect.assert_eq(&actual);
@@ -271,32 +265,6 @@ fn foo(a: A) { a.$0() }
271265
);
272266
}
273267

274-
#[test]
275-
fn test_suggest_new_first() {
276-
check_exact_order(
277-
r#"
278-
struct A;
279-
impl A {
280-
fn foo(&self) {}
281-
fn new_1(input: u32) -> A { A }
282-
fn new_2() -> Self { A }
283-
}
284-
285-
fn test() {
286-
let a = A::$0;
287-
}
288-
"#,
289-
// preference:
290-
// fn with no param that returns itself
291-
// fn with param that returns itself
292-
expect![[r#"
293-
fn new_2() fn() -> A
294-
fn new_1(…) fn(u32) -> A
295-
me foo(…) fn(&self)
296-
"#]],
297-
);
298-
}
299-
300268
#[test]
301269
fn test_visibility_filtering() {
302270
check(

crates/ide-completion/src/item.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ 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>,
9088
}
9189

9290
// We use custom debug for CompletionItem to make snapshot tests more readable.
@@ -505,7 +503,6 @@ impl Builder {
505503
relevance: self.relevance,
506504
ref_match: self.ref_match,
507505
import_to_add,
508-
sort_text: None,
509506
}
510507
}
511508
pub(crate) fn lookup_by(&mut self, lookup: impl Into<SmolStr>) -> &mut Builder {

crates/ide-completion/src/render.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,32 @@ fn main() {
16321632
);
16331633
}
16341634

1635+
#[test]
1636+
fn new_like_fns() {
1637+
check_relevance(
1638+
r#"
1639+
struct A;
1640+
impl A {
1641+
fn foo(&self) {}
1642+
fn new_1(input: u32) -> A { A }
1643+
fn new_2() -> Self { A }
1644+
}
1645+
1646+
fn test() {
1647+
let a = A::$0;
1648+
}
1649+
"#,
1650+
// preference:
1651+
// fn with no param that returns itself
1652+
// fn with param that returns itself
1653+
expect![[r#"
1654+
fn new_2() [name]
1655+
fn new_1(…) [name+local]
1656+
me foo(…) [type_could_unify]
1657+
"#]],
1658+
);
1659+
}
1660+
16351661
#[test]
16361662
fn struct_field_method_ref() {
16371663
check_kinds(

crates/ide-completion/src/tests.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ pub(crate) fn completion_list_no_kw(ra_fixture: &str) -> String {
8888
completion_list_with_config(TEST_CONFIG, ra_fixture, false, None)
8989
}
9090

91-
pub(crate) fn completion_list_exact_order(ra_fixture: &str) -> String {
92-
let items = get_all_items(TEST_CONFIG, ra_fixture, None);
93-
render_completion_list(items)
94-
}
95-
9691
pub(crate) fn completion_list_no_kw_with_private_editable(ra_fixture: &str) -> String {
9792
let mut config = TEST_CONFIG;
9893
config.enable_private_editable = true;

crates/rust-analyzer/src/lsp/to_proto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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); // TODO: copy sort_text from CompletionItem if present (+1 instance below)
311+
set_score(&mut lsp_item, max_relevance, item.relevance);
312312

313313
if config.completion().enable_imports_on_the_fly {
314314
if !item.import_to_add.is_empty() {

0 commit comments

Comments
 (0)