Rename LanguageConfig language_id as language_name

get-lang-config-by-injection-layer
Michael Davis 11 months ago
parent 17dd102e5c
commit 4e1aeb1b99
No known key found for this signature in database

@ -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)
} }
} }
} }

@ -179,7 +179,7 @@ pub fn languages_all() -> std::io::Result<()> {
syn_loader_conf syn_loader_conf
.language .language
.sort_unstable_by_key(|l| l.language_id.clone()); .sort_unstable_by_key(|l| l.language_name.clone());
let check_binary = |cmd: Option<&str>| match cmd { let check_binary = |cmd: Option<&str>| match cmd {
Some(cmd) => match which::which(cmd) { Some(cmd) => match which::which(cmd) {
@ -190,7 +190,7 @@ pub fn languages_all() -> std::io::Result<()> {
}; };
for lang in &syn_loader_conf.language { for lang in &syn_loader_conf.language {
column(&lang.language_id, Color::Reset); column(&lang.language_name, Color::Reset);
let mut cmds = lang.language_servers.iter().filter_map(|ls| { let mut cmds = lang.language_servers.iter().filter_map(|ls| {
syn_loader_conf syn_loader_conf
@ -210,7 +210,7 @@ pub fn languages_all() -> std::io::Result<()> {
check_binary(formatter); check_binary(formatter);
for ts_feat in TsFeature::all() { for ts_feat in TsFeature::all() {
match load_runtime_file(&lang.language_id, ts_feat.runtime_filename()).is_ok() { match load_runtime_file(&lang.language_name, ts_feat.runtime_filename()).is_ok() {
true => column("✓", Color::Green), true => column("✓", Color::Green),
false => column("✘", Color::Red), false => column("✘", Color::Red),
} }
@ -254,7 +254,7 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
let lang = match syn_loader_conf let lang = match syn_loader_conf
.language .language
.iter() .iter()
.find(|l| l.language_id == lang_str) .find(|l| l.language_name == lang_str)
{ {
Some(l) => l, Some(l) => l,
None => { None => {
@ -263,8 +263,11 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
let suggestions: Vec<&str> = syn_loader_conf let suggestions: Vec<&str> = syn_loader_conf
.language .language
.iter() .iter()
.filter(|l| l.language_id.starts_with(lang_str.chars().next().unwrap())) .filter(|l| {
.map(|l| l.language_id.as_str()) l.language_name
.starts_with(lang_str.chars().next().unwrap())
})
.map(|l| l.language_name.as_str())
.collect(); .collect();
if !suggestions.is_empty() { if !suggestions.is_empty() {
let suggestions = suggestions.join(", "); let suggestions = suggestions.join(", ");

@ -339,7 +339,7 @@ pub mod completers {
let language_ids = editor let language_ids = editor
.syn_loader .syn_loader
.language_configs() .language_configs()
.map(|config| &config.language_id) .map(|config| &config.language_name)
.chain(std::iter::once(&text)); .chain(std::iter::once(&text));
fuzzy_match(input, language_ids, false) fuzzy_match(input, language_ids, false)

@ -1085,7 +1085,7 @@ impl Document {
config_loader: Arc<syntax::Loader>, config_loader: Arc<syntax::Loader>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let language_config = config_loader let language_config = config_loader
.language_config_for_language_id(language_id) .language_config_for_language_name(language_id)
.ok_or_else(|| anyhow!("invalid language id: {}", language_id))?; .ok_or_else(|| anyhow!("invalid language id: {}", language_id))?;
self.set_language(Some(language_config), Some(config_loader)); self.set_language(Some(language_config), Some(config_loader));
Ok(()) Ok(())
@ -1530,7 +1530,7 @@ impl Document {
pub fn language_name(&self) -> Option<&str> { pub fn language_name(&self) -> Option<&str> {
self.language self.language
.as_ref() .as_ref()
.map(|language| language.language_id.as_str()) .map(|language| language.language_name.as_str())
} }
/// Language ID for the document. Either the `language-id`, /// Language ID for the document. Either the `language-id`,

@ -67,7 +67,7 @@ pub fn lang_features() -> Result<String, DynError> {
let mut langs = config let mut langs = config
.language .language
.iter() .iter()
.map(|l| l.language_id.clone()) .map(|l| l.language_name.clone())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
langs.sort_unstable(); langs.sort_unstable();
@ -81,9 +81,9 @@ pub fn lang_features() -> Result<String, DynError> {
let lc = config let lc = config
.language .language
.iter() .iter()
.find(|l| l.language_id == lang) .find(|l| l.language_name == lang)
.unwrap(); // lang comes from config .unwrap(); // lang comes from config
row.push(lc.language_id.clone()); row.push(lc.language_name.clone());
for (_feat, support_list) in &ts_features_to_langs { for (_feat, support_list) in &ts_features_to_langs {
row.push( row.push(

@ -14,7 +14,7 @@ pub fn query_check() -> Result<(), DynError> {
]; ];
for language in lang_config().language { for language in lang_config().language {
let language_name = &language.language_id; let language_name = &language.language_name;
let grammar_name = language.grammar.as_ref().unwrap_or(language_name); let grammar_name = language.grammar.as_ref().unwrap_or(language_name);
for query_file in query_files { for query_file in query_files {
let language = get_language(grammar_name); let language = get_language(grammar_name);

Loading…
Cancel
Save