summaryrefslogtreecommitdiff
path: root/src/ide
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-12-14 10:10:07 +0100
committerLaurenz <laurmaedje@gmail.com>2022-12-14 10:10:07 +0100
commit0c7fb7d30fb92cbb047fd096588959971ba32611 (patch)
tree9d4342e055a0d2ed406da356eaa83c6efbd4945c /src/ide
parent9ba4d2c134479aad876a0e2ac4cd1622a353109e (diff)
Hover tooltips
Diffstat (limited to 'src/ide')
-rw-r--r--src/ide/mod.rs2
-rw-r--r--src/ide/tooltip.rs19
2 files changed, 21 insertions, 0 deletions
diff --git a/src/ide/mod.rs b/src/ide/mod.rs
index a4b1cba5..a4427983 100644
--- a/src/ide/mod.rs
+++ b/src/ide/mod.rs
@@ -1,5 +1,7 @@
//! Capabilities for IDE support.
mod highlight;
+mod tooltip;
pub use highlight::*;
+pub use tooltip::*;
diff --git a/src/ide/tooltip.rs b/src/ide/tooltip.rs
new file mode 100644
index 00000000..df193cb2
--- /dev/null
+++ b/src/ide/tooltip.rs
@@ -0,0 +1,19 @@
+use crate::model::Value;
+use crate::syntax::{LinkedNode, Source, SyntaxKind};
+use crate::World;
+
+/// Produce a tooltip which can be shown when a cursor position is hovered.
+pub fn tooltip(world: &dyn World, source: &Source, cursor: usize) -> Option<String> {
+ let leaf = LinkedNode::new(source.root()).leaf_at(cursor)?;
+
+ // If a known identifier is under the cursor, provide its documentation.
+ if let SyntaxKind::Ident(ident) = leaf.kind() {
+ if let Some(value) = world.library().scope.get(ident) {
+ if let Value::Func(func) = value {
+ return func.doc().map(Into::into);
+ }
+ }
+ }
+
+ None
+}