Skip to content

Commit 84252c3

Browse files
committed
feat: Add hover docs for builtin types
1 parent 372ef8d commit 84252c3

6 files changed

+19
-22
lines changed

src/nodekind.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pub enum NodeKind {
88
Message,
99
EnumName,
1010
FieldName,
11-
FieldBuiltinTypeName,
1211
ServiceName,
1312
RpcName,
1413
PackageName,
@@ -24,7 +23,6 @@ impl NodeKind {
2423
NodeKind::Message => "message",
2524
NodeKind::EnumName => "enum_name",
2625
NodeKind::FieldName => "message_or_enum_type",
27-
NodeKind::FieldBuiltinTypeName => "type",
2826
NodeKind::ServiceName => "service_name",
2927
NodeKind::RpcName => "rpc_name",
3028
NodeKind::PackageName => "full_ident",
@@ -59,10 +57,6 @@ impl NodeKind {
5957
n.kind() == Self::FieldName.as_str()
6058
}
6159

62-
pub fn is_builtin_field_type(n: &Node) -> bool {
63-
n.kind() == Self::FieldBuiltinTypeName.as_str()
64-
}
65-
6660
pub fn is_userdefined(n: &Node) -> bool {
6761
n.kind() == Self::EnumName.as_str() || n.kind() == Self::MessageName.as_str()
6862
}

src/parser/tree.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ impl ParsedTree {
6363
.map(|n| n.utf8_text(content.as_ref()).expect("utf-8 parse error"))
6464
}
6565

66-
pub fn get_hoverable_node_text_at_position<'a>(&'a self, pos:&Position, content: &'a [u8]) -> Option<&'a str> {
67-
if let Some(n) = self.get_node_at_position(pos) {
68-
if NodeKind::is_builtin_field_type(&n) {
69-
return Some(n.utf8_text(content).expect("utf8-parse error"))
70-
}
71-
}
66+
pub fn get_hoverable_node_text_at_position<'a>(
67+
&'a self,
68+
pos: &Position,
69+
content: &'a [u8],
70+
) -> Option<&'a str> {
71+
let n = self.get_node_at_position(pos)?;
7272
self.get_actionable_node_text_at_position(pos, content)
73+
.or(Some(n.kind()))
7374
}
7475

7576
pub fn get_ancestor_nodes_at_position<'a>(&'a self, pos: &Position) -> Vec<Node<'a>> {
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
source: src/workspace/hover.rs
3-
expression: "state.hover(\"com.library\", \"Author.Address\")"
3+
expression: "state.hover(\"com.workspace\", \"int64\")"
4+
snapshot_kind: text
45
---
5-
- Address is a Address
6+
- "A 64-bit integer (varint encoding)\n\nValues of this type range between `-9223372036854775808` and `9223372036854775807`.\nBeware that negative values are encoded as ten bytes on the wire!"

src/workspace/snapshots/protols__workspace__hover__test__workspace_test_hover-2.snap.new

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
source: src/workspace/hover.rs
3-
expression: "state.hover(\"com.library\", \"com.utility.Foobar.Baz\")"
3+
expression: "state.hover(\"com.workspace\", \"Author.Address\")"
4+
snapshot_kind: text
45
---
5-
- What is baz?
6+
- Address is a Address
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
source: src/workspace/hover.rs
3+
expression: "state.hover(\"com.utility\", \"Baz\")"
4+
snapshot_kind: text
5+
---
6+
- What is baz?

0 commit comments

Comments
 (0)