Skip to content

Commit aa0d0e1

Browse files
GearsDatapackslpil
authored andcommitted
Show record field documentation on hover
1 parent 8b77f04 commit aa0d0e1

5 files changed

+145
-1
lines changed

compiler-core/src/ast/typed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ impl TypedExpr {
786786
match self {
787787
TypedExpr::Var { constructor, .. } => constructor.get_documentation(),
788788
TypedExpr::ModuleSelect { constructor, .. } => constructor.get_documentation(),
789+
TypedExpr::RecordAccess { documentation, .. } => documentation.as_deref(),
789790

790791
TypedExpr::Int { .. }
791792
| TypedExpr::Float { .. }
@@ -804,7 +805,6 @@ impl TypedExpr {
804805
| TypedExpr::Panic { .. }
805806
| TypedExpr::BitArray { .. }
806807
| TypedExpr::RecordUpdate { .. }
807-
| TypedExpr::RecordAccess { .. }
808808
| TypedExpr::NegateBool { .. }
809809
| TypedExpr::NegateInt { .. }
810810
| TypedExpr::Invalid { .. } => None,

compiler-core/src/language_server/tests/hover.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,3 +1750,69 @@ const value = #(1, 2, [Wibble, Wobble(<<1, 2, 3>>), Wibble])
17501750
find_position_of("3")
17511751
);
17521752
}
1753+
1754+
#[test]
1755+
fn record_field_documentation() {
1756+
assert_hover!(
1757+
"
1758+
pub type Wibble {
1759+
Wibble(
1760+
/// This is some documentation about the wibble field.
1761+
wibble: Int
1762+
)
1763+
}
1764+
1765+
pub fn wibble(w: Wibble) {
1766+
w.wibble
1767+
}
1768+
",
1769+
find_position_of("w.wibble").under_char('l')
1770+
);
1771+
}
1772+
1773+
#[test]
1774+
fn no_documentation_for_shared_record_field() {
1775+
assert_hover!(
1776+
"
1777+
pub type Wibble {
1778+
Wibble(
1779+
/// This is some documentation about the wibble field.
1780+
wibble: Int
1781+
)
1782+
Wobble(
1783+
/// This won't show up because we don't know which wibble field it is
1784+
wibble: Int
1785+
)
1786+
}
1787+
1788+
pub fn wibble(w: Wibble) {
1789+
w.wibble
1790+
}
1791+
",
1792+
find_position_of("w.wibble").under_char('l')
1793+
);
1794+
}
1795+
1796+
#[test]
1797+
fn documentation_for_shared_record_field_when_variant_is_known() {
1798+
assert_hover!(
1799+
"
1800+
pub type Wibble {
1801+
Wibble(
1802+
/// This is some documentation about the wibble field.
1803+
wibble: Int
1804+
)
1805+
Wobble(
1806+
/// This won't show up because it's a Wibble variant
1807+
wibble: Int
1808+
)
1809+
}
1810+
1811+
pub fn wibble(w: Wibble) {
1812+
let assert Wibble(..) = w
1813+
w.wibble
1814+
}
1815+
",
1816+
find_position_of("w.wibble").under_char('l')
1817+
);
1818+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
source: compiler-core/src/language_server/tests/hover.rs
3+
expression: "\npub type Wibble {\n Wibble(\n /// This is some documentation about the wibble field.\n wibble: Int\n )\n Wobble(\n /// This won't show up because it's a Wibble variant\n wibble: Int\n )\n}\n\npub fn wibble(w: Wibble) {\n let assert Wibble(..) = w\n w.wibble\n}\n"
4+
---
5+
pub type Wibble {
6+
Wibble(
7+
/// This is some documentation about the wibble field.
8+
wibble: Int
9+
)
10+
Wobble(
11+
/// This won't show up because it's a Wibble variant
12+
wibble: Int
13+
)
14+
}
15+
16+
pub fn wibble(w: Wibble) {
17+
let assert Wibble(..) = w
18+
w.wibble
19+
▔▔▔▔▔▔↑▔
20+
}
21+
22+
23+
----- Hover content -----
24+
Scalar(
25+
String(
26+
"```gleam\nInt\n```\n This is some documentation about the wibble field.\n",
27+
),
28+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
source: compiler-core/src/language_server/tests/hover.rs
3+
expression: "\npub type Wibble {\n Wibble(\n /// This is some documentation about the wibble field.\n wibble: Int\n )\n Wobble(\n /// This won't show up because we don't know which wibble field it is\n wibble: Int\n )\n}\n\npub fn wibble(w: Wibble) {\n w.wibble\n}\n"
4+
---
5+
pub type Wibble {
6+
Wibble(
7+
/// This is some documentation about the wibble field.
8+
wibble: Int
9+
)
10+
Wobble(
11+
/// This won't show up because we don't know which wibble field it is
12+
wibble: Int
13+
)
14+
}
15+
16+
pub fn wibble(w: Wibble) {
17+
w.wibble
18+
▔▔▔▔▔▔↑▔
19+
}
20+
21+
22+
----- Hover content -----
23+
Scalar(
24+
String(
25+
"```gleam\nInt\n```\n",
26+
),
27+
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
source: compiler-core/src/language_server/tests/hover.rs
3+
expression: "\npub type Wibble {\n Wibble(\n /// This is some documentation about the wibble field.\n wibble: Int\n )\n}\n\npub fn wibble(w: Wibble) {\n w.wibble\n}\n"
4+
---
5+
pub type Wibble {
6+
Wibble(
7+
/// This is some documentation about the wibble field.
8+
wibble: Int
9+
)
10+
}
11+
12+
pub fn wibble(w: Wibble) {
13+
w.wibble
14+
▔▔▔▔▔▔↑▔
15+
}
16+
17+
18+
----- Hover content -----
19+
Scalar(
20+
String(
21+
"```gleam\nInt\n```\n This is some documentation about the wibble field.\n",
22+
),
23+
)

0 commit comments

Comments
 (0)