Skip to content

Commit

Permalink
Merge pull request #18756 from roife/fix-18751
Browse files Browse the repository at this point in the history
fix missing name enum when hovering on fields in variants
  • Loading branch information
Veykril authored Dec 25, 2024
2 parents dc90d2d + 5a3d1a6 commit bfc223e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions crates/ide/src/hover/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use either::Either;
use hir::{
db::ExpandDatabase, Adt, AsAssocItem, AsExternAssocItem, AssocItemContainer, CaptureKind,
DynCompatibilityViolation, HasCrate, HasSource, HirDisplay, Layout, LayoutError,
MethodViolationCode, Name, Semantics, Symbol, Trait, Type, TypeInfo,
MethodViolationCode, Name, Semantics, Symbol, Trait, Type, TypeInfo, VariantDef,
};
use ide_db::{
base_db::SourceDatabase,
Expand Down Expand Up @@ -378,7 +378,18 @@ pub(super) fn process_markup(

fn definition_owner_name(db: &RootDatabase, def: &Definition, edition: Edition) -> Option<String> {
match def {
Definition::Field(f) => Some(f.parent_def(db).name(db)),
Definition::Field(f) => {
let parent = f.parent_def(db);
let parent_name = parent.name(db);
let parent_name = parent_name.display(db, edition).to_string();
return match parent {
VariantDef::Variant(variant) => {
let enum_name = variant.parent_enum(db).name(db);
Some(format!("{}::{parent_name}", enum_name.display(db, edition)))
}
_ => Some(parent_name),
};
}
Definition::Local(l) => l.parent(db).name(db),
Definition::Variant(e) => Some(e.parent_enum(db).name(db)),

Expand Down
2 changes: 1 addition & 1 deletion crates/ide/src/hover/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7294,7 +7294,7 @@ enum Enum {
*field*
```rust
ra_test_fixture::RecordV
ra_test_fixture::Enum::RecordV
```
```rust
Expand Down

0 comments on commit bfc223e

Please sign in to comment.