@@ -403,7 +403,6 @@ impl MappableCommand {
403403 decrement, "Decrement",
404404 record_macro, "Record macro",
405405 replay_macro, "Replay macro",
406− show_subtree, "Show tree-sitter subtree under primary selection",
407406 );
408407}
409408
@@ -2766,6 +2765,46 @@ pub mod cmd {
27662765 Ok(())
27672766 }
27682767
2768+ fn tree_sitter_subtree(
2769+ cx: &mut compositor::Context,
2770+ _args: &[Cow<str>],
2771+ _event: PromptEvent,
2772+ ) -> anyhow::Result<()> {
2773+ let (view, doc) = current!(cx.editor);
2774+
2775+ if let Some(syntax) = doc.syntax() {
2776+ let primary_selection = doc.selection(view.id).primary();
2777+ let text = doc.text();
2778+ let from = text.char_to_byte(primary_selection.from());
2779+ let to = text.char_to_byte(primary_selection.to());
2780+ if let Some(selected_node) = syntax
2781+ .tree()
2782+ .root_node()
2783+ .descendant_for_byte_range(from, to)
2784+ {
2785+ let contents = format!("```tsq\n{}\n```", selected_node.to_sexp());
2786+
2787+ let callback = async move {
2788+ let call: job::Callback =
2789+ Box::new(move |editor: &mut Editor, compositor: &mut Compositor| {
2790+ let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
2791+ let popup = Popup::new("hover", contents);
2792+ if let Some(doc_popup) = compositor.find_id("hover") {
2793+ *doc_popup = popup;
2794+ } else {
2795+ compositor.push(Box::new(popup));
2796+ }
2797+ });
2798+ Ok(call)
2799+ };
2800+
2801+ cx.jobs.callback(callback);
2802+ }
2803+ }
2804+
2805+ Ok(())
2806+ }
2807+
27692808 pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
27702809 TypableCommand {
27712810 name: "quit",
@@ -3082,6 +3121,13 @@ pub mod cmd {
30823121 fun: sort_reverse,
30833122 completer: None,
30843123 },
3124+ TypableCommand {
3125+ name: "tree-sitter-subtree",
3126+ aliases: &["ts-subtree"],
3127+ doc: "Display tree sitter subtree under cursor, primarily for debugging queries.",
3128+ fun: tree_sitter_subtree,
3129+ completer: None,
3130+ },
30853131 ];
30863132
30873133 pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableCommand>> =
@@ -6252,33 +6298,3 @@ fn replay_macro(cx: &mut Context) {
62526298 },
62536299 ));
62546300}
6255−
6256−fn show_subtree(cx: &mut Context) {
6257− let (view, doc) = current!(cx.editor);
6258−
6259− if let Some(syntax) = doc.syntax() {
6260− let primary_selection = doc.selection(view.id).primary();
6261− let text = doc.text();
6262− let from = text.char_to_byte(primary_selection.from());
6263− let to = text.char_to_byte(primary_selection.to());
6264− if let Some(selected_node) = syntax
6265− .tree()
6266− .root_node()
6267− .descendant_for_byte_range(from, to)
6268− {
6269− let contents = format!("```tsq\n{}\n```", selected_node.to_sexp());
6270−
6271− cx.callback = Some(Box::new(
6272− move |compositor: &mut Compositor, cx: &mut compositor::Context| {
6273− let contents = ui::Markdown::new(contents, cx.editor.syn_loader.clone());
6274− let popup = Popup::new("hover", contents);
6275− if let Some(doc_popup) = compositor.find_id("hover") {
6276− *doc_popup = popup;
6277− } else {
6278− compositor.push(Box::new(popup));
6279− }
6280− },
6281− ));
6282− }
6283− }
6284−}