diff --git a/crates/cairo-lang-language-server/src/lib.rs b/crates/cairo-lang-language-server/src/lib.rs index c083aa40101..e9418672cc1 100644 --- a/crates/cairo-lang-language-server/src/lib.rs +++ b/crates/cairo-lang-language-server/src/lib.rs @@ -52,7 +52,7 @@ use cairo_lang_defs::db::DefsGroup; use cairo_lang_defs::ids::{ FunctionTitleId, LanguageElementId, LookupItemId, MemberId, ModuleId, SubmoduleLongId, }; -use cairo_lang_diagnostics::Diagnostics; +use cairo_lang_diagnostics::{Diagnostics, ToOption}; use cairo_lang_filesystem::db::{ get_originating_location, AsFilesGroupMut, FilesGroup, FilesGroupEx, PrivRawFileContentQuery, }; @@ -995,6 +995,23 @@ fn find_definition( return Some((ResolvedItem::Concrete(item), stable_ptr)); } } + + for lookup_item_id in lookup_items.iter().rev().copied() { + if let LookupItemId::ModuleItem(item) = lookup_item_id { + let item = ResolvedGenericItem::from_module_item(db, item).to_option()?; + + if db + .first_ancestor_of_kind(identifier.as_syntax_node(), SyntaxKind::StatementLet) + .is_none() + { + return Some(( + ResolvedItem::Generic(item.clone()), + resolved_generic_item_def(db, item)?, + )); + } + } + } + None } diff --git a/crates/cairo-lang-language-server/tests/test_data/hover/basic.txt b/crates/cairo-lang-language-server/tests/test_data/hover/basic.txt index 420fca4957f..4a5ecc66943 100644 --- a/crates/cairo-lang-language-server/tests/test_data/hover/basic.txt +++ b/crates/cairo-lang-language-server/tests/test_data/hover/basic.txt @@ -264,15 +264,31 @@ Calculate the area of the rectangle. // = source context fn add_two(x: u32) -> u32 { x + 2 } // = highlight -No highlight information. +fn add_two(x: u32) -> u32 { x + 2 } // = popover +```cairo +hello +``` +```cairo +fn add_two(x: u32) -> u32 +``` +--- +`add_two` documentation. //! > hover #15 // = source context fn area(self: @Rectangle) -> u64; // = highlight -No highlight information. + fn area(self: @Rectangle) -> u64; // = popover +```cairo +hello +``` +```cairo +trait RectangleTrait +``` +--- +Rectangle trait. //! > hover #16 // = source context @@ -298,8 +314,16 @@ Rectangle struct. // = source context fn area(self: @Rectangle) -> u64 { // = highlight -No highlight information. + fn area(self: @Rectangle) -> u64 { // = popover +```cairo +hello +``` +```cairo +impl RectangleImpl of RectangleTrait +``` +--- +Implementing the `RectangleTrait` for the `Rectangle` struct. //! > hover #18 // = source context @@ -445,31 +469,57 @@ Width of the rectangle. // = source context enum Coin { // = highlight -No highlight information. +enum Coin { // = popover -No hover information. +```cairo +hello +``` +```cairo +enum Coin { + Penny, +} +``` //! > hover #27 // = source context Penny, // = highlight -No highlight information. + Penny, // = popover -No hover information. +```cairo +hello +``` +```cairo +enum Coin { + Penny, +} +``` //! > hover #28 // = source context fn value_in_cents(coin: Coin) -> felt252 { // = highlight -No highlight information. +fn value_in_cents(coin: Coin) -> felt252 { // = popover +```cairo +hello +``` +```cairo +fn value_in_cents(coin: Coin) -> felt252 +``` //! > hover #29 // = source context fn value_in_cents(coin: Coin) -> felt252 { // = highlight -No highlight information. +fn value_in_cents(coin: Coin) -> felt252 { // = popover +```cairo +hello +``` +```cairo +fn value_in_cents(coin: Coin) -> felt252 +``` //! > hover #30 // = source context diff --git a/crates/cairo-lang-language-server/tests/test_data/hover/partial.txt b/crates/cairo-lang-language-server/tests/test_data/hover/partial.txt index eab227148d2..c543e7abe63 100644 --- a/crates/cairo-lang-language-server/tests/test_data/hover/partial.txt +++ b/crates/cairo-lang-language-server/tests/test_data/hover/partial.txt @@ -52,8 +52,14 @@ let mut xyz: // = source context fn f(abc) -> felt252 { // = highlight -No highlight information. +fn f(abc) -> felt252 { // = popover +```cairo +hello +``` +```cairo +fn f(abc) -> felt252 +``` //! > hover #4 // = source context diff --git a/crates/cairo-lang-language-server/tests/test_data/hover/starknet.txt b/crates/cairo-lang-language-server/tests/test_data/hover/starknet.txt index 06d9b2cd2b9..fbcc0629610 100644 --- a/crates/cairo-lang-language-server/tests/test_data/hover/starknet.txt +++ b/crates/cairo-lang-language-server/tests/test_data/hover/starknet.txt @@ -66,8 +66,14 @@ pub fn contract_state_for_testing() -> ContractState // = source context fn constructor(ref self: ContractState, value_: u128) { // = highlight -No highlight information. + fn constructor(ref self: ContractState, value_: u128) { // = popover +```cairo +hello::Balance +``` +```cairo +fn constructor(ref self: ContractState, value_: u128) +``` //! > hover #2 // = source context