From d801a6693c3d475b3942f705d3ef48d7966bdf65 Mon Sep 17 00:00:00 2001 From: midnightexigent Date: Thu, 20 Oct 2022 14:13:56 +0000 Subject: Allow using path suffixes to associate language file-types (#2455) * feat(syntax): add strategy to associate file to language through pattern File path will match if it ends with any of the file types provided in the config. Also used this feature to add support for the .git/config and .ssh/config files * Add /etc/ssh/ssh_config to languages.toml * cargo xtask docgen * Update languages.md * Update languages.md * Update book/src/languages.md Co-authored-by: Ivan Tham * Update book/src/languages.md Co-authored-by: Ivan Tham Co-authored-by: Ivan Tham --- helix-core/src/syntax.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'helix-core/src/syntax.rs') diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index a08e5084..f9a2ea5f 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -471,9 +471,10 @@ impl Loader { for file_type in &config.file_types { // entry().or_insert(Vec::new).push(language_id); + let file_type = file_type.replace('/', &std::path::MAIN_SEPARATOR.to_string()); loader .language_config_ids_by_file_type - .insert(file_type.clone(), language_id); + .insert(file_type, language_id); } for shebang in &config.shebangs { loader @@ -498,6 +499,17 @@ impl Loader { path.extension() .and_then(|extension| extension.to_str()) .and_then(|extension| self.language_config_ids_by_file_type.get(extension)) + }) + .or_else(|| { + self.language_config_ids_by_file_type + .iter() + .find_map(|(file_type, id)| { + if path.to_str()?.ends_with(file_type) { + Some(id) + } else { + None + } + }) }); configuration_id.and_then(|&id| self.language_configs.get(id).cloned()) -- cgit v1.2.3-70-g09d2