Skip to content

Conversation

@sensei-hacker
Copy link
Member

@sensei-hacker sensei-hacker commented Jan 27, 2026

User description

Summary

Adds visual indicators in the Monaco editor gutter to show which Logic Conditions are currently active and true. Green checkmarks (✓) display for TRUE conditions, gray hollow circles (○) for FALSE conditions, providing real-time feedback during development and debugging.

Changes

  • FALSE condition indicators: Gray hollow circles complement existing green checkmarks, showing complete LC state
  • Transpiler-side line tracking: Immediate visual feedback after "Transpile" or "Save to FC" without requiring "Load from FC" roundtrip

Testing

  • ✅ Verified circles appear on correct lines immediately after transpile button
  • ✅ Tested TRUE/FALSE states display properly with correct visual indicators
  • ✅ Confirmed decompiler mapping replaces transpiler mapping when clicking "Load from FC"
  • ✅ Verified 500ms polling interval provides responsive feedback without saturating serial connection
  • ✅ Tested decoration clearing when disconnecting FC
  • ✅ Tested with both simple and complex LC configurations

Files Changed

  • tabs/javascript_programming.js - UI logic for highlighting, polling, state management
  • tabs/javascript_programming.html - CSS for TRUE/FALSE visual indicators
  • js/transpiler/transpiler/codegen.js - Line tracking during transpilation with offset handling
  • js/transpiler/transpiler/index.js - Return lcToLineMapping in transpiler result

PR Type

Enhancement


Description

This description is generated by an AI tool. It may have inaccuracies

  • Implement real-time active Logic Condition highlighting in Monaco editor

    • Green checkmarks (✓) for TRUE conditions, gray circles (○) for FALSE
    • Transpiler and decompiler track LC-to-line mappings for immediate feedback
  • Add 500ms status polling with MSP chainer for responsive LC state updates

    • Optimized polling rate reduces MSP load by 80% vs previous 100ms interval
    • Reordered FC availability checks to avoid wasteful operations on disconnect
  • Implement line offset correction for auto-added import statements

    • Properly adjusts Acorn line numbers to match Monaco editor line numbers
    • Ensures accurate LC-to-line mapping across transpiler and decompiler
  • Add comprehensive LC-to-line mapping algorithm with five-pass resolution

    • Handles simple conditions, compound conditions (a && b), nested conditions
    • Maps hoisted variables, sticky/timer patterns, and activator chains

Diagram Walkthrough

flowchart LR
  A["Transpiler/Decompiler"] -->|"Generate lcToLineMapping"| B["LC Index to Line Mapping"]
  B -->|"Store mapping"| C["JavaScript Programming Tab"]
  D["MSP Status Polling<br/>500ms interval"] -->|"Get LC status"| E["FC.LOGIC_CONDITIONS_STATUS"]
  E -->|"updateActiveHighlighting"| C
  C -->|"Apply decorations"| F["Monaco Editor Gutter<br/>✓ TRUE / ○ FALSE"]
Loading

File Walkthrough

Relevant files
Configuration changes
monaco_loader.js
Enable Monaco gutter margin for LC highlighting                   

js/transpiler/editor/monaco_loader.js

  • Enable glyphMargin: true in Monaco editor options to support gutter
    decorations
  • Add comment explaining gutter is used for active LC highlighting
    decorations
+1/-0     
Enhancement
codegen.js
Track LC-to-line mappings during code generation                 

js/transpiler/transpiler/codegen.js

  • Add lcToLineMapping object to track LC index to source line mappings
  • Add currentSourceLine and lineOffset properties for line tracking
    during code generation
  • Track source line location from AST statement location information
  • Subtract lineOffset from Acorn line numbers to match Monaco editor
    line numbers
  • Record LC-to-line mapping in pushLogicCommand() when pushing logic
    commands
  • Wrap statement generation in try-finally to properly restore source
    line context
+45/-22 
decompiler.js
Implement comprehensive LC-to-line mapping algorithm         

js/transpiler/transpiler/decompiler.js

  • Add lcToLineMapping and _tempLcLines properties to track LC line
    mappings
  • Return lcToLineMapping in decompile result alongside code and warnings
  • Implement finalizeLcLineMapping() with five-pass algorithm to resolve
    LC line numbers
  • Track if-statement lines during tree decompilation for later mapping
    resolution
  • Handle hoisted variables (const declarations), sticky/timer variables,
    activator relationships, and compound condition operands
  • Map operand LCs to parent LC lines for compound conditions like "if (a
    && b)"
+130/-1 
index.js
Return LC-to-line mapping from transpiler                               

js/transpiler/transpiler/index.js

  • Pass lineOffset from transpiler to codegen for accurate line number
    adjustment
  • Return lcToLineMapping from transpile result alongside commands and
    warnings
+3/-1     
javascript_programming.js
Add active LC highlighting with status polling                     

tabs/javascript_programming.js

  • Add lcToLineMapping, activeDecorations, and statusChainer properties
    for highlighting state management
  • Import interval module for managing polling intervals
  • Store LC-to-line mappings from transpiler and decompiler results
  • Implement setupActiveHighlighting() to create MSP chainer and start
    500ms polling interval
  • Implement updateActiveHighlighting() to poll LC status and apply
    Monaco gutter decorations
  • Implement clearActiveHighlighting() to remove all active decorations
  • Fix isDirty race condition by using setTimeout() to defer flag
    clearing after setValue()
  • Add null checks for FC data availability before accessing LC status
    and conditions
  • Stop polling interval and clear decorations in cleanup function
  • Categorize LCs as TRUE/FALSE/MIXED and apply appropriate gutter
    markers
+178/-2 
javascript_programming.html
Add CSS styling for LC gutter markers                                       

tabs/javascript_programming.html

  • Add .lc-active-true CSS class with green checkmark SVG icon for TRUE
    conditions
  • Add .lc-active-false CSS class with gray hollow circle SVG icon for
    FALSE conditions
  • Add Monaco editor gutter margin background styling
  • Add cursor pointer styling for gutter decoration hover interaction
+28/-0   

Augment decompiler to track which Logic Conditions map to which lines
in generated JavaScript code. This enables real-time highlighting of
active conditions in the JavaScript Programming tab.

Key features:
- 3-pass mapping algorithm handles simple, compound, and nested conditions
- Compound conditions (a && b) correctly map all sub-LCs to same line
- Activator chains propagate line numbers to child LCs
- Hoisted variables and sticky/timer patterns tracked
- Returns lcToLineMapping in decompile() result

Part of Feature 1: Active LC Highlighting (Phase 1/5)
Implement real-time status polling and gutter decoration updates in the
JavaScript Programming tab to show which Logic Conditions are currently
active/true.

Key features:
- Status polling every 100ms using MSPChainer
- updateActiveHighlighting() filters true LCs and applies gutter markers
- clearActiveHighlighting() when code is dirty (unsaved changes)
- Proper cleanup on tab switch/disconnect
- isDirty check prevents highlighting stale code

Part of Feature 1: Active LC Highlighting (Phase 2/5)
Implement CSS and Monaco editor configuration for green checkmark gutter
markers that indicate active/true Logic Conditions.

Key changes:
- Add .lc-active-true CSS class with SVG green checkmark icon
- Add Monaco gutter margin background styling
- Enable glyphMargin: true in Monaco editor options
- Set up proper cursor and sizing for gutter decorations

Part of Feature 1: Active LC Highlighting (Phase 3/5)
Fix 'Cannot read properties of null' error in updateActiveHighlighting()
by adding proper null checks for FC.LOGIC_CONDITIONS_STATUS and
FC.LOGIC_CONDITIONS before accessing .get().

This prevents errors during tab initialization when FC data is still loading.
The onChange handler was firing after setValue() during load, causing
isDirty to be set to true even after we cleared it. This prevented the
highlighting from ever appearing because updateActiveHighlighting()
returns early when isDirty is true.

Fixed by using setTimeout() to clear isDirty after the setValue() change
event has been processed.
Previous approach tried to find LCs by parsing the generated code for
/* LC X */ comments, but normal if-statements don't have these comments.

New approach:
- Track LC index and line content during code generation
- After adding boilerplate, search for the tracked lines in final code
- Map LC index to actual line numbers in final output

This ensures all if-statements and their associated LCs get mapped
correctly for the active highlighting feature.
Track what's being searched for and what's being found to diagnose
why the LC-to-line mapping is empty.
This will help us diagnose why the green checkmarks aren't appearing
by logging:
- When the function is called
- If isDirty is blocking it
- What the LC-to-line mapping is
- If FC data is available
- Which LCs are TRUE
- What lines should be highlighted
- If decorations are created
FC.LOGIC_CONDITIONS_STATUS.get() requires a condition index parameter
and returns a single value. We need getAll() to get the entire status array.

This was causing 'FC data is null' errors and preventing any highlighting
from appearing.
This completes the active LC highlighting feature with two major improvements:

1. FALSE condition indicators: Gray hollow circles (○) display when conditions
   evaluate to FALSE, complementing the existing green checkmarks for TRUE
   conditions. Mixed states (TRUE and FALSE on same line) show green checkmark.

2. Transpiler-side line tracking: LC-to-line mappings are now generated during
   transpilation, providing immediate visual feedback after "Transpile" or
   "Save to FC" without requiring "Load from FC" roundtrip. Correctly adjusts
   for auto-added import statement offset.

Technical changes:
- Add lineOffset tracking in codegen to account for prepended import lines
- Store currentSourceLine context during statement generation
- Return lcToLineMapping in transpiler result
- Update tab to use transpiler mapping immediately after transpile/save
- Change polling interval from 100ms to 500ms to reduce MSP load (2Hz vs 10Hz)
- Reorder checks: verify FC data availability before isDirty state
- Clean up excessive debug logging for production readiness

Testing:
- Verified circles appear on correct lines after transpile
- Tested TRUE/FALSE/MIXED states display properly
- Confirmed decompiler mapping replaces transpiler mapping on load
- Reviewed with inav-code-review agent - all critical issues resolved
@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Jan 27, 2026

ⓘ Your approaching your monthly quota for Qodo. Upgrade your plan

PR Compliance Guide 🔍

All compliance sections have been disabled in the configurations.

Fixes all 6 medium-priority issues identified by qodo-merge bot:
1. Clear stale decorations when loading code from FC
2. Clear mapping/decorations when loading default code
3. Add in-flight guard to prevent overlapping MSP polling requests
4. Remove duplicate intervals before adding new one
5. Improve type safety with Array.isArray() checks for MSP data

Code organization improvements:
- Extract highlighting logic to new module js/transpiler/lc_highlighting.js
- Reduce tab file from 928 to 893 lines (-35 lines)
- Create 5 testable, pure functions: categorizeLCsByStatus(),
  mapLCsToLines(), createMonacoDecorations(), applyDecorations(),
  clearDecorations()
- Better separation of concerns (tab orchestrates, module implements)
- Improved code maintainability and testability
@sensei-hacker sensei-hacker changed the title Add active LC highlighting with FALSE indicators to JavaScript Programming tab JavaScript Programming tab: Add true/false indicators to aid debugging Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant