mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-04 20:54:13 +00:00
Implement glob imports from enums
This commit is contained in:
parent
35cfb418ba
commit
c1e295682e
@ -327,7 +327,7 @@ impl Enum {
|
|||||||
db.enum_data(*self).name.clone()
|
db.enum_data(*self).name.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn variants(&self, db: &impl HirDatabase) -> Vec<EnumVariant> {
|
pub fn variants(&self, db: &impl PersistentHirDatabase) -> Vec<EnumVariant> {
|
||||||
db.enum_data(*self)
|
db.enum_data(*self)
|
||||||
.variants
|
.variants
|
||||||
.iter()
|
.iter()
|
||||||
@ -389,7 +389,7 @@ impl EnumVariant {
|
|||||||
self.parent
|
self.parent
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self, db: &impl HirDatabase) -> Option<Name> {
|
pub fn name(&self, db: &impl PersistentHirDatabase) -> Option<Name> {
|
||||||
db.enum_data(self.parent).variants[self.id].name.clone()
|
db.enum_data(self.parent).variants[self.id].name.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,14 +264,45 @@ where
|
|||||||
import: &ImportData,
|
import: &ImportData,
|
||||||
) -> ReachedFixedPoint {
|
) -> ReachedFixedPoint {
|
||||||
log::debug!("resolving import: {:?}", import);
|
log::debug!("resolving import: {:?}", import);
|
||||||
if import.is_glob {
|
|
||||||
return ReachedFixedPoint::Yes;
|
|
||||||
};
|
|
||||||
let original_module = Module { krate: self.krate, module_id };
|
let original_module = Module { krate: self.krate, module_id };
|
||||||
let (def, reached_fixedpoint) =
|
let (def, reached_fixedpoint) =
|
||||||
self.result.resolve_path_fp(self.db, original_module, &import.path);
|
self.result.resolve_path_fp(self.db, original_module, &import.path);
|
||||||
|
|
||||||
if reached_fixedpoint == ReachedFixedPoint::Yes {
|
if reached_fixedpoint != ReachedFixedPoint::Yes {
|
||||||
|
return reached_fixedpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
if import.is_glob {
|
||||||
|
log::debug!("glob import: {:?}", import);
|
||||||
|
match def.take_types() {
|
||||||
|
Some(ModuleDef::Module(m)) => {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
Some(ModuleDef::Enum(e)) => {
|
||||||
|
tested_by!(glob_enum);
|
||||||
|
let variants = e.variants(self.db);
|
||||||
|
let resolutions = variants.into_iter()
|
||||||
|
.filter_map(|variant| {
|
||||||
|
let res = Resolution {
|
||||||
|
def: PerNs::both(variant.into(), e.into()),
|
||||||
|
import: Some(import_id),
|
||||||
|
};
|
||||||
|
let name = variant.name(self.db)?;
|
||||||
|
Some((name, res))
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
self.update(module_id, |items| {
|
||||||
|
items.items.extend(resolutions);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Some(d) => {
|
||||||
|
log::debug!("glob import {:?} from non-module/enum {:?}", import, d);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
log::debug!("glob import {:?} didn't resolve as type", import);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
let last_segment = import.path.segments.last().unwrap();
|
let last_segment = import.path.segments.last().unwrap();
|
||||||
let name = import.alias.clone().unwrap_or_else(|| last_segment.name.clone());
|
let name = import.alias.clone().unwrap_or_else(|| last_segment.name.clone());
|
||||||
log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
|
log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
|
||||||
|
Loading…
Reference in New Issue
Block a user