@ -361,14 +361,12 @@ pub fn read_query(language: &str, filename: &str) -> String {
impl LanguageConfiguration {
impl LanguageConfiguration {
fn initialize_highlight ( & self , scopes : & [ String ] ) -> Option < Arc < HighlightConfiguration > > {
fn initialize_highlight ( & self , scopes : & [ String ] ) -> Option < Arc < HighlightConfiguration > > {
let language = self . language_id . to_ascii_lowercase ( ) ;
let highlights_query = read_query ( & self . language_id , "highlights.scm" ) ;
let highlights_query = read_query ( & language , "highlights.scm" ) ;
// always highlight syntax errors
// always highlight syntax errors
// highlights_query += "\n(ERROR) @error";
// highlights_query += "\n(ERROR) @error";
let injections_query = read_query ( & language , "injections.scm" ) ;
let injections_query = read_query ( & self . language _id , "injections.scm" ) ;
let locals_query = read_query ( & language , "locals.scm" ) ;
let locals_query = read_query ( & self . language _id , "locals.scm" ) ;
if highlights_query . is_empty ( ) {
if highlights_query . is_empty ( ) {
None
None
@ -432,14 +430,20 @@ impl LanguageConfiguration {
}
}
fn load_query ( & self , kind : & str ) -> Option < Query > {
fn load_query ( & self , kind : & str ) -> Option < Query > {
let lang_name = self . language_id . to_ascii_lowercase ( ) ;
let query_text = read_query ( & self . language_id , kind ) ;
let query_text = read_query ( & lang_name , kind ) ;
if query_text . is_empty ( ) {
if query_text . is_empty ( ) {
return None ;
return None ;
}
}
let lang = self . highlight_config . get ( ) ? . as_ref ( ) ? . language ;
let lang = self . highlight_config . get ( ) ? . as_ref ( ) ? . language ;
Query ::new ( lang , & query_text )
Query ::new ( lang , & query_text )
. map_err ( | e | log ::error ! ( "Failed to parse {} queries for {}: {}" , kind , lang_name , e ) )
. map_err ( | e | {
log ::error ! (
"Failed to parse {} queries for {}: {}" ,
kind ,
self . language_id ,
e
)
} )
. ok ( )
. ok ( )
}
}
}
}
@ -2119,7 +2123,7 @@ mod test {
) ;
) ;
let loader = Loader ::new ( Configuration { language : vec ! [ ] } ) ;
let loader = Loader ::new ( Configuration { language : vec ! [ ] } ) ;
let language = get_language ( " R ust") . unwrap ( ) ;
let language = get_language ( " r ust") . unwrap ( ) ;
let query = Query ::new ( language , query_str ) . unwrap ( ) ;
let query = Query ::new ( language , query_str ) . unwrap ( ) ;
let textobject = TextObjectQuery { query } ;
let textobject = TextObjectQuery { query } ;
@ -2179,7 +2183,7 @@ mod test {
let loader = Loader ::new ( Configuration { language : vec ! [ ] } ) ;
let loader = Loader ::new ( Configuration { language : vec ! [ ] } ) ;
let language = get_language ( " R ust") . unwrap ( ) ;
let language = get_language ( " r ust") . unwrap ( ) ;
let config = HighlightConfiguration ::new (
let config = HighlightConfiguration ::new (
language ,
language ,
& std ::fs ::read_to_string ( "../runtime/grammars/sources/rust/queries/highlights.scm" )
& std ::fs ::read_to_string ( "../runtime/grammars/sources/rust/queries/highlights.scm" )
@ -2275,7 +2279,7 @@ mod test {
let source = Rope ::from_str ( source ) ;
let source = Rope ::from_str ( source ) ;
let loader = Loader ::new ( Configuration { language : vec ! [ ] } ) ;
let loader = Loader ::new ( Configuration { language : vec ! [ ] } ) ;
let language = get_language ( " R ust") . unwrap ( ) ;
let language = get_language ( " r ust") . unwrap ( ) ;
let config = HighlightConfiguration ::new ( language , "" , "" , "" ) . unwrap ( ) ;
let config = HighlightConfiguration ::new ( language , "" , "" , "" ) . unwrap ( ) ;
let syntax = Syntax ::new ( & source , Arc ::new ( config ) , Arc ::new ( loader ) ) ;
let syntax = Syntax ::new ( & source , Arc ::new ( config ) , Arc ::new ( loader ) ) ;