on master help sign in
Allow using path suffixes to associate language file-types (#2455)
d801a66midnightexigent
book/src/languages.md+1−1
@@ -50,7 +50,7 @@ These configuration keys are available:
50| `name` | The name of the language |
50| `name` | The name of the language |
51| `scope` | A string like `source.js` that identifies the language. Currently, we strive to match the scope names used by popular TextMate grammars and by the Linguist library. Usually `source.<name>` or `text.<name>` in case of markup languages |
51| `scope` | A string like `source.js` that identifies the language. Currently, we strive to match the scope names used by popular TextMate grammars and by the Linguist library. Usually `source.<name>` or `text.<name>` in case of markup languages |
52| `injection-regex` | regex pattern that will be tested against a language name in order to determine whether this language should be used for a potential [language injection][treesitter-language-injection] site. |
52| `injection-regex` | regex pattern that will be tested against a language name in order to determine whether this language should be used for a potential [language injection][treesitter-language-injection] site. |
53−| `file-types` | The filetypes of the language, for example `["yml", "yaml"]`. Extensions and full file names are supported. |
53+| `file-types` | The filetypes of the language, for example `["yml", "yaml"]`. This attempts to match by exact file name (`.zshrc`), then by file extension (`toml`), then by path suffix (`.git/config`). |
54| `shebangs` | The interpreters from the shebang line, for example `["sh", "bash"]` |
54| `shebangs` | The interpreters from the shebang line, for example `["sh", "bash"]` |
55| `roots` | A set of marker files to look for when trying to find the workspace root. For example `Cargo.lock`, `yarn.lock` |
55| `roots` | A set of marker files to look for when trying to find the workspace root. For example `Cargo.lock`, `yarn.lock` |
56| `auto-format` | Whether to autoformat this language when saving |
56| `auto-format` | Whether to autoformat this language when saving |
helix-core/src/syntax.rs+13−1
@@ -471,9 +471,10 @@ impl Loader {
471
471
472 for file_type in &config.file_types {
472 for file_type in &config.file_types {
473 // entry().or_insert(Vec::new).push(language_id);
473 // entry().or_insert(Vec::new).push(language_id);
474+ let file_type = file_type.replace('/', &std::path::MAIN_SEPARATOR.to_string());
474 loader
475 loader
475 .language_config_ids_by_file_type
476 .language_config_ids_by_file_type
476− .insert(file_type.clone(), language_id);
477+ .insert(file_type, language_id);
477 }
478 }
478 for shebang in &config.shebangs {
479 for shebang in &config.shebangs {
479 loader
480 loader
@@ -498,6 +499,17 @@ impl Loader {
498 path.extension()
499 path.extension()
499 .and_then(|extension| extension.to_str())
500 .and_then(|extension| extension.to_str())
500 .and_then(|extension| self.language_config_ids_by_file_type.get(extension))
501 .and_then(|extension| self.language_config_ids_by_file_type.get(extension))
502+ })
503+ .or_else(|| {
504+ self.language_config_ids_by_file_type
505+ .iter()
506+ .find_map(|(file_type, id)| {
507+ if path.to_str()?.ends_with(file_type) {
508+ Some(id)
509+ } else {
510+ None
511+ }
512+ })
501 });
513 });
502
514
503 configuration_id.and_then(|&id| self.language_configs.get(id).cloned())
515 configuration_id.and_then(|&id| self.language_configs.get(id).cloned())
languages.toml+1−1
@@ -1054,7 +1054,7 @@ name = "git-config"
1054scope = "source.gitconfig"
1054scope = "source.gitconfig"
1055roots = []
1055roots = []
1056# TODO: allow specifying file-types as a regex so we can read directory names (e.g. `.git/config`)
1056# TODO: allow specifying file-types as a regex so we can read directory names (e.g. `.git/config`)
1057−file-types = [".gitmodules", ".gitconfig"]
1057+file-types = [".gitmodules", ".gitconfig", ".git/config", ".config/git/config"]
1058injection-regex = "git-config"
1058injection-regex = "git-config"
1059comment-token = "#"
1059comment-token = "#"
1060indent = { tab-width = 4, unit = "\t" }
1060indent = { tab-width = 4, unit = "\t" }