mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Sort completion items that skip await
and iter()
behind those that don't
I don't think my ranking is perfect, because it places them even behind snippet completions, but this is something.
This commit is contained in:
parent
2c040c03cf
commit
8e0bc9f67f
@ -181,6 +181,8 @@ pub struct CompletionRelevance {
|
|||||||
pub postfix_match: Option<CompletionRelevancePostfixMatch>,
|
pub postfix_match: Option<CompletionRelevancePostfixMatch>,
|
||||||
/// This is set for items that are function (associated or method)
|
/// This is set for items that are function (associated or method)
|
||||||
pub function: Option<CompletionRelevanceFn>,
|
pub function: Option<CompletionRelevanceFn>,
|
||||||
|
/// true when there is an `await.method()` or `iter().method()` completion.
|
||||||
|
pub is_skipping_completion: bool,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||||
pub struct CompletionRelevanceTraitInfo {
|
pub struct CompletionRelevanceTraitInfo {
|
||||||
@ -269,6 +271,7 @@ impl CompletionRelevance {
|
|||||||
postfix_match,
|
postfix_match,
|
||||||
trait_,
|
trait_,
|
||||||
function,
|
function,
|
||||||
|
is_skipping_completion,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
// only applicable for completions within use items
|
// only applicable for completions within use items
|
||||||
@ -296,6 +299,12 @@ impl CompletionRelevance {
|
|||||||
score -= 5;
|
score -= 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lower rank for completions that skip `await` and `iter()`.
|
||||||
|
if is_skipping_completion {
|
||||||
|
score -= 7;
|
||||||
|
}
|
||||||
|
|
||||||
// lower rank for items that need an import
|
// lower rank for items that need an import
|
||||||
if requires_import {
|
if requires_import {
|
||||||
score -= 1;
|
score -= 1;
|
||||||
|
@ -141,6 +141,7 @@ pub(crate) fn render_field(
|
|||||||
item.set_relevance(CompletionRelevance {
|
item.set_relevance(CompletionRelevance {
|
||||||
type_match: compute_type_match(ctx.completion, ty),
|
type_match: compute_type_match(ctx.completion, ty),
|
||||||
exact_name_match: compute_exact_name_match(ctx.completion, &name),
|
exact_name_match: compute_exact_name_match(ctx.completion, &name),
|
||||||
|
is_skipping_completion: receiver.is_some(),
|
||||||
..CompletionRelevance::default()
|
..CompletionRelevance::default()
|
||||||
});
|
});
|
||||||
item.detail(ty.display(db, ctx.completion.edition).to_string())
|
item.detail(ty.display(db, ctx.completion.edition).to_string())
|
||||||
@ -213,6 +214,10 @@ pub(crate) fn render_tuple_field(
|
|||||||
);
|
);
|
||||||
item.detail(ty.display(ctx.db(), ctx.completion.edition).to_string())
|
item.detail(ty.display(ctx.db(), ctx.completion.edition).to_string())
|
||||||
.lookup_by(field.to_string());
|
.lookup_by(field.to_string());
|
||||||
|
item.set_relevance(CompletionRelevance {
|
||||||
|
is_skipping_completion: receiver.is_some(),
|
||||||
|
..ctx.completion_relevance()
|
||||||
|
});
|
||||||
item.build(ctx.db())
|
item.build(ctx.db())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1333,6 +1338,7 @@ fn main() { let _: m::Spam = S$0 }
|
|||||||
is_private_editable: false,
|
is_private_editable: false,
|
||||||
postfix_match: None,
|
postfix_match: None,
|
||||||
function: None,
|
function: None,
|
||||||
|
is_skipping_completion: false,
|
||||||
},
|
},
|
||||||
trigger_call_info: true,
|
trigger_call_info: true,
|
||||||
},
|
},
|
||||||
@ -1362,6 +1368,7 @@ fn main() { let _: m::Spam = S$0 }
|
|||||||
is_private_editable: false,
|
is_private_editable: false,
|
||||||
postfix_match: None,
|
postfix_match: None,
|
||||||
function: None,
|
function: None,
|
||||||
|
is_skipping_completion: false,
|
||||||
},
|
},
|
||||||
trigger_call_info: true,
|
trigger_call_info: true,
|
||||||
},
|
},
|
||||||
@ -1451,6 +1458,7 @@ fn foo() { A { the$0 } }
|
|||||||
is_private_editable: false,
|
is_private_editable: false,
|
||||||
postfix_match: None,
|
postfix_match: None,
|
||||||
function: None,
|
function: None,
|
||||||
|
is_skipping_completion: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -1509,6 +1517,7 @@ impl S {
|
|||||||
return_type: Other,
|
return_type: Other,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
is_skipping_completion: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
CompletionItem {
|
CompletionItem {
|
||||||
@ -1651,6 +1660,7 @@ fn foo(s: S) { s.$0 }
|
|||||||
return_type: Other,
|
return_type: Other,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
is_skipping_completion: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -1862,6 +1872,7 @@ fn f() -> i32 {
|
|||||||
is_private_editable: false,
|
is_private_editable: false,
|
||||||
postfix_match: None,
|
postfix_match: None,
|
||||||
function: None,
|
function: None,
|
||||||
|
is_skipping_completion: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -2622,6 +2633,7 @@ fn foo(f: Foo) { let _: &u32 = f.b$0 }
|
|||||||
return_type: Other,
|
return_type: Other,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
is_skipping_completion: false,
|
||||||
},
|
},
|
||||||
ref_match: "&@107",
|
ref_match: "&@107",
|
||||||
},
|
},
|
||||||
@ -2707,6 +2719,7 @@ fn foo() {
|
|||||||
is_private_editable: false,
|
is_private_editable: false,
|
||||||
postfix_match: None,
|
postfix_match: None,
|
||||||
function: None,
|
function: None,
|
||||||
|
is_skipping_completion: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -2764,6 +2777,7 @@ fn main() {
|
|||||||
return_type: Other,
|
return_type: Other,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
is_skipping_completion: false,
|
||||||
},
|
},
|
||||||
ref_match: "&@92",
|
ref_match: "&@92",
|
||||||
},
|
},
|
||||||
@ -3138,6 +3152,7 @@ fn main() {
|
|||||||
is_private_editable: false,
|
is_private_editable: false,
|
||||||
postfix_match: None,
|
postfix_match: None,
|
||||||
function: None,
|
function: None,
|
||||||
|
is_skipping_completion: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
CompletionItem {
|
CompletionItem {
|
||||||
@ -3171,6 +3186,7 @@ fn main() {
|
|||||||
is_private_editable: false,
|
is_private_editable: false,
|
||||||
postfix_match: None,
|
postfix_match: None,
|
||||||
function: None,
|
function: None,
|
||||||
|
is_skipping_completion: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -123,6 +123,7 @@ fn render(
|
|||||||
exact_name_match: compute_exact_name_match(completion, &call),
|
exact_name_match: compute_exact_name_match(completion, &call),
|
||||||
function,
|
function,
|
||||||
trait_: trait_info,
|
trait_: trait_info,
|
||||||
|
is_skipping_completion: matches!(func_kind, FuncKind::Method(_, Some(_))),
|
||||||
..ctx.completion_relevance()
|
..ctx.completion_relevance()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user