Skip to content

Commit 22adcfd

Browse files
bors[bot]Veykril
andauthored
Merge #11086
11086: internal: Simplify completion rendering r=Veykril a=Veykril Removes all the helper render structs in favor of simple functions, making things a lot easier to oversee(imho) bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents a406574 + 929cae7 commit 22adcfd

File tree

14 files changed

+383
-465
lines changed

14 files changed

+383
-465
lines changed

crates/hir/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3024,7 +3024,7 @@ impl Callable {
30243024
}
30253025

30263026
/// For IDE only
3027-
#[derive(Debug, PartialEq, Eq, Hash)]
3027+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
30283028
pub enum ScopeDef {
30293029
ModuleDef(ModuleDef),
30303030
MacroDef(MacroDef),

crates/ide_completion/src/completions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Completions {
8484
&mut self,
8585
ctx: &CompletionContext,
8686
local_name: hir::Name,
87-
resolution: &hir::ScopeDef,
87+
resolution: hir::ScopeDef,
8888
) {
8989
if ctx.is_scope_def_hidden(resolution) {
9090
cov_mark::hit!(qualified_path_doc_hidden);
@@ -115,7 +115,7 @@ impl Completions {
115115
if !ctx.is_visible(&func) {
116116
return;
117117
}
118-
self.add_opt(render_fn(RenderContext::new(ctx), None, local_name, func));
118+
self.add(render_fn(RenderContext::new(ctx), None, local_name, func));
119119
}
120120

121121
pub(crate) fn add_method(
@@ -128,7 +128,7 @@ impl Completions {
128128
if !ctx.is_visible(&func) {
129129
return;
130130
}
131-
self.add_opt(render_method(RenderContext::new(ctx), None, receiver, local_name, func));
131+
self.add(render_method(RenderContext::new(ctx), None, receiver, local_name, func));
132132
}
133133

134134
pub(crate) fn add_const(&mut self, ctx: &CompletionContext, konst: hir::Const) {

crates/ide_completion/src/completions/lifetime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub(crate) fn complete_lifetime(acc: &mut Completions, ctx: &CompletionContext)
3535
ctx.scope.process_all_names(&mut |name, res| {
3636
if let ScopeDef::GenericParam(hir::GenericParam::LifetimeParam(_)) = res {
3737
if param_lifetime != Some(&*name.to_smol_str()) {
38-
acc.add_resolution(ctx, name, &res);
38+
acc.add_resolution(ctx, name, res);
3939
}
4040
}
4141
});
@@ -51,7 +51,7 @@ pub(crate) fn complete_label(acc: &mut Completions, ctx: &CompletionContext) {
5151
}
5252
ctx.scope.process_all_names(&mut |name, res| {
5353
if let ScopeDef::Label(_) = res {
54-
acc.add_resolution(ctx, name, &res);
54+
acc.add_resolution(ctx, name, res);
5555
}
5656
});
5757
}

crates/ide_completion/src/completions/pattern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
5959
_ => false,
6060
};
6161
if add_resolution {
62-
acc.add_resolution(ctx, name, &res);
62+
acc.add_resolution(ctx, name, res);
6363
}
6464
});
6565
}

crates/ide_completion/src/completions/qualified_path.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
4444
}
4545
}
4646
if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = def {
47-
acc.add_resolution(ctx, name, &def);
47+
acc.add_resolution(ctx, name, def);
4848
}
4949
}
5050
}
@@ -64,7 +64,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
6464
.next()
6565
{
6666
if let Some(name) = next.name(ctx.db) {
67-
acc.add_resolution(ctx, name, &ScopeDef::ModuleDef(next.into()));
67+
acc.add_resolution(ctx, name, ScopeDef::ModuleDef(next.into()));
6868
}
6969
}
7070
}
@@ -80,7 +80,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
8080
_ => false,
8181
};
8282
if add_resolution {
83-
acc.add_resolution(ctx, name, &def);
83+
acc.add_resolution(ctx, name, def);
8484
}
8585
}
8686
}
@@ -147,7 +147,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
147147
};
148148

149149
if add_resolution {
150-
acc.add_resolution(ctx, name, &def);
150+
acc.add_resolution(ctx, name, def);
151151
}
152152
}
153153
}

crates/ide_completion/src/completions/unqualified_path.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
2424
cov_mark::hit!(unqualified_path_only_modules_in_import);
2525
ctx.process_all_names(&mut |name, res| {
2626
if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res {
27-
acc.add_resolution(ctx, name, &res);
27+
acc.add_resolution(ctx, name, res);
2828
}
2929
});
3030

@@ -43,7 +43,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
4343
_ => false,
4444
};
4545
if add_resolution {
46-
acc.add_resolution(ctx, name, &res);
46+
acc.add_resolution(ctx, name, res);
4747
}
4848
});
4949
return;
@@ -61,7 +61,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
6161
}
6262
}
6363
if let hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res {
64-
acc.add_resolution(ctx, name, &res);
64+
acc.add_resolution(ctx, name, res);
6565
}
6666
});
6767
return;
@@ -76,7 +76,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
7676
_ => false,
7777
};
7878
if add_resolution {
79-
acc.add_resolution(ctx, name, &res);
79+
acc.add_resolution(ctx, name, res);
8080
}
8181
});
8282
return;
@@ -134,7 +134,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
134134
_ => true,
135135
};
136136
if add_resolution {
137-
acc.add_resolution(ctx, name, &res);
137+
acc.add_resolution(ctx, name, res);
138138
}
139139
});
140140
}

crates/ide_completion/src/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl<'a> CompletionContext<'a> {
278278
self.is_visible_impl(&item.visibility(self.db), &item.attrs(self.db), item.krate(self.db))
279279
}
280280

281-
pub(crate) fn is_scope_def_hidden(&self, scope_def: &ScopeDef) -> bool {
281+
pub(crate) fn is_scope_def_hidden(&self, scope_def: ScopeDef) -> bool {
282282
if let (Some(attrs), Some(krate)) = (scope_def.attrs(self.db), scope_def.krate(self.db)) {
283283
return self.is_doc_hidden(&attrs, krate);
284284
}
@@ -303,7 +303,7 @@ impl<'a> CompletionContext<'a> {
303303
/// A version of [`SemanticsScope::process_all_names`] that filters out `#[doc(hidden)]` items.
304304
pub(crate) fn process_all_names(&self, f: &mut dyn FnMut(Name, ScopeDef)) {
305305
self.scope.process_all_names(&mut |name, def| {
306-
if self.is_scope_def_hidden(&def) {
306+
if self.is_scope_def_hidden(def) {
307307
return;
308308
}
309309

@@ -367,7 +367,7 @@ impl<'a> CompletionContext<'a> {
367367
parse.reparse(&edit).tree()
368368
};
369369
let fake_ident_token =
370-
file_with_fake_ident.syntax().token_at_offset(offset).right_biased().unwrap();
370+
file_with_fake_ident.syntax().token_at_offset(offset).right_biased()?;
371371

372372
let original_token = original_file.syntax().token_at_offset(offset).left_biased()?;
373373
let token = sema.descend_into_macros_single(original_token.clone());

0 commit comments

Comments
 (0)