@@ -1527,6 +1527,84 @@ fn tree_sitter_scopes(
1530+fn tree_sitter_highlight_name(
1531+ cx: &mut compositor::Context,
1532+ _args: &[Cow<str>],
1533+ event: PromptEvent,
1534+) -> anyhow::Result<()> {
1535+ fn find_highlight_at_cursor(
1536+ cx: &mut compositor::Context<'_>,
1537+ ) -> Option<helix_core::syntax::Highlight> {
1538+ use helix_core::syntax::HighlightEvent;
1540+ let (view, doc) = current!(cx.editor);
1541+ let syntax = doc.syntax()?;
1542+ let text = doc.text().slice(..);
1543+ let cursor = doc.selection(view.id).primary().cursor(text);
1544+ let byte = text.char_to_byte(cursor);
1548+ .descendant_for_byte_range(byte, byte)?;
1549+ // Query the same range as the one used in syntax highlighting.
1551+ // Calculate viewport byte ranges:
1552+ let row = text.char_to_line(view.offset.anchor.min(text.len_chars()));
1553+ // Saturating subs to make it inclusive zero indexing.
1554+ let last_line = text.len_lines().saturating_sub(1);
1555+ let height = view.inner_area(doc).height;
1556+ let last_visible_line = (row + height as usize).saturating_sub(1).min(last_line);
1557+ let start = text.line_to_byte(row.min(last_line));
1558+ let end = text.line_to_byte(last_visible_line + 1);
1563+ let mut highlight = None;
1565+ for event in syntax.highlight_iter(text, Some(range), None) {
1566+ match event.unwrap() {
1567+ HighlightEvent::Source { start, end }
1568+ if start == node.start_byte() && end == node.end_byte() =>
1572+ HighlightEvent::HighlightStart(hl) => {
1573+ highlight = Some(hl);
1582+ if event != PromptEvent::Validate {
1586+ let Some(highlight) = find_highlight_at_cursor(cx) else {
1590+ let content = cx.editor.theme.scope(highlight.0).to_string();
1592+ let callback = async move {
1593+ let call: job::Callback = Callback::EditorCompositor(Box::new(
1594+ move |editor: &mut Editor, compositor: &mut Compositor| {
1595+ let content = ui::Markdown::new(content, editor.syn_loader.clone());
1596+ let popup = Popup::new("hover", content).auto_close(true);
1597+ compositor.replace_or_push("hover", popup);
1603+ cx.jobs.callback(callback);
1530fn vsplit(
1608fn vsplit(
1531 cx: &mut compositor::Context,
1609 cx: &mut compositor::Context,
1532 args: &[Cow<str>],
1610 args: &[Cow<str>],
@@ -2703,6 +2781,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
2703 fun: tree_sitter_scopes,
2781 fun: tree_sitter_scopes,
2704 signature: CommandSignature::none(),
2782 signature: CommandSignature::none(),
2785+ name: "tree-sitter-highlight-name",
2787+ doc: "Display name of tree-sitter highlight scope under the cursor.",
2788+ fun: tree_sitter_highlight_name,
2789+ signature: CommandSignature::none(),
2706 TypableCommand {
2791 TypableCommand {
2707 name: "debug-start",
2792 name: "debug-start",
2708 aliases: &["dbg"],
2793 aliases: &["dbg"],