@@ -459,7 +459,10 @@ pub fn read_query(language: &str, filename: &str) -> String {
459459}
460460
461461impl LanguageConfiguration {
462- fn initialize_highlight ( & self , scopes : & [ String ] ) -> Option < Arc < HighlightConfiguration > > {
462+ fn initialize_highlight < T : AsRef < str > > (
463+ & self ,
464+ scopes : & [ T ] ,
465+ ) -> Option < Arc < HighlightConfiguration > > {
463466 let highlights_query = read_query ( & self . language_id , "highlights.scm" ) ;
464467 // always highlight syntax errors
465468 // highlights_query += "\n(ERROR) @error";
@@ -493,13 +496,16 @@ impl LanguageConfiguration {
493496 }
494497 }
495498
496- pub fn reconfigure ( & self , scopes : & [ String ] ) {
499+ pub fn reconfigure ( & self , scopes : & [ & str ] ) {
497500 if let Some ( Some ( config) ) = self . highlight_config . get ( ) {
498501 config. configure ( scopes) ;
499502 }
500503 }
501504
502- pub fn highlight_config ( & self , scopes : & [ String ] ) -> Option < Arc < HighlightConfiguration > > {
505+ pub fn highlight_config < T : AsRef < str > > (
506+ & self ,
507+ scopes : & [ T ] ,
508+ ) -> Option < Arc < HighlightConfiguration > > {
503509 self . highlight_config
504510 . get_or_init ( || self . initialize_highlight ( scopes) )
505511 . clone ( )
@@ -681,16 +687,17 @@ impl Loader {
681687 self . language_configs . iter ( )
682688 }
683689
684- pub fn set_scopes ( & self , scopes : Vec < String > ) {
685- self . scopes . store ( Arc :: new ( scopes) ) ;
690+ pub fn set_scopes ( & self , scopes : & [ & str ] ) {
691+ self . scopes
692+ . store ( Arc :: new ( scopes. iter ( ) . map ( ToString :: to_string) . collect ( ) ) ) ;
686693
687694 // Reconfigure existing grammars
688695 for config in self
689696 . language_configs
690697 . iter ( )
691698 . filter ( |cfg| cfg. is_highlight_initialized ( ) )
692699 {
693- config. reconfigure ( & self . scopes ( ) ) ;
700+ config. reconfigure ( scopes) ;
694701 }
695702 }
696703
@@ -1568,7 +1575,7 @@ impl HighlightConfiguration {
15681575 ///
15691576 /// When highlighting, results are returned as `Highlight` values, which contain the index
15701577 /// of the matched highlight this list of highlight names.
1571- pub fn configure ( & self , recognized_names : & [ String ] ) {
1578+ pub fn configure < T : AsRef < str > > ( & self , recognized_names : & [ T ] ) {
15721579 let mut capture_parts = Vec :: new ( ) ;
15731580 let indices: Vec < _ > = self
15741581 . query
@@ -1584,7 +1591,7 @@ impl HighlightConfiguration {
15841591 let recognized_name = recognized_name;
15851592 let mut len = 0 ;
15861593 let mut matches = true ;
1587- for ( i, part) in recognized_name. split ( '.' ) . enumerate ( ) {
1594+ for ( i, part) in recognized_name. as_ref ( ) . split ( '.' ) . enumerate ( ) {
15881595 match capture_parts. get ( i) {
15891596 Some ( capture_part) if * capture_part == part => len += 1 ,
15901597 _ => {
@@ -2312,7 +2319,7 @@ mod test {
23122319
23132320 #[ test]
23142321 fn test_parser ( ) {
2315- let highlight_names: Vec < String > = [
2322+ let highlight_names: & [ & str ] = & [
23162323 "attribute" ,
23172324 "constant" ,
23182325 "function.builtin" ,
@@ -2331,11 +2338,7 @@ mod test {
23312338 "variable" ,
23322339 "variable.builtin" ,
23332340 "variable.parameter" ,
2334- ]
2335- . iter ( )
2336- . cloned ( )
2337- . map ( String :: from)
2338- . collect ( ) ;
2341+ ] ;
23392342
23402343 let loader = Loader :: new ( Configuration { language : vec ! [ ] } ) ;
23412344
@@ -2349,7 +2352,7 @@ mod test {
23492352 "" , // locals.scm
23502353 )
23512354 . unwrap ( ) ;
2352- config. configure ( & highlight_names) ;
2355+ config. configure ( highlight_names) ;
23532356
23542357 let source = Rope :: from_str (
23552358 "
0 commit comments