Skip to content

Commit

Permalink
Auto merge of #16099 - Veykril:flyimport, r=Veykril
Browse files Browse the repository at this point in the history
internal: Improve import asset perf a bit

And bump the query limit from 40 to 100
  • Loading branch information
bors committed Dec 12, 2023
2 parents e004a5d + 6dee64c commit ce49437
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 191 deletions.
44 changes: 25 additions & 19 deletions crates/hir/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct FileSymbol {
pub loc: DeclarationLocation,
pub container_name: Option<SmolStr>,
pub is_alias: bool,
pub is_assoc: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -121,34 +122,34 @@ impl<'a> SymbolCollector<'a> {
match module_def_id {
ModuleDefId::ModuleId(id) => self.push_module(id),
ModuleDefId::FunctionId(id) => {
self.push_decl(id);
self.push_decl(id, false);
self.collect_from_body(id);
}
ModuleDefId::AdtId(AdtId::StructId(id)) => self.push_decl(id),
ModuleDefId::AdtId(AdtId::EnumId(id)) => self.push_decl(id),
ModuleDefId::AdtId(AdtId::UnionId(id)) => self.push_decl(id),
ModuleDefId::AdtId(AdtId::StructId(id)) => self.push_decl(id, false),
ModuleDefId::AdtId(AdtId::EnumId(id)) => self.push_decl(id, false),
ModuleDefId::AdtId(AdtId::UnionId(id)) => self.push_decl(id, false),
ModuleDefId::ConstId(id) => {
self.push_decl(id);
self.push_decl(id, false);
self.collect_from_body(id);
}
ModuleDefId::StaticId(id) => {
self.push_decl(id);
self.push_decl(id, false);
self.collect_from_body(id);
}
ModuleDefId::TraitId(id) => {
self.push_decl(id);
self.push_decl(id, false);
self.collect_from_trait(id);
}
ModuleDefId::TraitAliasId(id) => {
self.push_decl(id);
self.push_decl(id, false);
}
ModuleDefId::TypeAliasId(id) => {
self.push_decl(id);
self.push_decl(id, false);
}
ModuleDefId::MacroId(id) => match id {
MacroId::Macro2Id(id) => self.push_decl(id),
MacroId::MacroRulesId(id) => self.push_decl(id),
MacroId::ProcMacroId(id) => self.push_decl(id),
MacroId::Macro2Id(id) => self.push_decl(id, false),
MacroId::MacroRulesId(id) => self.push_decl(id, false),
MacroId::ProcMacroId(id) => self.push_decl(id, false),
},
// Don't index these.
ModuleDefId::BuiltinType(_) => {}
Expand Down Expand Up @@ -190,6 +191,7 @@ impl<'a> SymbolCollector<'a> {
container_name: self.current_container_name.clone(),
loc: dec_loc,
is_alias: false,
is_assoc: false,
});
});
}
Expand All @@ -202,9 +204,9 @@ impl<'a> SymbolCollector<'a> {
for &id in id {
if id.module(self.db.upcast()) == module_id {
match id {
MacroId::Macro2Id(id) => self.push_decl(id),
MacroId::MacroRulesId(id) => self.push_decl(id),
MacroId::ProcMacroId(id) => self.push_decl(id),
MacroId::Macro2Id(id) => self.push_decl(id, false),
MacroId::MacroRulesId(id) => self.push_decl(id, false),
MacroId::ProcMacroId(id) => self.push_decl(id, false),
}
}
}
Expand Down Expand Up @@ -266,13 +268,13 @@ impl<'a> SymbolCollector<'a> {

fn push_assoc_item(&mut self, assoc_item_id: AssocItemId) {
match assoc_item_id {
AssocItemId::FunctionId(id) => self.push_decl(id),
AssocItemId::ConstId(id) => self.push_decl(id),
AssocItemId::TypeAliasId(id) => self.push_decl(id),
AssocItemId::FunctionId(id) => self.push_decl(id, true),
AssocItemId::ConstId(id) => self.push_decl(id, true),
AssocItemId::TypeAliasId(id) => self.push_decl(id, true),
}
}

fn push_decl<L>(&mut self, id: L)
fn push_decl<L>(&mut self, id: L, is_assoc: bool)
where
L: Lookup + Into<ModuleDefId>,
<L as Lookup>::Data: HasSource,
Expand All @@ -296,6 +298,7 @@ impl<'a> SymbolCollector<'a> {
loc: dec_loc.clone(),
container_name: self.current_container_name.clone(),
is_alias: true,
is_assoc,
});
}
}
Expand All @@ -306,6 +309,7 @@ impl<'a> SymbolCollector<'a> {
container_name: self.current_container_name.clone(),
loc: dec_loc,
is_alias: false,
is_assoc,
});
}

Expand All @@ -331,6 +335,7 @@ impl<'a> SymbolCollector<'a> {
loc: dec_loc.clone(),
container_name: self.current_container_name.clone(),
is_alias: true,
is_assoc: false,
});
}
}
Expand All @@ -341,6 +346,7 @@ impl<'a> SymbolCollector<'a> {
container_name: self.current_container_name.clone(),
loc: dec_loc,
is_alias: false,
is_assoc: false,
});
}
}
12 changes: 5 additions & 7 deletions crates/ide-completion/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,11 @@ impl Builder {
}
if let [import_edit] = &*self.imports_to_add {
// snippets can have multiple imports, but normal completions only have up to one
if let Some(original_path) = import_edit.original_path.as_ref() {
label_detail.replace(SmolStr::from(format!(
"{} (use {})",
label_detail.as_deref().unwrap_or_default(),
original_path.display(db)
)));
}
label_detail.replace(SmolStr::from(format!(
"{} (use {})",
label_detail.as_deref().unwrap_or_default(),
import_edit.import_path.display(db)
)));
} else if let Some(trait_name) = self.trait_name {
label_detail.replace(SmolStr::from(format!(
"{} (as {trait_name})",
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-completion/src/snippet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn import_edits(ctx: &CompletionContext<'_>, requires: &[GreenNode]) -> Option<V
ctx.config.prefer_no_std,
ctx.config.prefer_prelude,
)?;
Some((path.len() > 1).then(|| LocatedImport::new(path.clone(), item, item, None)))
Some((path.len() > 1).then(|| LocatedImport::new(path.clone(), item, item)))
};
let mut res = Vec::with_capacity(requires.len());
for import in requires {
Expand Down
26 changes: 13 additions & 13 deletions crates/ide-completion/src/tests/flyimport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ fn main() {
}
"#,
expect![[r#"
ct SPECIAL_CONST (use dep::test_mod::TestTrait) u8 DEPRECATED
fn weird_function() (use dep::test_mod::TestTrait) fn() DEPRECATED
ct SPECIAL_CONST (use dep::test_mod::TestTrait) u8 DEPRECATED
"#]],
);
}
Expand Down Expand Up @@ -717,27 +717,27 @@ fn main() {
check(
fixture,
expect![[r#"
st Item (use foo::bar::baz::Item) Item
st Item (use foo::bar) Item
"#]],
);

check_edit(
"Item",
fixture,
r#"
use foo::bar;
use foo::bar;
mod foo {
pub mod bar {
pub mod baz {
pub struct Item;
}
}
mod foo {
pub mod bar {
pub mod baz {
pub struct Item;
}
}
}
fn main() {
bar::baz::Item
}"#,
fn main() {
bar::baz::Item
}"#,
);
}

Expand Down Expand Up @@ -803,7 +803,7 @@ fn main() {
check(
fixture,
expect![[r#"
ct TEST_ASSOC (use foo::bar::Item) usize
ct TEST_ASSOC (use foo::bar) usize
"#]],
);

Expand Down
Loading

0 comments on commit ce49437

Please sign in to comment.