mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Refactor
This commit is contained in:
parent
953b5f23cc
commit
174952e89b
1 changed files with 18 additions and 24 deletions
|
@ -307,42 +307,36 @@ impl Completions {
|
||||||
|
|
||||||
pub(crate) fn compute_score(
|
pub(crate) fn compute_score(
|
||||||
ctx: &CompletionContext,
|
ctx: &CompletionContext,
|
||||||
|
// FIXME: this definitely should be a `Type`
|
||||||
ty: &str,
|
ty: &str,
|
||||||
name: &str,
|
name: &str,
|
||||||
) -> Option<CompletionScore> {
|
) -> Option<CompletionScore> {
|
||||||
let (active_name, active_type) = if let Some(record_field) = &ctx.record_field_syntax {
|
let (active_name, active_type) = if let Some(record_field) = &ctx.record_field_syntax {
|
||||||
if let Some((struct_field, _)) = ctx.sema.resolve_record_field(record_field) {
|
let (struct_field, _local) = ctx.sema.resolve_record_field(record_field)?;
|
||||||
(
|
(
|
||||||
struct_field.name(ctx.db).to_string(),
|
struct_field.name(ctx.db).to_string(),
|
||||||
struct_field.signature_ty(ctx.db).display(ctx.db).to_string(),
|
struct_field.signature_ty(ctx.db).display(ctx.db).to_string(),
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
} else if let Some(call_info) = call_info(ctx.db, ctx.file_position) {
|
} else if let Some(call_info) = call_info(ctx.db, ctx.file_position) {
|
||||||
if call_info.active_parameter_type().is_some()
|
(call_info.active_parameter_name()?, call_info.active_parameter_type()?)
|
||||||
&& call_info.active_parameter_name().is_some()
|
|
||||||
{
|
|
||||||
(call_info.active_parameter_name().unwrap(), call_info.active_parameter_type().unwrap())
|
|
||||||
} else {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Compute score
|
// Compute score
|
||||||
// For the same type
|
// For the same type
|
||||||
if &active_type == ty {
|
if &active_type != ty {
|
||||||
// If same type + same name then go top position
|
return None;
|
||||||
let res = if active_name == name {
|
|
||||||
CompletionScore::TypeAndNameMatch
|
|
||||||
} else {
|
|
||||||
CompletionScore::TypeMatch
|
|
||||||
};
|
|
||||||
return Some(res);
|
|
||||||
}
|
}
|
||||||
None
|
|
||||||
|
let mut res = CompletionScore::TypeMatch;
|
||||||
|
|
||||||
|
// If same type + same name then go top position
|
||||||
|
if active_name == name {
|
||||||
|
res = CompletionScore::TypeAndNameMatch
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Params {
|
enum Params {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue