@ -93,7 +93,7 @@ impl Default for Configuration {
#[ serde(rename_all = " kebab-case " , deny_unknown_fields) ]
#[ serde(rename_all = " kebab-case " , deny_unknown_fields) ]
pub struct LanguageConfiguration {
pub struct LanguageConfiguration {
#[ serde(rename = " name " ) ]
#[ serde(rename = " name " ) ]
pub language_ id : String , // c-sharp, rust, tsx
pub language_ name : String , // c-sharp, rust, tsx
#[ serde(rename = " language-id " ) ]
#[ serde(rename = " language-id " ) ]
// see the table under https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentItem
// see the table under https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentItem
pub language_server_language_id : Option < String > , // csharp, rust, typescriptreact, for the language-server
pub language_server_language_id : Option < String > , // csharp, rust, typescriptreact, for the language-server
@ -636,21 +636,21 @@ 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 highlights_query = read_query ( & self . language_ id , "highlights.scm" ) ;
let highlights_query = read_query ( & self . language_ name , "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 ( & self . language_ id , "injections.scm" ) ;
let injections_query = read_query ( & self . language_ name , "injections.scm" ) ;
let locals_query = read_query ( & self . language_ id , "locals.scm" ) ;
let locals_query = read_query ( & self . language_ name , "locals.scm" ) ;
if highlights_query . is_empty ( ) {
if highlights_query . is_empty ( ) {
None
None
} else {
} else {
let language = get_language ( self . grammar . as_deref ( ) . unwrap_or ( & self . language_ id ) )
let language = get_language ( self . grammar . as_deref ( ) . unwrap_or ( & self . language_ name ) )
. map_err ( | err | {
. map_err ( | err | {
log ::error ! (
log ::error ! (
"Failed to load tree-sitter parser for language {:?}: {}" ,
"Failed to load tree-sitter parser for language {:?}: {}" ,
self . language_ id ,
self . language_ name ,
err
err
)
)
} )
} )
@ -661,7 +661,7 @@ impl LanguageConfiguration {
& injections_query ,
& injections_query ,
& locals_query ,
& locals_query ,
)
)
. map_err ( | err | log ::error ! ( "Could not parse queries for language {:?}. Are your grammars out of sync? Try running 'hx --grammar fetch' and 'hx --grammar build'. This query could not be parsed: {:?}" , self . language_ id , err ) )
. map_err ( | err | log ::error ! ( "Could not parse queries for language {:?}. Are your grammars out of sync? Try running 'hx --grammar fetch' and 'hx --grammar build'. This query could not be parsed: {:?}" , self . language_ name , err ) )
. ok ( ) ? ;
. ok ( ) ? ;
config . configure ( scopes ) ;
config . configure ( scopes ) ;
@ -705,7 +705,7 @@ impl LanguageConfiguration {
}
}
fn load_query ( & self , kind : & str ) -> Option < Query > {
fn load_query ( & self , kind : & str ) -> Option < Query > {
let query_text = read_query ( & self . language_ id , kind ) ;
let query_text = read_query ( & self . language_ name , kind ) ;
if query_text . is_empty ( ) {
if query_text . is_empty ( ) {
return None ;
return None ;
}
}
@ -715,7 +715,7 @@ impl LanguageConfiguration {
log ::error ! (
log ::error ! (
"Failed to parse {} queries for {}: {}" ,
"Failed to parse {} queries for {}: {}" ,
kind ,
kind ,
self . language_ id ,
self . language_ name ,
e
e
)
)
} )
} )
@ -855,10 +855,13 @@ impl Loader {
. cloned ( )
. cloned ( )
}
}
pub fn language_config_for_language_id ( & self , id : & str ) -> Option < Arc < LanguageConfiguration > > {
pub fn language_config_for_language_name (
& self ,
name : & str ,
) -> Option < Arc < LanguageConfiguration > > {
self . language_configs
self . language_configs
. iter ( )
. iter ( )
. find ( | config | config . language_id = = id )
. find ( | config | config . language_ name = = name )
. cloned ( )
. cloned ( )
}
}
@ -890,7 +893,7 @@ impl Loader {
InjectionLanguageMarker ::Name ( string ) = > self . language_config_for_name ( string ) ,
InjectionLanguageMarker ::Name ( string ) = > self . language_config_for_name ( string ) ,
InjectionLanguageMarker ::Filename ( file ) = > self . language_config_for_file_name ( file ) ,
InjectionLanguageMarker ::Filename ( file ) = > self . language_config_for_file_name ( file ) ,
InjectionLanguageMarker ::Shebang ( shebang ) = > {
InjectionLanguageMarker ::Shebang ( shebang ) = > {
self . language_config_for_language_ id ( shebang )
self . language_config_for_language_ name ( shebang )
}
}
}
}
}
}