Skip to content

Commit d4accf8

Browse files
committed
Auto merge of #16099 - Veykril:flyimport, r=Veykril
internal: Improve import asset perf a bit And bump the query limit from 40 to 100
2 parents e004a5d + 1604ad1 commit d4accf8

File tree

11 files changed

+196
-191
lines changed

11 files changed

+196
-191
lines changed

crates/hir/src/symbols.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub struct FileSymbol {
2323
pub loc: DeclarationLocation,
2424
pub container_name: Option<SmolStr>,
2525
pub is_alias: bool,
26+
pub is_assoc: bool,
2627
}
2728

2829
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -121,34 +122,34 @@ impl<'a> SymbolCollector<'a> {
121122
match module_def_id {
122123
ModuleDefId::ModuleId(id) => self.push_module(id),
123124
ModuleDefId::FunctionId(id) => {
124-
self.push_decl(id);
125+
self.push_decl(id, false);
125126
self.collect_from_body(id);
126127
}
127-
ModuleDefId::AdtId(AdtId::StructId(id)) => self.push_decl(id),
128-
ModuleDefId::AdtId(AdtId::EnumId(id)) => self.push_decl(id),
129-
ModuleDefId::AdtId(AdtId::UnionId(id)) => self.push_decl(id),
128+
ModuleDefId::AdtId(AdtId::StructId(id)) => self.push_decl(id, false),
129+
ModuleDefId::AdtId(AdtId::EnumId(id)) => self.push_decl(id, false),
130+
ModuleDefId::AdtId(AdtId::UnionId(id)) => self.push_decl(id, false),
130131
ModuleDefId::ConstId(id) => {
131-
self.push_decl(id);
132+
self.push_decl(id, false);
132133
self.collect_from_body(id);
133134
}
134135
ModuleDefId::StaticId(id) => {
135-
self.push_decl(id);
136+
self.push_decl(id, false);
136137
self.collect_from_body(id);
137138
}
138139
ModuleDefId::TraitId(id) => {
139-
self.push_decl(id);
140+
self.push_decl(id, false);
140141
self.collect_from_trait(id);
141142
}
142143
ModuleDefId::TraitAliasId(id) => {
143-
self.push_decl(id);
144+
self.push_decl(id, false);
144145
}
145146
ModuleDefId::TypeAliasId(id) => {
146-
self.push_decl(id);
147+
self.push_decl(id, false);
147148
}
148149
ModuleDefId::MacroId(id) => match id {
149-
MacroId::Macro2Id(id) => self.push_decl(id),
150-
MacroId::MacroRulesId(id) => self.push_decl(id),
151-
MacroId::ProcMacroId(id) => self.push_decl(id),
150+
MacroId::Macro2Id(id) => self.push_decl(id, false),
151+
MacroId::MacroRulesId(id) => self.push_decl(id, false),
152+
MacroId::ProcMacroId(id) => self.push_decl(id, false),
152153
},
153154
// Don't index these.
154155
ModuleDefId::BuiltinType(_) => {}
@@ -190,6 +191,7 @@ impl<'a> SymbolCollector<'a> {
190191
container_name: self.current_container_name.clone(),
191192
loc: dec_loc,
192193
is_alias: false,
194+
is_assoc: false,
193195
});
194196
});
195197
}
@@ -202,9 +204,9 @@ impl<'a> SymbolCollector<'a> {
202204
for &id in id {
203205
if id.module(self.db.upcast()) == module_id {
204206
match id {
205-
MacroId::Macro2Id(id) => self.push_decl(id),
206-
MacroId::MacroRulesId(id) => self.push_decl(id),
207-
MacroId::ProcMacroId(id) => self.push_decl(id),
207+
MacroId::Macro2Id(id) => self.push_decl(id, false),
208+
MacroId::MacroRulesId(id) => self.push_decl(id, false),
209+
MacroId::ProcMacroId(id) => self.push_decl(id, false),
208210
}
209211
}
210212
}
@@ -266,13 +268,13 @@ impl<'a> SymbolCollector<'a> {
266268

267269
fn push_assoc_item(&mut self, assoc_item_id: AssocItemId) {
268270
match assoc_item_id {
269-
AssocItemId::FunctionId(id) => self.push_decl(id),
270-
AssocItemId::ConstId(id) => self.push_decl(id),
271-
AssocItemId::TypeAliasId(id) => self.push_decl(id),
271+
AssocItemId::FunctionId(id) => self.push_decl(id, true),
272+
AssocItemId::ConstId(id) => self.push_decl(id, true),
273+
AssocItemId::TypeAliasId(id) => self.push_decl(id, true),
272274
}
273275
}
274276

275-
fn push_decl<L>(&mut self, id: L)
277+
fn push_decl<L>(&mut self, id: L, is_assoc: bool)
276278
where
277279
L: Lookup + Into<ModuleDefId>,
278280
<L as Lookup>::Data: HasSource,
@@ -296,6 +298,7 @@ impl<'a> SymbolCollector<'a> {
296298
loc: dec_loc.clone(),
297299
container_name: self.current_container_name.clone(),
298300
is_alias: true,
301+
is_assoc,
299302
});
300303
}
301304
}
@@ -306,6 +309,7 @@ impl<'a> SymbolCollector<'a> {
306309
container_name: self.current_container_name.clone(),
307310
loc: dec_loc,
308311
is_alias: false,
312+
is_assoc,
309313
});
310314
}
311315

@@ -331,6 +335,7 @@ impl<'a> SymbolCollector<'a> {
331335
loc: dec_loc.clone(),
332336
container_name: self.current_container_name.clone(),
333337
is_alias: true,
338+
is_assoc: false,
334339
});
335340
}
336341
}
@@ -341,6 +346,7 @@ impl<'a> SymbolCollector<'a> {
341346
container_name: self.current_container_name.clone(),
342347
loc: dec_loc,
343348
is_alias: false,
349+
is_assoc: false,
344350
});
345351
}
346352
}

crates/ide-completion/src/item.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,11 @@ impl Builder {
458458
}
459459
if let [import_edit] = &*self.imports_to_add {
460460
// snippets can have multiple imports, but normal completions only have up to one
461-
if let Some(original_path) = import_edit.original_path.as_ref() {
462-
label_detail.replace(SmolStr::from(format!(
463-
"{} (use {})",
464-
label_detail.as_deref().unwrap_or_default(),
465-
original_path.display(db)
466-
)));
467-
}
461+
label_detail.replace(SmolStr::from(format!(
462+
"{} (use {})",
463+
label_detail.as_deref().unwrap_or_default(),
464+
import_edit.import_path.display(db)
465+
)));
468466
} else if let Some(trait_name) = self.trait_name {
469467
label_detail.replace(SmolStr::from(format!(
470468
"{} (as {trait_name})",

crates/ide-completion/src/snippet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ fn import_edits(ctx: &CompletionContext<'_>, requires: &[GreenNode]) -> Option<V
181181
ctx.config.prefer_no_std,
182182
ctx.config.prefer_prelude,
183183
)?;
184-
Some((path.len() > 1).then(|| LocatedImport::new(path.clone(), item, item, None)))
184+
Some((path.len() > 1).then(|| LocatedImport::new(path.clone(), item, item)))
185185
};
186186
let mut res = Vec::with_capacity(requires.len());
187187
for import in requires {

crates/ide-completion/src/tests/flyimport.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,8 @@ fn main() {
597597
}
598598
"#,
599599
expect![[r#"
600-
ct SPECIAL_CONST (use dep::test_mod::TestTrait) u8 DEPRECATED
601600
fn weird_function() (use dep::test_mod::TestTrait) fn() DEPRECATED
601+
ct SPECIAL_CONST (use dep::test_mod::TestTrait) u8 DEPRECATED
602602
"#]],
603603
);
604604
}
@@ -717,27 +717,27 @@ fn main() {
717717
check(
718718
fixture,
719719
expect![[r#"
720-
st Item (use foo::bar::baz::Item) Item
720+
st Item (use foo::bar) Item
721721
"#]],
722722
);
723723

724724
check_edit(
725725
"Item",
726726
fixture,
727727
r#"
728-
use foo::bar;
728+
use foo::bar;
729729
730-
mod foo {
731-
pub mod bar {
732-
pub mod baz {
733-
pub struct Item;
734-
}
735-
}
730+
mod foo {
731+
pub mod bar {
732+
pub mod baz {
733+
pub struct Item;
736734
}
735+
}
736+
}
737737
738-
fn main() {
739-
bar::baz::Item
740-
}"#,
738+
fn main() {
739+
bar::baz::Item
740+
}"#,
741741
);
742742
}
743743

@@ -803,7 +803,7 @@ fn main() {
803803
check(
804804
fixture,
805805
expect![[r#"
806-
ct TEST_ASSOC (use foo::bar::Item) usize
806+
ct TEST_ASSOC (use foo::bar) usize
807807
"#]],
808808
);
809809

0 commit comments

Comments
 (0)