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

Syntax highlighting for .env.* #8466

Closed
1 task done
nk-tedo-001 opened this issue Feb 27, 2024 · 12 comments · Fixed by #20429
Closed
1 task done

Syntax highlighting for .env.* #8466

nk-tedo-001 opened this issue Feb 27, 2024 · 12 comments · Fixed by #20429
Labels
bug [core label] good first issue Issue suitable for first-time contributors language An umbrella label for all programming languages syntax behaviors unsupported language

Comments

@nk-tedo-001
Copy link

nk-tedo-001 commented Feb 27, 2024

Check for existing issues

  • 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

@nk-tedo-001 nk-tedo-001 added admin read bug [core label] labels Feb 27, 2024
@mrnugget
Copy link
Member

I think you'd just have to add it here, right?

path_suffixes = ["sh", "bash", "bashrc", "bash_profile", "bash_aliases", "bash_logout", "profile", "zsh", "zshrc", "zshenv", "zsh_profile", "zsh_aliases", "zsh_histfile", "zlogin", "zprofile", ".env"]

But would that fix your problem? From reading through those docs it sounds like you also want to support .env.production, etc., right?

@nk-tedo-001
Copy link
Author

I think you'd just have to add it here, right?

path_suffixes = ["sh", "bash", "bashrc", "bash_profile", "bash_aliases", "bash_logout", "profile", "zsh", "zshrc", "zshenv", "zsh_profile", "zsh_aliases", "zsh_histfile", "zlogin", "zprofile", ".env"]

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

  1. .env (which currently works),
  2. .env.*,
  3. and .env.*.*

If a wildcard cannot be applied, we can enumerate a short list of files:

  1. .env,
  2. .env.local,
  3. .env.dev, .env.development, .env.dev.local, .env.development.local,
  4. .env.test, and .env.test.local.
  5. .env.stage, .env.stage.local,
  6. .env.prod, and .env.prod.local

@mrnugget
Copy link
Member

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.

@SomeoneToIgnore
Copy link
Contributor

SomeoneToIgnore commented Feb 27, 2024

Also note that there's #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

@mrnugget
Copy link
Member

Ahh, interesting. Yeah, stems seems like something we'd need in the language config then.

@JosephTLyons JosephTLyons added language An umbrella label for all programming languages syntax behaviors good first issue Issue suitable for first-time contributors unsupported language and removed triage labels Feb 27, 2024
@JosephTLyons JosephTLyons changed the title .env.local is not threated as env file by default Syntax highlighting for .env.* Feb 27, 2024
@rwese
Copy link

rwese commented Mar 3, 2024

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.

@JosephTLyons
Copy link
Collaborator

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": {},

@jaydenseric
Copy link
Contributor

Please whatever the solution, allow syntax highlighting .env.example. And perhaps also .env.whatever.example.

@lpillonel
Copy link

you can simply add in your settings :

"file_types": {
  "Shell Script": [".env.*"]
}

At least works for me : )

@notpeter
Copy link
Member

notpeter commented Nov 4, 2024

Closing as @lpillonel has provided a straightforward example for how Zed can be configured to support syntax highlighting for these files. Thanks for reporting.

@notpeter notpeter closed this as completed Nov 4, 2024
@nk-tedo-001
Copy link
Author

Closing as @lpillonel has provided a straightforward example for how Zed can be configured to support syntax highlighting for these files. Thanks for reporting.

Since this could be considered a workaround, why not enable it by default? It would be user friendly.

@notpeter
Copy link
Member

notpeter commented Nov 8, 2024

Since this could be considered a workaround, why not enable it by default? It would be user friendly.

Sure, why not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [core label] good first issue Issue suitable for first-time contributors language An umbrella label for all programming languages syntax behaviors unsupported language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants