Skip to content

Conversation

@haidubogdan
Copy link
Contributor

@haidubogdan haidubogdan commented Dec 11, 2025

This pull request proposes support for .env files.
Maybe it has too much features for the daily usage for these kind of files, but I think it's something to be discussed.
As the feedback progresses I can add more unit tests.

Implementations :

  • mime provider for .env files
  • coloring support
image
  • coloring options for keyword like values (null, true, false ...)
  • interpolated env key features like completion and declaration finder
  • partial ticket fix Add comment/uncomment options on .properties, .cnf, .env files #6677 covering env files
  • hints for duplicate key assignment
  • important file node inclusion for .env file for web and php projects
image

@mbien mbien added the Editor label Dec 12, 2025
@apache apache locked and limited conversation to collaborators Dec 12, 2025
@apache apache unlocked this conversation Dec 12, 2025
Copy link
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general good idea. The grammar seems to be incomplete. I entered DB_TEST=demo then inserted a newline and inputted D. Then I got on CLI:

     [exec] line 2:1 missing ASSIGN_OPERATOR at '<EOF>'

This looks like debug output.

Entering TEST (notice the trailing space) yields:

    [exec] line 1:4 missing ASSIGN_OPERATOR at '<EOF>'
     [exec] SEVERE: Lexer org.netbeans.modules.languages.env.lexer.EnvLexer@7856b550
     [exec]   returned null token but lexerInput.readLength()=1
     [exec]   lexer-state: -1
     [exec]   tokenStartOffset=4, readOffset=5, lookaheadOffset=6
     [exec]   Chars: " " - these characters need to be tokenized.
     [exec] Fix the lexer to not return null token in this state.
     [exec] java.lang.IllegalStateException: Lexer org.netbeans.modules.languages.env.lexer.EnvLexer@7856b550
     [exec]   returned null token but lexerInput.readLength()=1
     [exec]   lexer-state: -1
     [exec]   tokenStartOffset=4, readOffset=5, lookaheadOffset=6
     [exec]   Chars: " " - these characters need to be tokenized.
     [exec] Fix the lexer to not return null token in this state.
     [exec] 	at org.netbeans.lib.lexer.LexerInputOperation.checkLexerInputFinished(LexerInputOperation.java:435)
     [exec] 	at org.netbeans.lib.lexer.LexerInputOperation.nextToken(LexerInputOperation.java:193)
     [exec] 	at org.netbeans.lib.lexer.BatchTokenList.tokenOrEmbeddingImpl(BatchTokenList.java:171)
     [exec] 	at org.netbeans.lib.lexer.BatchTokenList.tokenOrEmbedding(BatchTokenList.java:166)
     [exec] 	at org.netbeans.lib.lexer.LexerUtilsConstants.tokenIndexLazyTokenCreation(LexerUtilsConstants.java:307)
     [exec] 	at org.netbeans.lib.lexer.BatchTokenList.tokenIndex(BatchTokenList.java:161)
     [exec] 	at org.netbeans.api.lexer.TokenSequence.move(TokenSequence.java:650)
     [exec] 	at org.netbeans.modules.languages.env.EnvOccurencesFinder.computeOccurrences(EnvOccurencesFinder.java:99)
     [exec] 	at org.netbeans.modules.languages.env.EnvOccurencesFinder.run(EnvOccurencesFinder.java:60)
     [exec] 	at org.netbeans.modules.languages.env.EnvOccurencesFinder.run(EnvOccurencesFinder.java:35)
     [exec] [catch] at org.netbeans.modules.csl.editor.semantic.MarkOccurrencesHighlighter.processImpl(MarkOccurrencesHighlighter.java:157)
     [exec] 	at org.netbeans.modules.csl.editor.semantic.MarkOccurrencesHighlighter.run(MarkOccurrencesHighlighter.java:114)
     [exec] 	at org.netbeans.modules.csl.editor.semantic.MarkOccurrencesHighlighter.run(MarkOccurrencesHighlighter.java:59)
     [exec] 	at org.netbeans.modules.parsing.impl.TaskProcessor.callParserResultTask(TaskProcessor.java:561)
     [exec] 	at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.run(TaskProcessor.java:786)
     [exec] 	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:288)
     [exec] 	at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.execute(TaskProcessor.java:702)
     [exec] 	at org.netbeans.modules.parsing.impl.TaskProcessor$CompilationJob.run(TaskProcessor.java:663)
     [exec] 	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
     [exec] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
     [exec] 	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1403)
     [exec] 	at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
     [exec] 	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287)
     [exec] 	at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2018)
     [exec] line 1:5 missing ASSIGN_OPERATOR at '<EOF>'

The hint integration shows an untranslated label (first linne in tree):

grafik

<friend>org.netbeans.modules.javascript2.nodejs</friend>
<friend>org.netbeans.modules.javascript2.requirejs</friend>
<friend>org.netbeans.modules.languages.apacheconf</friend>
<friend>org.netbeans.modules.languages.env</friend>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to include the .env file in the Important Files folder for web projects.
I was thinking if it would be better to have a stand alone implementation, but so far I see that most configuration files use this dependency from web.common.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthiasblaesing
Regarding the console output, I see that on antlr language parser there is a removal of the console error listener.
I will apply the same logic.

parser.removeErrorListener(ConsoleErrorListener.INSTANCE);

I will, also, try to display a better message for the syntax error.

- mime provider for .env files
- coloring support
- interpolated env key features like completion and declaration finder
- partial ticket fix apache#6677 covering env files
- include .env file in ImportantFiles node for web and php projects
Copy link
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sane to. Thank you for the update. One comment though: Please don't for push into PRs under review unless they are trivial. If rebase is combined with that it is hard to see what changed in an update. What is more, you'll get information from github about regular pushes, but not about forced pushes.

@lkishalmi I think the issue you mentioned is fixed. From my POV this is good to go in. Do you agree?

Copy link
Contributor

@lkishalmi lkishalmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@matthiasblaesing
Copy link
Contributor

Thank you both. Lets get this in.

@matthiasblaesing matthiasblaesing merged commit b3c35f2 into apache:master Dec 30, 2025
30 checks passed
@matthiasblaesing matthiasblaesing added this to the NB29 milestone Dec 30, 2025
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for having two lexer files with similar tokens?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haidubogdan Hey, in case you missed my question :). Don't get me wrong, I'm not blocking it, I just want to know why this is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I wanted to answer the question, but it's like the comment disappeared from the pull request :) .
The parser lexer is different from the coloring lexer for optimization and scope purpose.
Within the parser verification I just need some specific tokens to know that the language construct is good, so I can skip most of the tokens which would have represented the env key value, improving the parser speed.

@Chris2011
Copy link
Contributor

Damned, I saw that I needed to add my comments. Instead I just saw "pending"... Anyway, thx for having this in :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add comment/uncomment options on .properties, .cnf, .env files

5 participants