Skip to content

feat(editor): add dotenv parser#802

Open
KaanAydinli wants to merge 4 commits into
crynta:mainfrom
KaanAydinli:feat/editor-dotenv-coloring
Open

feat(editor): add dotenv parser#802
KaanAydinli wants to merge 4 commits into
crynta:mainfrom
KaanAydinli:feat/editor-dotenv-coloring

Conversation

@KaanAydinli

@KaanAydinli KaanAydinli commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

What

Adds .env / dotenv syntax highlighting in the editor, including variable keys, values, comments, quoted strings, escapes, and common dotenv prefixes like export.

Why

.env files were previously rendered without language-aware highlighting, making variables and comments harder to scan.

How

Adds a lightweight CodeMirror stream parser for dotenv files and wires it into the editor language resolver. Includes regression coverage for leading # values so KEY=#hash is treated as a
value, not a comment.

Testing

  • pnpm exec tsc --noEmit clean
  • Manual smoke-test of the affected feature
  • (If you touched src-tauri/) cargo test --locked and cargo clippy --all-targets --locked -- -D warnings clean
  • (If you changed a #[tauri::command] signature) called out below so the FE caller can be updated in lockstep
  • (If UI) tested in pnpm tauri dev
  • Platforms tested: Linux
  • Shells tested (if relevant): N/A

Additional verification:

  • pnpm test src/modules/editor/lib/dotenv.test.ts
  • pnpm biome check src/modules/editor/lib/dotenv.ts src/modules/editor/lib/dotenv.test.ts src/modules/editor/lib/languageResolver.ts
  • git diff --check oldmain..HEAD

Screenshots / GIFs

Notes for reviewer

Summary by CodeRabbit

  • New Features

    • Added first-class .env / .env.* file support: syntax highlighting for exports, keys, = operator, quoted/unquoted values, variable expansions ($VAR and ${VAR}), comment handling, and improved bracket/quote/comment editor behavior; .env filenames are now reliably recognized and resolved.
  • Tests

    • Added a Vitest suite covering tokenization cases (exports, quoted values, variable refs, and comment edge cases).

@KaanAydinli KaanAydinli requested a review from crynta as a code owner June 13, 2026 21:01
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d71ed701-3dbc-427d-93c9-21d1599558a5

📥 Commits

Reviewing files that changed from the base of the PR and between 1bc1f69 and 7643183.

📒 Files selected for processing (2)
  • src/modules/editor/lib/dotenv.test.ts
  • src/modules/editor/lib/dotenv.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/modules/editor/lib/dotenv.ts

📝 Walkthrough

Walkthrough

Adds a CodeMirror StreamParser for .env files (export/key/value/variable/comment tokenization), tests that parser, and integrates it into the language resolver so .env and .env.* filenames resolve to the new parser.

Changes

Dotenv tokenizer and integration

Layer / File(s) Summary
Dotenv tokenizer state machine and parsing
src/modules/editor/lib/dotenv.ts
Introduces DotenvState to track parse mode, quote context, and whitespace sequences. Implements tokenVariable to recognize $VAR and ${VAR} forms, tokenQuotedValue to parse quoted strings with variable interpolation in double quotes, and exports the dotenv CodeMirror StreamParser with state transitions for export, key, operator, value, comment, and invalid token emission.
Dotenv tokenizer test suite
src/modules/editor/lib/dotenv.test.ts
Provides tokenizeLine helper to initialize parser state, tokenize input with StringStream, and accumulate token/style pairs. Test suite validates export/key/value/comment highlighting, variable references inside double-quoted strings, and hash character handling in unquoted values (including when value begins with #).
Language resolver dotenv wiring
src/modules/editor/lib/languageResolver.ts
Adds dotenvLoader that dynamically imports the tokenizer, registers it under the env extension, introduces filenameLoader(base) to select dotenvLoader for .env and .env.* files, and threads that selection through cacheKey generation and resolveLanguage loader selection to ensure .env* filenames receive precedence.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

A config file sits, quietly plain,
With exports and vars in .env domain,
Now CodeMirror reads every line—
Dollar signs glow, comments align,
Syntax lights up the developer's domain! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(editor): add dotenv parser' accurately and concisely captures the main change: adding dotenv syntax highlighting support to the editor via a new parser.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/modules/editor/lib/dotenv.test.ts (1)

24-68: ⚡ Quick win

Add regression for empty-value comments.

Please add a case for KEY= #comment`` and assert #comment is `comment` (not `string`) so this edge case stays protected.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/modules/editor/lib/dotenv.test.ts` around lines 24 - 68, Add a regression
test in the existing "dotenv tokenizer" suite that calls tokenizeLine with the
string `KEY= `#comment`` and asserts the resulting tokens mark `#comment` as a
comment (not a string); specifically add an it block (e.g., it("treats
empty-value comments as comments", ...)) that expects tokenizeLine("KEY=
`#comment`") toEqual
[["KEY","variableName.definition"],["=","operator"],["`#comment`","comment"]].
Place this new test alongside the other it cases in the same describe so the
tokenizer behavior for empty-value comments is protected.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/modules/editor/lib/dotenv.ts`:
- Around line 73-77: The space-eating branch currently only sets
state.afterValueSpace when state.mode === "value" && state.valueStarted, which
misclassifies "KEY= `#comment`"; change the condition so that when
stream.eatSpace() and state.mode === "value" you set state.afterValueSpace =
true regardless of state.valueStarted (remove the valueStarted guard), so
trailing spaces after '=' correctly mark comments (update the block that
references stream.eatSpace(), state.mode, state.valueStarted and
state.afterValueSpace in src/modules/editor/lib/dotenv.ts).

---

Nitpick comments:
In `@src/modules/editor/lib/dotenv.test.ts`:
- Around line 24-68: Add a regression test in the existing "dotenv tokenizer"
suite that calls tokenizeLine with the string `KEY= `#comment`` and asserts the
resulting tokens mark `#comment` as a comment (not a string); specifically add
an it block (e.g., it("treats empty-value comments as comments", ...)) that
expects tokenizeLine("KEY= `#comment`") toEqual
[["KEY","variableName.definition"],["=","operator"],["`#comment`","comment"]].
Place this new test alongside the other it cases in the same describe so the
tokenizer behavior for empty-value comments is protected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fb095433-30ff-4674-8ce5-ded167aca526

📥 Commits

Reviewing files that changed from the base of the PR and between 4e6a478 and 1bc1f69.

📒 Files selected for processing (3)
  • src/modules/editor/lib/dotenv.test.ts
  • src/modules/editor/lib/dotenv.ts
  • src/modules/editor/lib/languageResolver.ts

Comment thread src/modules/editor/lib/dotenv.ts
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

Successfully merging this pull request may close these issues.

1 participant