on master help sign in
add show_subtree command for viewing tree-sitter subtree in Popup (#1453)
64d3e7bMichael Davis
helix-term/src/commands.rs+33−2
@@ -400,6 +400,7 @@ impl MappableCommand {
400 decrement, "Decrement",
400 decrement, "Decrement",
401 record_macro, "Record macro",
401 record_macro, "Record macro",
402 replay_macro, "Replay macro",
402 replay_macro, "Replay macro",
403+ show_subtree, "Show tree-sitter subtree under primary selection",
403 );
404 );
404}
405}
405
406
@@ -5388,8 +5389,8 @@ fn hover(cx: &mut Context) {
5388 // skip if contents empty
5389 // skip if contents empty
5389
5390
5390 let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
5391 let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
5391− let popup = Popup::new("documentation", contents);
5392+ let popup = Popup::new("hover", contents);
5392− if let Some(doc_popup) = compositor.find_id("documentation") {
5393+ if let Some(doc_popup) = compositor.find_id("hover") {
5393 *doc_popup = popup;
5394 *doc_popup = popup;
5394 } else {
5395 } else {
5395 compositor.push(Box::new(popup));
5396 compositor.push(Box::new(popup));
@@ -6210,3 +6211,33 @@ fn replay_macro(cx: &mut Context) {
6210 },
6211 },
6211 ));
6212 ));
6212}
6213}
6214+
6215+fn show_subtree(cx: &mut Context) {
6216+ let (view, doc) = current!(cx.editor);
6217+
6218+ if let Some(syntax) = doc.syntax() {
6219+ let primary_selection = doc.selection(view.id).primary();
6220+ let text = doc.text();
6221+ let from = text.char_to_byte(primary_selection.from());
6222+ let to = text.char_to_byte(primary_selection.to());
6223+ if let Some(selected_node) = syntax
6224+ .tree()
6225+ .root_node()
6226+ .descendant_for_byte_range(from, to)
6227+ {
6228+ let contents = format!("```tsq\n{}\n```", selected_node.to_sexp());
6229+
6230+ cx.callback = Some(Box::new(
6231+ move |compositor: &mut Compositor, cx: &mut compositor::Context| {
6232+ let contents = ui::Markdown::new(contents, cx.editor.syn_loader.clone());
6233+ let popup = Popup::new("hover", contents);
6234+ if let Some(doc_popup) = compositor.find_id("hover") {
6235+ *doc_popup = popup;
6236+ } else {
6237+ compositor.push(Box::new(popup));
6238+ }
6239+ },
6240+ ));
6241+ }
6242+ }
6243+}
languages.toml+1
@@ -378,6 +378,7 @@ scope = "source.tsq"
378file-types = ["scm"]
378file-types = ["scm"]
379roots = []
379roots = []
380comment-token = ";"
380comment-token = ";"
381+injection-regex = "tsq"
381indent = { tab-width = 2, unit = " " }
382indent = { tab-width = 2, unit = " " }
382
383
383[[language]]
384[[language]]