forked from helix-editor/helix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add glob file type support (helix-editor#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 <[email protected]>
- Loading branch information
Showing
12 changed files
with
262 additions
and
187 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,45 @@ | ||
/// Syntax configuration loader based on built-in languages.toml. | ||
pub fn default_syntax_loader() -> crate::syntax::Configuration { | ||
use crate::syntax::{Configuration, Loader, LoaderError}; | ||
|
||
/// Language configuration based on built-in languages.toml. | ||
pub fn default_lang_config() -> Configuration { | ||
helix_loader::config::default_lang_config() | ||
.try_into() | ||
.expect("Could not serialize built-in languages.toml") | ||
.expect("Could not deserialize built-in languages.toml") | ||
} | ||
/// Syntax configuration loader based on user configured languages.toml. | ||
pub fn user_syntax_loader() -> Result<crate::syntax::Configuration, toml::de::Error> { | ||
|
||
/// Language configuration loader based on built-in languages.toml. | ||
pub fn default_lang_loader() -> Loader { | ||
Loader::new(default_lang_config()).expect("Could not compile loader for default config") | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum LanguageLoaderError { | ||
DeserializeError(toml::de::Error), | ||
LoaderError(LoaderError), | ||
} | ||
|
||
impl std::fmt::Display for LanguageLoaderError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::DeserializeError(err) => write!(f, "Failed to parse language config: {err}"), | ||
Self::LoaderError(err) => write!(f, "Failed to compile language config: {err}"), | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for LanguageLoaderError {} | ||
|
||
/// Language configuration based on user configured languages.toml. | ||
pub fn user_lang_config() -> Result<Configuration, toml::de::Error> { | ||
helix_loader::config::user_lang_config()?.try_into() | ||
} | ||
|
||
/// Language configuration loader based on user configured languages.toml. | ||
pub fn user_lang_loader() -> Result<Loader, LanguageLoaderError> { | ||
let config: Configuration = helix_loader::config::user_lang_config() | ||
.map_err(LanguageLoaderError::DeserializeError)? | ||
.try_into() | ||
.map_err(LanguageLoaderError::DeserializeError)?; | ||
|
||
Loader::new(config).map_err(LanguageLoaderError::LoaderError) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.