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

Wrong syntax highlighting in .env.* files #67

Closed
danulqua opened this issue Nov 3, 2022 · 13 comments
Closed

Wrong syntax highlighting in .env.* files #67

danulqua opened this issue Nov 3, 2022 · 13 comments

Comments

@danulqua
Copy link

danulqua commented Nov 3, 2022

Syntax highlighting in the original .env file is OK. But if you append different environment names to it, e.g. .env.production, .env.development, or .env.example - it isn't correct.

CleanShot 2022-11-03 at 16 06 21@2x

@motdotla
Copy link
Member

Thank you for reporting this @danil0110

@ConnorJennison
Copy link
Collaborator

Hey there. I'm working on reworking the syntax highlighting right now. Just as note I noticed for the normal .env file it would for some reason use the properties language for syntax highlighting, whereas other .env.* files would use dotenv language, which is why they look different.

@danulqua
Copy link
Author

danulqua commented Dec 7, 2022

@ConnorJennison true, I've checked that. I've also noticed that, I guess, dotenv extension has a hardcoded variations of .env files. If I use .env.development, .env.production, .env.example - it sets language to env, but as soon as I create other files like .env.sample, .env.random-name - it sets language to Plain Text.

@ConnorJennison
Copy link
Collaborator

ConnorJennison commented Dec 7, 2022

Yeah I tried to add a wildcard to the end of .env in the extensions list to see if that could pick up any .env.* but it doesn't work like that it looks like. If you have a .env.random-name file vscode treats that as a .random-name extension. We have a pretty long list of extensions configured in the package.json file that specify which extensions should use dotenv langauge by default. If you have other possible common examples like .env.sample I can add those into the list, but if you use more custom ones too then for those I think you'd just have to set the language to dotenv by doing Control+K M (not sure if that's the keybind on mac also, but it should be under command pallete as Change Language Mode

@danulqua
Copy link
Author

danulqua commented Dec 8, 2022

@ConnorJennison I've made a little survey through some chats with developers. Here is the list with the names which are being used frequently:

  • .env.dev
  • .env.development
  • .env.prod
  • .env.production
  • .env.test
  • .env.testing
  • .env.local
  • .env.stage
  • .env.staging
  • .env.deploy
  • .env.deployment
  • .env.example
  • .env.sample

@ConnorJennison
Copy link
Collaborator

Thanks for this list. Most of these should be configured but for the ones that aren't I will add them and will release along with improved syntax highlighting once I finish that.

@motdotla
Copy link
Member

@danil0110, @ConnorJennison and I just released 0.21.0 that should fix these issues up.

Let us know if you still see anything. Thank you for reporting!

@danulqua
Copy link
Author

@motdotla @ConnorJennison
Nothing changed on my side
CleanShot 2022-12-12 at 15 59 31@2x

@danulqua
Copy link
Author

@motdotla @ConnorJennison any feedback?

@ConnorJennison
Copy link
Collaborator

Just saw this, I'll take a look tomorrow when Im working. Thanks for letting me know

@ConnorJennison
Copy link
Collaborator

ConnorJennison commented Dec 19, 2022

Downloaded vscode on my windows laptop to test real quick and this is what I see for .env file

dotenv-example

Can you check a couple of things for me.

  1. Do Control/CMD+K M and make sure the language selected for those files is dotenv. It will say configured language next to that if being used for highlighting for that file. (it should be dotenv by default but I noticed before that a .env file was using the properties language for some reason, but when I tried it just now it auto-configured it to dotenv so I'm still not sure what is causing that`

  2. Go into extension list and make sure that you are using version 0.21.0 (I think you should be able to check by clicking the Install Another Version button.

  3. If neither of those did anything open the command pallete (Control/CMD + Shift + P) and type scopes and click the thing that comes up. Then you can click around the file and look at the textmate scopes for the different elements that will determine how it is highlighted. In your files if you click on DATABASE then the scope should be variable.key.dotenv and if you click on the string value for that key then the scopes should be string.quoted.single.dotenv and property.value.dotenv

Let me know if any of this solves it or if you're still seeing the same thing

EDIT: Just to be thorough I also made .env.exmple, .env.development, and .env.sample files and they both auto-configured to dotenv language and both look like above.

@ConnorJennison
Copy link
Collaborator

re: the properties thing I noticed I named my test file test.env. I made a new one called just .env and that did configure to properties language at first, so that's likely why you're .env file looks different as well. I'm not sure what is causing that right now and I'll make an issue to track it, but I think you should be able to add an association to make a .env file load as dotenv language as a workaround until I can track it down.

@danulqua
Copy link
Author

Yes, everything is fine with .env.* files, they have .env language, the theme that I've been using has the same colors for vars and values so I thought it's a dotenv bug, sorry.
Except .env file, as you said, it has properties language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants