Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using path suffixes to associate language file-types #2455

Merged
merged 14 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion helix-core/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,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
Expand All @@ -489,6 +490,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())
Expand Down
2 changes: 1 addition & 1 deletion languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ name = "git-config"
scope = "source.gitconfig"
roots = []
# TODO: allow specifying file-types as a regex so we can read directory names (e.g. `.git/config`)
file-types = [".gitmodules", ".gitconfig"]
file-types = [".gitmodules", ".gitconfig", ".git/config", ".config/git/config"]
injection-regex = "git-config"
comment-token = "#"
indent = { tab-width = 4, unit = "\t" }
Expand Down