summaryrefslogtreecommitdiff
path: root/helix-term/src/application.rs
diff options
context:
space:
mode:
authorGalen Abell2024-02-11 17:24:20 +0000
committerGitHub2024-02-11 17:24:20 +0000
commit581a1ebf5d327c1128fe6c283578e8f36a4b5fb5 (patch)
tree52cea1829f5e5cdf54280eaf631e7ae17feae39f /helix-term/src/application.rs
parentd570c29ce37ffbb46a9c49708c31dfd81daa27cf (diff)
Add glob file type support (#8006)
* Replace FileType::Suffix with FileType::Glob Suffix is rather limited and cannot be used to match files which have semantic meaning based on location + file type (for example, Github Action workflow files). This patch adds support for a Glob FileType to replace Suffix, which encompasses the existing behavior & adds additional file matching functionality. Globs are standard Unix-style path globs, which are matched against the absolute path of the file. If the configured glob for a language is a relative glob (that is, it isn't an absolute path or already starts with a glob pattern), a glob pattern will be prepended to allow matching relative paths from any directory. The order of file type matching is also updated to first match on globs and then on extension. This is necessary as most cases where glob-matching is useful will have already been matched by an extension if glob matching is done last. * Convert file-types suffixes to globs * Use globs for filename matching Trying to match the file-type raw strings against both filename and extension leads to files with the same name as the extension having the incorrect syntax. * Match dockerfiles with suffixes It's common practice to add a suffix to dockerfiles based on their context, e.g. `Dockerfile.dev`, `Dockerfile.prod`, etc. * Make env filetype matching more generic Match on `.env` or any `.env.*` files. * Update docs * Use GlobSet to match all file type globs at once * Update todo.txt glob patterns * Consolidate language Configuration and Loader creation This is a refactor that improves the error handling for creating the `helix_core::syntax::Loader` from the default and user language configuration. * Fix integration tests * Add additional starlark file-type glob --------- Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Diffstat (limited to 'helix-term/src/application.rs')
-rw-r--r--helix-term/src/application.rs14
1 files changed, 4 insertions, 10 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index b5150a13..b844b5f0 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -96,11 +96,7 @@ fn setup_integration_logging() {
}
impl Application {
- pub fn new(
- args: Args,
- config: Config,
- syn_loader_conf: syntax::Configuration,
- ) -> Result<Self, Error> {
+ pub fn new(args: Args, config: Config, lang_loader: syntax::Loader) -> Result<Self, Error> {
#[cfg(feature = "integration")]
setup_integration_logging();
@@ -126,7 +122,7 @@ impl Application {
})
.unwrap_or_else(|| theme_loader.default_theme(true_color));
- let syn_loader = std::sync::Arc::new(syntax::Loader::new(syn_loader_conf));
+ let syn_loader = std::sync::Arc::new(lang_loader);
#[cfg(not(feature = "integration"))]
let backend = CrosstermBackend::new(stdout(), &config.editor);
@@ -394,10 +390,8 @@ impl Application {
/// refresh language config after config change
fn refresh_language_config(&mut self) -> Result<(), Error> {
- let syntax_config = helix_core::config::user_syntax_loader()
- .map_err(|err| anyhow::anyhow!("Failed to load language config: {}", err))?;
-
- self.syn_loader = std::sync::Arc::new(syntax::Loader::new(syntax_config));
+ let lang_loader = helix_core::config::user_lang_loader()?;
+ self.syn_loader = std::sync::Arc::new(lang_loader);
self.editor.syn_loader = self.syn_loader.clone();
for document in self.editor.documents.values_mut() {
document.detect_language(self.syn_loader.clone());