@@ -752,7 +752,7 @@ impl Syntax {
753 let mut injections = Vec::new();
753 let mut injections = Vec::new();
754 for mat in matches {
754 for mat in matches {
755− let (language_name, content_node, include_children) = injection_for_match(
755+ let (language_name, content_node, included_children) = injection_for_match(
756 &layer.config,
756 &layer.config,
757 &layer.config.injections_query,
757 &layer.config.injections_query,
@@ -769,7 +769,7 @@ impl Syntax {
770 if let Some(config) = (injection_callback)(&language_name) {
770 if let Some(config) = (injection_callback)(&language_name) {
771 let ranges =
771 let ranges =
772− intersect_ranges(&layer.ranges, &[content_node], include_children);
772+ intersect_ranges(&layer.ranges, &[content_node], included_children);
774 if !ranges.is_empty() {
774 if !ranges.is_empty() {
775 injections.push((config, ranges));
775 injections.push((config, ranges));
@@ -781,7 +781,10 @@ impl Syntax {
781 // Process combined injections.
781 // Process combined injections.
782 if let Some(combined_injections_query) = &layer.config.combined_injections_query {
782 if let Some(combined_injections_query) = &layer.config.combined_injections_query {
783 let mut injections_by_pattern_index =
783 let mut injections_by_pattern_index =
785+ (None, Vec::new(), IncludedChildren::default());
784− vec![(None, Vec::new(), false); combined_injections_query.pattern_count()];
786+ combined_injections_query.pattern_count()
785 let matches = cursor.matches(
788 let matches = cursor.matches(
786 combined_injections_query,
789 combined_injections_query,
787 layer.tree().root_node(),
790 layer.tree().root_node(),
@@ -789,7 +792,7 @@ impl Syntax {
790 for mat in matches {
793 for mat in matches {
791 let entry = &mut injections_by_pattern_index[mat.pattern_index];
794 let entry = &mut injections_by_pattern_index[mat.pattern_index];
792− let (language_name, content_node, include_children) = injection_for_match(
795+ let (language_name, content_node, included_children) = injection_for_match(
793 &layer.config,
796 &layer.config,
794 combined_injections_query,
797 combined_injections_query,
@@ -801,16 +804,16 @@ impl Syntax {
801 if let Some(content_node) = content_node {
804 if let Some(content_node) = content_node {
802 entry.1.push(content_node);
805 entry.1.push(content_node);
804− entry.2 = include_children;
807+ entry.2 = included_children;
806− for (lang_name, content_nodes, includes_children) in injections_by_pattern_index
809+ for (lang_name, content_nodes, included_children) in injections_by_pattern_index
808 if let (Some(lang_name), false) = (lang_name, content_nodes.is_empty()) {
811 if let (Some(lang_name), false) = (lang_name, content_nodes.is_empty()) {
809 if let Some(config) = (injection_callback)(&lang_name) {
812 if let Some(config) = (injection_callback)(&lang_name) {
810 let ranges = intersect_ranges(
813 let ranges = intersect_ranges(
811 &layer.ranges,
814 &layer.ranges,
812 &content_nodes,
815 &content_nodes,
813− includes_children,
816+ included_children,
815 if !ranges.is_empty() {
818 if !ranges.is_empty() {
816 injections.push((config, ranges));
819 injections.push((config, ranges));
@@ -1408,6 +1411,19 @@ impl<'a> HighlightIterLayer<'a> {
1415+enum IncludedChildren {
1421+impl Default for IncludedChildren {
1422+ fn default() -> Self {
1411// Compute the ranges that should be included when parsing an injection.
1427// Compute the ranges that should be included when parsing an injection.
1412// This takes into account three things:
1428// This takes into account three things:
1413// * `parent_ranges` - The ranges must all fall within the *current* layer's ranges.
1429// * `parent_ranges` - The ranges must all fall within the *current* layer's ranges.
@@ -1420,7 +1436,7 @@ impl<'a> HighlightIterLayer<'a> {
1420fn intersect_ranges(
1436fn intersect_ranges(
1421 parent_ranges: &[Range],
1437 parent_ranges: &[Range],
1422 nodes: &[Node],
1438 nodes: &[Node],
1423− includes_children: bool,
1439+ included_children: IncludedChildren,
1424) -> Vec<Range> {
1440) -> Vec<Range> {
1425 let mut cursor = nodes[0].walk();
1441 let mut cursor = nodes[0].walk();
1426 let mut result = Vec::new();
1442 let mut result = Vec::new();
@@ -1444,11 +1460,15 @@ fn intersect_ranges(
1445 for excluded_range in node
1461 for excluded_range in node
1446 .children(&mut cursor)
1462 .children(&mut cursor)
1447− .filter_map(|child| {
1463+ .filter_map(|child| match included_children {
1448− if includes_children {
1464+ IncludedChildren::None => Some(child.range()),
1449− None
1465+ IncludedChildren::All => None,
1466+ IncludedChildren::Unnamed => {
1467+ if child.is_named() {
1468+ Some(child.range())
1450− } else {
1469+ } else {
1451− Some(child.range())
1470+ None
1454 .chain([following_range].iter().cloned())
1474 .chain([following_range].iter().cloned())
@@ -1777,7 +1797,7 @@ fn injection_for_match<'a>(
1777 query: &'a Query,
1797 query: &'a Query,
1778 query_match: &QueryMatch<'a, 'a>,
1798 query_match: &QueryMatch<'a, 'a>,
1779 source: RopeSlice<'a>,
1799 source: RopeSlice<'a>,
1780−) -> (Option<Cow<'a, str>>, Option<Node<'a>>, bool) {
1800+) -> (Option<Cow<'a, str>>, Option<Node<'a>>, IncludedChildren) {
1781 let content_capture_index = config.injection_content_capture_index;
1801 let content_capture_index = config.injection_content_capture_index;
1782 let language_capture_index = config.injection_language_capture_index;
1802 let language_capture_index = config.injection_language_capture_index;
@@ -1793,7 +1813,7 @@ fn injection_for_match<'a>(
1796− let mut include_children = false;
1816+ let mut included_children = IncludedChildren::default();
1797 for prop in query.property_settings(query_match.pattern_index) {
1817 for prop in query.property_settings(query_match.pattern_index) {
1798 match prop.key.as_ref() {
1818 match prop.key.as_ref() {
1799 // In addition to specifying the language name via the text of a
1819 // In addition to specifying the language name via the text of a
@@ -1809,12 +1829,17 @@ fn injection_for_match<'a>(
1809 // `injection.content` node - only the ranges that belong to the
1829 // `injection.content` node - only the ranges that belong to the
1810 // node itself. This can be changed using a `#set!` predicate that
1830 // node itself. This can be changed using a `#set!` predicate that
1811 // sets the `injection.include-children` key.
1831 // sets the `injection.include-children` key.
1812− "injection.include-children" => include_children = true,
1832+ "injection.include-children" => included_children = IncludedChildren::All,
1834+ // Some queries might only exclude named children but include unnamed
1835+ // children in their `injection.content` node. This can be enabled using
1836+ // a `#set!` predicate that sets the `injection.include-unnamed-children` key.
1837+ "injection.include-unnamed-children" => included_children = IncludedChildren::Unnamed,
1817− (language_name, content_node, include_children)
1842+ (language_name, content_node, included_children)
1820pub struct Merge<I> {
1845pub struct Merge<I> {