Skip to content

Commit 102938e

Browse files
committed
naming is hard
1 parent 7bbd852 commit 102938e

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

crates/ide-completion/src/item.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ pub struct CompletionRelevance {
166166
pub postfix_match: Option<CompletionRelevancePostfixMatch>,
167167
/// This is set for type inference results
168168
pub is_definite: bool,
169-
/// This is set for items that are associated functions
170-
pub associated_fn: Option<CompletionRelevanceAssociatedFn>,
169+
/// This is set for items that are function (associated or method)
170+
pub function: Option<CompletionRelevanceFn>,
171171
}
172172

173173
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
@@ -210,14 +210,14 @@ pub enum CompletionRelevancePostfixMatch {
210210
}
211211

212212
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
213-
pub struct CompletionRelevanceAssociatedFn {
213+
pub struct CompletionRelevanceFn {
214214
pub has_args: bool,
215215
pub has_self_arg: bool,
216-
pub ty: CompletionRelevanceAssociatedFnType,
216+
pub ty: CompletionRelevanceFnType,
217217
}
218218

219219
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
220-
pub enum CompletionRelevanceAssociatedFnType {
220+
pub enum CompletionRelevanceFnType {
221221
Other,
222222
/// Returns a type that is expected in this context
223223
ReturnsExpectedType,
@@ -253,7 +253,7 @@ impl CompletionRelevance {
253253
postfix_match,
254254
is_definite,
255255
is_item_from_notable_trait,
256-
associated_fn,
256+
function: associated_fn,
257257
} = self;
258258

259259
// lower rank private things
@@ -302,11 +302,11 @@ impl CompletionRelevance {
302302
score += associated_fn
303303
.map(|asf| {
304304
let mut score = match asf.ty {
305-
CompletionRelevanceAssociatedFnType::ReturnsExpectedType => 20,
306-
CompletionRelevanceAssociatedFnType::DirectConstructor => 15,
307-
CompletionRelevanceAssociatedFnType::Builder => 10,
308-
CompletionRelevanceAssociatedFnType::Constructor => 5,
309-
CompletionRelevanceAssociatedFnType::Other => 0,
305+
CompletionRelevanceFnType::ReturnsExpectedType => 20,
306+
CompletionRelevanceFnType::DirectConstructor => 15,
307+
CompletionRelevanceFnType::Builder => 10,
308+
CompletionRelevanceFnType::Constructor => 5,
309+
CompletionRelevanceFnType::Other => 0,
310310
};
311311

312312
// Prefer functions with no arguments, then functions with self arguments

crates/ide-completion/src/render.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ fn main() { let _: m::Spam = S$0 }
11771177
is_private_editable: false,
11781178
postfix_match: None,
11791179
is_definite: false,
1180-
associated_fn: None,
1180+
function: None,
11811181
},
11821182
trigger_call_info: true,
11831183
},
@@ -1205,7 +1205,7 @@ fn main() { let _: m::Spam = S$0 }
12051205
is_private_editable: false,
12061206
postfix_match: None,
12071207
is_definite: false,
1208-
associated_fn: None,
1208+
function: None,
12091209
},
12101210
trigger_call_info: true,
12111211
},
@@ -1285,7 +1285,7 @@ fn foo() { A { the$0 } }
12851285
is_private_editable: false,
12861286
postfix_match: None,
12871287
is_definite: false,
1288-
associated_fn: None,
1288+
function: None,
12891289
},
12901290
},
12911291
]
@@ -1330,8 +1330,8 @@ impl S {
13301330
is_private_editable: false,
13311331
postfix_match: None,
13321332
is_definite: false,
1333-
associated_fn: Some(
1334-
CompletionRelevanceAssociatedFn {
1333+
function: Some(
1334+
CompletionRelevanceFn {
13351335
has_args: true,
13361336
has_self_arg: true,
13371337
ty: Other,
@@ -1454,8 +1454,8 @@ fn foo(s: S) { s.$0 }
14541454
is_private_editable: false,
14551455
postfix_match: None,
14561456
is_definite: false,
1457-
associated_fn: Some(
1458-
CompletionRelevanceAssociatedFn {
1457+
function: Some(
1458+
CompletionRelevanceFn {
14591459
has_args: true,
14601460
has_self_arg: true,
14611461
ty: Other,
@@ -2223,8 +2223,8 @@ fn foo(f: Foo) { let _: &u32 = f.b$0 }
22232223
is_private_editable: false,
22242224
postfix_match: None,
22252225
is_definite: false,
2226-
associated_fn: Some(
2227-
CompletionRelevanceAssociatedFn {
2226+
function: Some(
2227+
CompletionRelevanceFn {
22282228
has_args: true,
22292229
has_self_arg: true,
22302230
ty: Other,
@@ -2305,7 +2305,7 @@ fn foo() {
23052305
is_private_editable: false,
23062306
postfix_match: None,
23072307
is_definite: false,
2308-
associated_fn: None,
2308+
function: None,
23092309
},
23102310
},
23112311
]
@@ -2354,8 +2354,8 @@ fn main() {
23542354
is_private_editable: false,
23552355
postfix_match: None,
23562356
is_definite: false,
2357-
associated_fn: Some(
2358-
CompletionRelevanceAssociatedFn {
2357+
function: Some(
2358+
CompletionRelevanceFn {
23592359
has_args: false,
23602360
has_self_arg: false,
23612361
ty: Other,

crates/ide-completion/src/render/function.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use crate::{
1111
CompletionContext, DotAccess, DotAccessKind, PathCompletionCtx, PathKind, Qualified,
1212
},
1313
item::{
14-
Builder, CompletionItem, CompletionItemKind, CompletionRelevance,
15-
CompletionRelevanceAssociatedFn, CompletionRelevanceAssociatedFnType,
14+
Builder, CompletionItem, CompletionItemKind, CompletionRelevance, CompletionRelevanceFn,
15+
CompletionRelevanceFnType,
1616
},
1717
render::{compute_exact_name_match, compute_ref_match, compute_type_match, RenderContext},
1818
CallableSnippets,
@@ -112,7 +112,7 @@ fn render(
112112
compute_type_match(completion, &func.ty(db))
113113
},
114114
exact_name_match: compute_exact_name_match(completion, &call),
115-
associated_fn: compute_associated_fn(&ctx, func, &func_kind, db),
115+
function: compute_associated_fn(&ctx, func, &func_kind, db),
116116
is_op_method,
117117
is_item_from_notable_trait,
118118
..ctx.completion_relevance()
@@ -168,7 +168,7 @@ fn compute_associated_fn(
168168
func: hir::Function,
169169
func_kind: &FuncKind<'_>,
170170
db: &dyn HirDatabase,
171-
) -> Option<CompletionRelevanceAssociatedFn> {
171+
) -> Option<CompletionRelevanceFn> {
172172
if func.as_assoc_item(ctx.db()).is_none() {
173173
return None;
174174
}
@@ -202,21 +202,21 @@ fn compute_associated_fn(
202202
{
203203
// impl Foo { fn baz(&self) -> u32 { 0 } }
204204
// let _: u32 = foo.$0; // baz is preferred as it returns expected u32
205-
CompletionRelevanceAssociatedFnType::ReturnsExpectedType
205+
CompletionRelevanceFnType::ReturnsExpectedType
206206
} else if ret_type.display(db).to_string().ends_with("Builder") {
207207
// fn([..]) -> [..]Builder
208-
CompletionRelevanceAssociatedFnType::Builder
208+
CompletionRelevanceFnType::Builder
209209
} else if returns_self_wrapped {
210210
// fn([..]) -> Result<A>
211-
CompletionRelevanceAssociatedFnType::Constructor
211+
CompletionRelevanceFnType::Constructor
212212
} else if returns_self {
213213
// fn([..]) -> A
214-
CompletionRelevanceAssociatedFnType::DirectConstructor
214+
CompletionRelevanceFnType::DirectConstructor
215215
} else {
216-
CompletionRelevanceAssociatedFnType::Other
216+
CompletionRelevanceFnType::Other
217217
};
218218

219-
Some(CompletionRelevanceAssociatedFn { ty, has_args, has_self_arg })
219+
Some(CompletionRelevanceFn { ty, has_args, has_self_arg })
220220
}
221221

222222
pub(super) fn add_call_parens<'b>(

0 commit comments

Comments
 (0)