Skip to content

Commit 0d1f4f9

Browse files
committed
Lower postfix suggestions in completions list
1 parent 259182b commit 0d1f4f9

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

crates/ide_completion/src/completions/postfix.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,12 @@ fn build_postfix_snippet_builder<'ctx>(
240240
let mut item =
241241
CompletionItem::new(CompletionItemKind::Snippet, ctx.source_range(), label);
242242
item.detail(detail).snippet_edit(cap, edit);
243-
if ctx.original_token.text() == label {
244-
let relevance =
245-
CompletionRelevance { exact_postfix_snippet_match: true, ..Default::default() };
246-
item.set_relevance(relevance);
247-
}
248-
243+
let relevance = if ctx.original_token.text() == label {
244+
CompletionRelevance { exact_postfix_snippet_match: true, ..Default::default() }
245+
} else {
246+
CompletionRelevance { is_postfix: true, ..Default::default() }
247+
};
248+
item.set_relevance(relevance);
249249
item
250250
}
251251
}

crates/ide_completion/src/item.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ pub struct CompletionRelevance {
152152
/// Basically, we want to guarantee that postfix snippets always takes
153153
/// precedence over everything else.
154154
pub exact_postfix_snippet_match: bool,
155+
/// Set in cases when item is postfix, but not exact
156+
pub is_postfix: bool,
155157
}
156158

157159
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
@@ -179,7 +181,7 @@ pub enum CompletionRelevanceTypeMatch {
179181
}
180182

181183
impl CompletionRelevance {
182-
const BASE_LINE: u32 = 2;
184+
const BASE_LINE: u32 = 3;
183185
/// Provides a relevance score. Higher values are more relevant.
184186
///
185187
/// The absolute value of the relevance score is not meaningful, for
@@ -199,6 +201,9 @@ impl CompletionRelevance {
199201
if self.is_private_editable {
200202
score -= 1;
201203
}
204+
if self.is_postfix {
205+
score -= 3;
206+
}
202207

203208
// score increases
204209
if self.exact_name_match {
@@ -215,6 +220,7 @@ impl CompletionRelevance {
215220
if self.exact_postfix_snippet_match {
216221
score += 100;
217222
}
223+
218224
score
219225
}
220226

@@ -573,6 +579,10 @@ mod tests {
573579
// This test asserts that the relevance score for these items is ascending, and
574580
// that any items in the same vec have the same score.
575581
let expected_relevance_order = vec![
582+
vec![CompletionRelevance {
583+
is_postfix: true,
584+
..CompletionRelevance::default()
585+
}],
576586
vec![CompletionRelevance {
577587
is_op_method: true,
578588
is_private_editable: true,

crates/ide_completion/src/render.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ fn main() { let _: m::Spam = S$0 }
615615
is_op_method: false,
616616
is_private_editable: false,
617617
exact_postfix_snippet_match: false,
618+
is_postfix: false,
618619
},
619620
},
620621
CompletionItem {
@@ -636,6 +637,7 @@ fn main() { let _: m::Spam = S$0 }
636637
is_op_method: false,
637638
is_private_editable: false,
638639
exact_postfix_snippet_match: false,
640+
is_postfix: false,
639641
},
640642
},
641643
]
@@ -723,6 +725,7 @@ fn foo() { A { the$0 } }
723725
is_op_method: false,
724726
is_private_editable: false,
725727
exact_postfix_snippet_match: false,
728+
is_postfix: false,
726729
},
727730
},
728731
]

0 commit comments

Comments
 (0)