DartPP — Dart PreProcessor for VS CodeA feature-flag preprocessor for Flutter projects. Annotate your code with special directive comments and DartPP will comment out or restore entire blocks based on boolean flags in Quick Start1. Create
2. Annotate your files with directives
3. Run a command — Commands
Directive SyntaxDart / Kotlin / Java / Gradle
YAML (
|
| Directive | Meaning |
|---|---|
#if FEATURE |
Active when FEATURE is true |
#ifndef FEATURE |
Active when FEATURE is false |
#elif FEATURE |
Else-if branch |
#else |
Fallback branch |
#endif |
Close the current block |
Full example:
//#if FIREBASE
print('Firebase');
//#elif SUPABASE
print('Supabase');
//#else
print('No backend');
//#endif
Editor Decorations
Open any supported file and DartPP automatically annotates it:
- Directive line — inline label:
✓ FIREBASE enabled(green) or✗ FIREBASE disabled(red) - Disabled block lines — dimmed/greyed out
/**//<!---->markers — rendered transparent (invisible) so the file looks clean
No configuration needed — decorations update live as you edit.
CodeLens
Above every #if / #ifndef block two clickable items appear:
$(pass-filled) FIREBASE — Enabled Disable
$(circle-slash) ADS — Disabled Enable
Clicking Enable or Disable toggles the flag, saves .dartpp.json, and immediately applies changes to all project files.
Wrap with Directive
Select any lines → right-click → DartPP: Wrap with Directive (or use the Command Palette).
Choose a pattern:
| Pattern | Result |
|---|---|
#if FEATURE |
Single guarded block |
#ifndef FEATURE |
Inverted guard |
#if … #else … #endif |
Two-branch |
#if … #elif … #else … #endif |
Three-branch |
The directive style (//, #, <!-- -->) is chosen automatically based on the file type.
Files Processed
| Included | Excluded |
|---|---|
lib/**/*.dart |
.dart_tool/** |
pubspec.yaml |
build/** |
android/**/*.kt |
.git/** |
android/**/*.java |
.gradle/** |
android/**/*.xml |
.idea/** |
android/**/*.gradle |
|
android/**/*.gradle.kts |
|
*.gradle (root) |
|
*.gradle.kts (root) |
Settings
| Setting | Default | Description |
|---|---|---|
dartpp.configFile |
.dartpp.json |
Config file path relative to workspace root |
dartpp.runFlutterPubGet |
true |
Run flutter pub get after Apply Configuration |
Output Channel
All activity is logged to View → Output → DartPP:
- Feature flags loaded (enabled / disabled counts)
- Files processed or skipped
flutter pub getstdout and stderr- Decoration parse results
Building & Installing
npm install
npm run compile # compile TypeScript → out/
npm run package # produce dartpp-1.0.0.vsix (requires @vscode/vsce)
Install the .vsix:
code --install-extension dartpp-1.0.0.vsix
Or: Extensions panel → ··· → Install from VSIX…
The extension activates automatically when the workspace contains .dartpp.json.
Project Structure
src/
├─ extension.ts Activation, commands, file watcher
├─ commands/
│ ├─ applyConfiguration.ts Apply flags to all files + flutter pub get
│ ├─ toggleFeature.ts QuickPick toggle + auto-apply
│ ├─ reloadConfiguration.ts Reload flags + refresh decorations
│ └─ wrapWithDirective.ts Wrap selection with directive block
├─ parser/
│ ├─ lexer.ts Tokenise directives (Dart / YAML / XML styles)
│ ├─ parser.ts Stack-based AST builder
│ ├─ evaluator.ts AST → output + block metadata
│ └─ processor.ts Public API: commentOutSource, validateDirectives
├─ config/
│ └─ configManager.ts Load / save / toggle .dartpp.json
├─ decorations/
│ └─ decorationProvider.ts Labels, dimming, hidden /* */ markers
├─ codelens/
│ └─ codeLensProvider.ts Clickable Enable / Disable above each block
└─ utils/
└─ fileUtils.ts File collection (Dart, YAML, Android, Gradle)