diff options
author | midnightexigent | 2022-10-20 14:13:56 +0000 |
---|---|---|
committer | GitHub | 2022-10-20 14:13:56 +0000 |
commit | d801a6693c3d475b3942f705d3ef48d7966bdf65 (patch) | |
tree | bac1900ae07756d79c66bfa6a2c8708f8c3ff2ff /helix-core/src/syntax.rs | |
parent | 78c0cdc519a2c76842441103b1ed716bb7c0a4e1 (diff) |
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 <pickfire@riseup.net>
* Update book/src/languages.md
Co-authored-by: Ivan Tham <pickfire@riseup.net>
Co-authored-by: Ivan Tham <pickfire@riseup.net>
Diffstat (limited to 'helix-core/src/syntax.rs')
-rw-r--r-- | helix-core/src/syntax.rs | 14 |
1 files changed, 13 insertions, 1 deletions
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()) |