zed
zed copied to clipboard
Syntax highlighting for .env.*
Check for existing issues
- [X] Completed
Describe the bug / provide steps to reproduce it
If I edit the .env.local file, Zed does not recognize it as an environment file. Therefore, there is no highlighting, commenting, or other editor features.
I suggest that every env file should be handled properly. Refer to https://create-react-app.dev/docs/adding-custom-environment-variables/#what-other-env-files-can-be-used for more information.
Environment
Zed: v0.123.6 (Zed) OS: macOS 14.1.1 Memory: 32 GiB Architecture: x86_64
I think you'd just have to add it here, right? https://github.com/zed-industries/zed/blob/cbdc07dcd0fe7811615333c91d95d93815eee9f5/crates/languages/src/bash/config.toml#L3
But would that fix your problem? From reading through those docs it sounds like you also want to support .env.production, etc., right?
I think you'd just have to add it here, right?
https://github.com/zed-industries/zed/blob/cbdc07dcd0fe7811615333c91d95d93815eee9f5/crates/languages/src/bash/config.toml#L3
Most likely, all configurations are contained within the Zed binary, as I was unable to locate any separate configuration files. Therefore, I am unable to test this myself.
But would that fix your problem? From reading through those docs it sounds like you also want to support
.env.production, etc., right?
We can add the most commonly used names as
- .env (which currently works),
.env.*,- and
.env.*.*
If a wildcard cannot be applied, we can enumerate a short list of files:
- .env,
- .env.local,
- .env.dev, .env.development, .env.dev.local, .env.development.local,
- .env.test, and .env.test.local.
- .env.stage, .env.stage.local,
- .env.prod, and .env.prod.local
Most likely, all configurations are contained within the Zed binary, as I was unable to locate any separate configuration files. Therefore, I am unable to test this myself.
Yep, sorry, I meant: you can add this in a PR :)
But yeah, we don't seem to support wildcards so far, only suffixes. What we need is a path_prefix.
Also note that there's https://github.com/zed-industries/zed/pull/8453 for extension-less files, and it looks like its logic matches what one would want for .env*?
https://github.com/zed-industries/zed/pull/8453/files#diff-bde575654544e89aff5972d3565828c6d6deb5fb3b9fbc01299b1b82bf5a8569R106-R110
Ahh, interesting. Yeah, stems seems like something we'd need in the language config then.
I've looked into it on how to get this done, as i thought it would be trivial, while it is not hard per-se it requires a change here:
language_registry.rs :: language_for_file will need a change, as it uses the path.extension_or_hidden_file_name which will only return the last extension.
- Crate path: new function
path.get_all_extensions_or_hidden_file_name(): Option<Vec<&str>> - language_for_file:
- iterate over all found extensions
- take the last recognized language
Additionally, it would be an option to enable support for globbing / wildcard matches in path_suffixes of languages config.toml, this would add extra refactoring work.
Sorry I wasn't more help, but I gave it an honest try.
Just to mention it, we do have a file_types setting that might be useful here, as a temporary bandaid:
// An object whose keys are language names, and whose values
// are arrays of filenames or extensions of files that should
// use those languages.
//
// For example, to treat files like `foo.notjs` as JavaScript,
// and 'Embargo.lock' as TOML:
//
// {
// "JavaScript": ["notjs"],
// "TOML": ["Embargo.lock"]
// }
//
"file_types": {},
Please whatever the solution, allow syntax highlighting .env.example. And perhaps also .env.whatever.example.
you can simply add in your settings :
"file_types": {
"Shell Script": [".env.*"]
}
At least works for me : )