@@ -648,74 +648,51 @@ fn tree_highlights(
648648 src : & str ,
649649 config : & TreeSitterConfig ,
650650) -> HighlightedNodeIds {
651- let mut keyword_ish_capture_ids = vec ! [ ] ;
652- // TODO: Use config.highlight_query.capture_names() to find all
653- // the keyword.foo captures.
654- if let Some ( idx) = config. highlight_query . capture_index_for_name ( "keyword" ) {
655- keyword_ish_capture_ids. push ( idx) ;
656- }
657- if let Some ( idx) = config
658- . highlight_query
659- . capture_index_for_name ( "keyword.function" )
660- {
661- keyword_ish_capture_ids. push ( idx) ;
662- }
663- if let Some ( idx) = config
664- . highlight_query
665- . capture_index_for_name ( "keyword.operator" )
666- {
667- keyword_ish_capture_ids. push ( idx) ;
668- }
669- if let Some ( idx) = config
670- . highlight_query
671- . capture_index_for_name ( "keyword.return" )
672- {
673- keyword_ish_capture_ids. push ( idx) ;
674- }
675- if let Some ( idx) = config. highlight_query . capture_index_for_name ( "operator" ) {
676- keyword_ish_capture_ids. push ( idx) ;
677- }
678- if let Some ( idx) = config. highlight_query . capture_index_for_name ( "repeat" ) {
679- keyword_ish_capture_ids. push ( idx) ;
680- }
681- if let Some ( idx) = config. highlight_query . capture_index_for_name ( "constant" ) {
682- keyword_ish_capture_ids. push ( idx) ;
683- }
684- if let Some ( idx) = config. highlight_query . capture_index_for_name ( "boolean" ) {
685- keyword_ish_capture_ids. push ( idx) ;
686- }
687- if let Some ( idx) = config
688- . highlight_query
689- . capture_index_for_name ( "constant.builtin" )
690- {
691- keyword_ish_capture_ids. push ( idx) ;
692- }
693-
651+ let mut keyword_ish_capture_ids: Vec < u32 > = vec ! [ ] ;
694652 let mut string_capture_ids = vec ! [ ] ;
695- if let Some ( idx) = config. highlight_query . capture_index_for_name ( "string" ) {
696- string_capture_ids. push ( idx) ;
697- }
698- if let Some ( idx) = config. highlight_query . capture_index_for_name ( "character" ) {
699- string_capture_ids. push ( idx) ;
700- }
701-
702653 let mut type_capture_ids = vec ! [ ] ;
703- if let Some ( idx) = config. highlight_query . capture_index_for_name ( "type" ) {
704- type_capture_ids. push ( idx) ;
705- }
706- if let Some ( idx) = config
707- . highlight_query
708- . capture_index_for_name ( "type.builtin" )
709- {
710- type_capture_ids. push ( idx) ;
711- }
712- if let Some ( idx) = config. highlight_query . capture_index_for_name ( "label" ) {
654+
655+ // Query names are often written with namespacing, so
656+ // highlights.scm might contain @constant or the more specific
657+ // @constant.builtin.
658+ //
659+ // We support e.g. arbitrary @constant.foo so we get the benefit
660+ // of all the relevant highlighting queries.
661+ let cn = config. highlight_query . capture_names ( ) ;
662+ for ( idx, name) in cn. iter ( ) . enumerate ( ) {
663+ if name == "type"
664+ || name. starts_with ( "type." )
665+ || name. starts_with ( "storage.type." )
666+ || name. starts_with ( "keyword.type." )
667+ || name == "tag"
668+ {
669+ // TODO: this doesn't capture (type_ref) in Elm as that
670+ // applies to the parent node.
671+ type_capture_ids. push ( idx as u32 ) ;
672+ } else if name == "keyword"
673+ || name. starts_with ( "keyword." )
674+ || name == "constant"
675+ || name. starts_with ( "constant." )
676+ || name == "operator"
677+ || name == "repeat"
678+ || name == "boolean"
679+ {
680+ keyword_ish_capture_ids. push ( idx as u32 ) ;
681+ }
682+
683+ if name == "string"
684+ || name. starts_with ( "string." )
685+ || name == "character"
686+ || name. starts_with ( "character." )
687+ {
688+ string_capture_ids. push ( idx as u32 ) ;
689+ }
690+
713691 // Rust uses 'label' for lifetimes, and highglighting
714692 // lifetimes consistently with types seems reasonable.
715- type_capture_ids. push ( idx) ;
716- }
717- if let Some ( idx) = config. highlight_query . capture_index_for_name ( "tag" ) {
718- type_capture_ids. push ( idx) ;
693+ if name == "label" {
694+ type_capture_ids. push ( idx as u32 ) ;
695+ }
719696 }
720697
721698 let mut qc = ts:: QueryCursor :: new ( ) ;
0 commit comments