Skip to content

Commit

Permalink
LS: Fix hover on definition
Browse files Browse the repository at this point in the history
commit-id:7654b189
  • Loading branch information
Draggu committed Aug 21, 2024
1 parent 3be4896 commit ca54664
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 24 deletions.
14 changes: 13 additions & 1 deletion crates/cairo-lang-language-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -995,6 +995,18 @@ fn find_definition(
return Some((ResolvedItem::Concrete(item), stable_ptr));
}
}

for lookup_item_id in lookup_items.iter().copied() {
if let LookupItemId::ModuleItem(item) = lookup_item_id {
let item = ResolvedGenericItem::from_module_item(db, item).to_option()?;

return Some((
ResolvedItem::Generic(item.clone()),
resolved_generic_item_def(db, item)?,
));
}
}

None
}

Expand Down
102 changes: 85 additions & 17 deletions crates/cairo-lang-language-server/tests/test_data/hover/basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,14 @@ pub mod front_of_house {
// = source context
let mut x<caret> = 5;
// = highlight
No highlight information.
let mut <sel>x</sel> = 5;
// = popover
Type: `core::integer::u32`
```cairo
hello
```
```cairo
fn main()
```

//! > hover #1
// = source context
Expand Down Expand Up @@ -202,9 +207,14 @@ Add to waitlist function.
// = source context
let mut re<caret>ct = Rectangle { width: 30, height: 50 };
// = highlight
No highlight information.
let mut <sel>rect</sel> = Rectangle { width: 30, height: 50 };
// = popover
Type: `hello::Rectangle`
```cairo
hello
```
```cairo
fn main()
```

//! > hover #10
// = source context
Expand All @@ -230,19 +240,27 @@ Rectangle struct.
// = source context
let mut rect = Rectangle { wid<caret>th: 30, height: 50 };
// = highlight
No highlight information.
let mut rect = Rectangle { <sel>width</sel>: 30, height: 50 };
// = popover
```cairo
hello::Rectangle
hello
```
```cairo
fn main()
```

//! > hover #12
// = source context
let ar<caret>ea = rect.area();
// = highlight
No highlight information.
let <sel>area</sel> = rect.area();
// = popover
Type: `core::integer::u64`
```cairo
hello
```
```cairo
fn main()
```

//! > hover #13
// = source context
Expand All @@ -264,15 +282,31 @@ Calculate the area of the rectangle.
// = source context
fn add_t<caret>wo(x: u32) -> u32 { x + 2 }
// = highlight
No highlight information.
fn <sel>add_two</sel>(x: u32) -> u32 { x + 2 }
// = popover
```cairo
hello
```
```cairo
fn add_two(x: u32) -> u32
```
---
`add_two` documentation.

//! > hover #15
// = source context
fn area(sel<caret>f: @Rectangle) -> u64;
// = highlight
No highlight information.
fn area(<sel>self</sel>: @Rectangle) -> u64;
// = popover
```cairo
hello
```
```cairo
trait RectangleTrait
```
---
Rectangle trait.

//! > hover #16
// = source context
Expand All @@ -298,8 +332,16 @@ Rectangle struct.
// = source context
fn area(se<caret>lf: @Rectangle) -> u64 {
// = highlight
No highlight information.
fn area(<sel>self</sel>: @Rectangle) -> u64 {
// = popover
```cairo
hello
```
```cairo
impl RectangleImpl of RectangleTrait
```
---
Implementing the `RectangleTrait` for the `Rectangle` struct.

//! > hover #18
// = source context
Expand Down Expand Up @@ -445,31 +487,57 @@ Width of the rectangle.
// = source context
enum Co<caret>in {
// = highlight
No highlight information.
enum <sel>Coin</sel> {
// = popover
No hover information.
```cairo
hello
```
```cairo
enum Coin {
Penny,
}
```

//! > hover #27
// = source context
Pen<caret>ny,
// = highlight
No highlight information.
<sel>Penny</sel>,
// = popover
No hover information.
```cairo
hello
```
```cairo
enum Coin {
Penny,
}
```

//! > hover #28
// = source context
fn value_i<caret>n_cents(coin: Coin) -> felt252 {
// = highlight
No highlight information.
fn <sel>value_in_cents</sel>(coin: Coin) -> felt252 {
// = popover
```cairo
hello
```
```cairo
fn value_in_cents(coin: Coin) -> felt252
```

//! > hover #29
// = source context
fn value_in_cents(co<caret>in: Coin) -> felt252 {
// = highlight
No highlight information.
fn value_in_cents(<sel>coin</sel>: Coin) -> felt252 {
// = popover
```cairo
hello
```
```cairo
fn value_in_cents(coin: Coin) -> felt252
```

//! > hover #30
// = source context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,26 @@ fn f(ab<caret>c) -> felt252 {
// = source context
let mut xy<caret>z = unknown_function();
// = highlight
No highlight information.
let mut <sel>xyz</sel> = unknown_function();
// = popover
Type: `<missing>`
```cairo
hello
```
```cairo
fn main()
```

//! > hover #1
// = source context
let mut xyz = unkn<caret>own_function();
// = highlight
No highlight information.
let mut xyz = <sel>unknown_function</sel>();
// = popover
```cairo
<missing>
hello
```
```cairo
fn main()
```

//! > hover #2
Expand All @@ -52,8 +60,14 @@ let mut xyz: <missing>
// = source context
fn f(ab<caret>c) -> felt252 {
// = highlight
No highlight information.
fn f(<sel>abc</sel>) -> felt252 {
// = popover
```cairo
hello
```
```cairo
fn f(abc) -> felt252
```

//! > hover #4
// = source context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,14 @@ pub fn contract_state_for_testing() -> ContractState
// = source context
fn constructor(ref se<caret>lf: ContractState, value_: u128) {
// = highlight
No highlight information.
fn constructor(ref <sel>self</sel>: ContractState, value_: u128) {
// = popover
```cairo
hello::Balance
```
```cairo
fn constructor(ref self: ContractState, value_: u128)
```

//! > hover #2
// = source context
Expand Down

0 comments on commit ca54664

Please sign in to comment.