mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 09:26:19 +04:00
Rename LanguageConfig language_id as language_name
This commit is contained in:
parent
17dd102e5c
commit
4e1aeb1b99
@ -93,7 +93,7 @@ fn default() -> Self {
|
||||
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
|
||||
pub struct LanguageConfiguration {
|
||||
#[serde(rename = "name")]
|
||||
pub language_id: String, // c-sharp, rust, tsx
|
||||
pub language_name: String, // c-sharp, rust, tsx
|
||||
#[serde(rename = "language-id")]
|
||||
// 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
|
||||
@ -636,21 +636,21 @@ pub fn read_query(language: &str, filename: &str) -> String {
|
||||
|
||||
impl LanguageConfiguration {
|
||||
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
|
||||
// highlights_query += "\n(ERROR) @error";
|
||||
|
||||
let injections_query = read_query(&self.language_id, "injections.scm");
|
||||
let locals_query = read_query(&self.language_id, "locals.scm");
|
||||
let injections_query = read_query(&self.language_name, "injections.scm");
|
||||
let locals_query = read_query(&self.language_name, "locals.scm");
|
||||
|
||||
if highlights_query.is_empty() {
|
||||
None
|
||||
} 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| {
|
||||
log::error!(
|
||||
"Failed to load tree-sitter parser for language {:?}: {}",
|
||||
self.language_id,
|
||||
self.language_name,
|
||||
err
|
||||
)
|
||||
})
|
||||
@ -661,7 +661,7 @@ fn initialize_highlight(&self, scopes: &[String]) -> Option<Arc<HighlightConfigu
|
||||
&injections_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()?;
|
||||
|
||||
config.configure(scopes);
|
||||
@ -705,7 +705,7 @@ pub fn scope(&self) -> &str {
|
||||
}
|
||||
|
||||
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() {
|
||||
return None;
|
||||
}
|
||||
@ -715,7 +715,7 @@ fn load_query(&self, kind: &str) -> Option<Query> {
|
||||
log::error!(
|
||||
"Failed to parse {} queries for {}: {}",
|
||||
kind,
|
||||
self.language_id,
|
||||
self.language_name,
|
||||
e
|
||||
)
|
||||
})
|
||||
@ -855,10 +855,13 @@ pub fn language_config_for_scope(&self, scope: &str) -> Option<Arc<LanguageConfi
|
||||
.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
|
||||
.iter()
|
||||
.find(|config| config.language_id == id)
|
||||
.find(|config| config.language_name == name)
|
||||
.cloned()
|
||||
}
|
||||
|
||||
@ -890,7 +893,7 @@ pub fn language_configuration_for_injection_string(
|
||||
InjectionLanguageMarker::Name(string) => self.language_config_for_name(string),
|
||||
InjectionLanguageMarker::Filename(file) => self.language_config_for_file_name(file),
|
||||
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
|
||||
.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 {
|
||||
Some(cmd) => match which::which(cmd) {
|
||||
@ -190,7 +190,7 @@ pub fn languages_all() -> std::io::Result<()> {
|
||||
};
|
||||
|
||||
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| {
|
||||
syn_loader_conf
|
||||
@ -210,7 +210,7 @@ pub fn languages_all() -> std::io::Result<()> {
|
||||
check_binary(formatter);
|
||||
|
||||
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),
|
||||
false => column("✘", Color::Red),
|
||||
}
|
||||
@ -254,7 +254,7 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
|
||||
let lang = match syn_loader_conf
|
||||
.language
|
||||
.iter()
|
||||
.find(|l| l.language_id == lang_str)
|
||||
.find(|l| l.language_name == lang_str)
|
||||
{
|
||||
Some(l) => l,
|
||||
None => {
|
||||
@ -263,8 +263,11 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
|
||||
let suggestions: Vec<&str> = syn_loader_conf
|
||||
.language
|
||||
.iter()
|
||||
.filter(|l| l.language_id.starts_with(lang_str.chars().next().unwrap()))
|
||||
.map(|l| l.language_id.as_str())
|
||||
.filter(|l| {
|
||||
l.language_name
|
||||
.starts_with(lang_str.chars().next().unwrap())
|
||||
})
|
||||
.map(|l| l.language_name.as_str())
|
||||
.collect();
|
||||
if !suggestions.is_empty() {
|
||||
let suggestions = suggestions.join(", ");
|
||||
|
@ -339,7 +339,7 @@ pub fn language(editor: &Editor, input: &str) -> Vec<Completion> {
|
||||
let language_ids = editor
|
||||
.syn_loader
|
||||
.language_configs()
|
||||
.map(|config| &config.language_id)
|
||||
.map(|config| &config.language_name)
|
||||
.chain(std::iter::once(&text));
|
||||
|
||||
fuzzy_match(input, language_ids, false)
|
||||
|
@ -1085,7 +1085,7 @@ pub fn set_language_by_language_id(
|
||||
config_loader: Arc<syntax::Loader>,
|
||||
) -> anyhow::Result<()> {
|
||||
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))?;
|
||||
self.set_language(Some(language_config), Some(config_loader));
|
||||
Ok(())
|
||||
@ -1530,7 +1530,7 @@ pub fn language_scope(&self) -> Option<&str> {
|
||||
pub fn language_name(&self) -> Option<&str> {
|
||||
self.language
|
||||
.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`,
|
||||
|
@ -67,7 +67,7 @@ pub fn lang_features() -> Result<String, DynError> {
|
||||
let mut langs = config
|
||||
.language
|
||||
.iter()
|
||||
.map(|l| l.language_id.clone())
|
||||
.map(|l| l.language_name.clone())
|
||||
.collect::<Vec<_>>();
|
||||
langs.sort_unstable();
|
||||
|
||||
@ -81,9 +81,9 @@ pub fn lang_features() -> Result<String, DynError> {
|
||||
let lc = config
|
||||
.language
|
||||
.iter()
|
||||
.find(|l| l.language_id == lang)
|
||||
.find(|l| l.language_name == lang)
|
||||
.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 {
|
||||
row.push(
|
||||
|
@ -14,7 +14,7 @@ pub fn query_check() -> Result<(), DynError> {
|
||||
];
|
||||
|
||||
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);
|
||||
for query_file in query_files {
|
||||
let language = get_language(grammar_name);
|
||||
|
Loading…
Reference in New Issue
Block a user