Skip to content

Commit

Permalink
Fix definition nodes for other generic items
Browse files Browse the repository at this point in the history
commit-id:517d9f93
  • Loading branch information
mkaput committed Feb 5, 2025
1 parent 4f8557f commit 673a287
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
29 changes: 23 additions & 6 deletions src/lang/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use std::iter;

use cairo_lang_defs::db::DefsGroup;
use cairo_lang_defs::ids::{
LanguageElementId, LocalVarLongId, LookupItemId, MemberId, ModuleId, ModuleItemId,
NamedLanguageElementId, SubmoduleLongId, TopLevelLanguageElementId, TraitItemId, VarId,
GenericTypeId, LanguageElementId, LocalVarLongId, LookupItemId, MemberId, ModuleId,
ModuleItemId, NamedLanguageElementId, SubmoduleLongId, TopLevelLanguageElementId, TraitItemId,
VarId,
};
use cairo_lang_diagnostics::ToOption;
use cairo_lang_doc::db::DocGroup;
Expand Down Expand Up @@ -649,7 +650,9 @@ fn resolved_generic_item_def(
item: ResolvedGenericItem,
) -> Option<SyntaxStablePtrId> {
Some(match item {
ResolvedGenericItem::GenericConstant(item) => item.untyped_stable_ptr(db),
ResolvedGenericItem::GenericConstant(item) => {
item.stable_ptr(db).lookup(db).name(db).stable_ptr().untyped()
}

ResolvedGenericItem::Module(module_id) => {
match module_id {
Expand Down Expand Up @@ -681,11 +684,25 @@ fn resolved_generic_item_def(
declaration.name(db).stable_ptr().untyped()
}

ResolvedGenericItem::GenericType(generic_type) => generic_type.untyped_stable_ptr(db),
ResolvedGenericItem::GenericType(generic_type) => match generic_type {
GenericTypeId::Struct(struct_id) => {
struct_id.stable_ptr(db).lookup(db).name(db).stable_ptr().untyped()
}
GenericTypeId::Enum(enum_id) => {
enum_id.stable_ptr(db).lookup(db).name(db).stable_ptr().untyped()
}
GenericTypeId::Extern(extern_type_id) => {
extern_type_id.stable_ptr(db).lookup(db).name(db).stable_ptr().untyped()
}
},

ResolvedGenericItem::GenericTypeAlias(type_alias) => type_alias.untyped_stable_ptr(db),
ResolvedGenericItem::GenericTypeAlias(type_alias) => {
type_alias.stable_ptr(db).lookup(db).name(db).stable_ptr().untyped()
}

ResolvedGenericItem::GenericImplAlias(impl_alias) => impl_alias.untyped_stable_ptr(db),
ResolvedGenericItem::GenericImplAlias(impl_alias) => {
impl_alias.stable_ptr(db).lookup(db).name(db).stable_ptr().untyped()
}

ResolvedGenericItem::Variant(variant) => {
variant.id.stable_ptr(db).lookup(db).name(db).stable_ptr().untyped()
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/find_references/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ fn enum_name() {
struct Foo {}
}
"#, @r"
<sel=declaration>enum <sel>Foo</sel> {
enum <sel=declaration>Foo</sel> {
Bar,
Baz,
}</sel>
}
fn main() {
let foo = <sel>Foo</sel>::Bar;
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/find_references/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ fn struct_by_name() {
use super::Foo;
}
"#, @r"
<sel=declaration>#[derive(Drop)]
struct <sel>Foo</sel> { field: felt252 }</sel>
#[derive(Drop)]
struct <sel=declaration>Foo</sel> { field: felt252 }
fn main() {
let foo: <sel>Foo</sel> = <sel>Foo</sel> { field: 0 };
}
Expand All @@ -37,8 +37,8 @@ fn struct_member_via_definition() {
let x = foo.width * 2;
}
"#, @r"
<sel=declaration>#[derive(Drop)]
struct <sel>Foo</sel> { width: u64 }</sel>
#[derive(Drop)]
struct <sel=declaration>Foo</sel> { width: u64 }
fn main() {
let foo = <sel>Foo</sel> { width: 0 };
let x = foo.width * 2;
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/goto_definition/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn enum_item_in_type() {
enum Foo { Bar }
fn calc(foo: Fo<caret>o) {}
"#, @r"
<sel>enum Foo { Bar }</sel>
enum <sel>Foo</sel> { Bar }
fn calc(foo: Foo) {}
");
}
Expand All @@ -20,7 +20,7 @@ fn enum_item_in_expr() {
let foo = Fo<caret>o::Bar;
}
"#, @r"
<sel>enum Foo { Bar }</sel>
enum <sel>Foo</sel> { Bar }
fn main() {
let foo = Foo::Bar;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/goto_definition/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn struct_item_in_constructor() {
let foo = Fo<caret>o {};
}
", @r"
<sel>struct Foo { }</sel>
struct <sel>Foo</sel> { }
fn main() {
let foo = Foo {};
}
Expand All @@ -22,7 +22,7 @@ fn struct_item_in_type() {
struct Foo { }
fn calc(foo: Fo<caret>o) {}
", @r"
<sel>struct Foo { }</sel>
struct <sel>Foo</sel> { }
fn calc(foo: Foo) {}
")
}
Expand Down

0 comments on commit 673a287

Please sign in to comment.