Skip to content

feat: viewport-aware debugger polling with ST/IL inline badge support#689

Closed
thiagoralves wants to merge 6 commits into
developmentfrom
feat/debugger-viewport-polling-st-il
Closed

feat: viewport-aware debugger polling with ST/IL inline badge support#689
thiagoralves wants to merge 6 commits into
developmentfrom
feat/debugger-viewport-polling-st-il

Conversation

@thiagoralves
Copy link
Copy Markdown
Contributor

@thiagoralves thiagoralves commented Mar 13, 2026

Summary

  • Viewport-aware polling (from PR Fix debugger polling to fetch only visible variables #646): Replaces the catch-all "poll all variables of active POU" approach with targeted polling that only fetches variables from visible LD/FBD nodes, reducing serial throughput on constrained boards
  • ST/IL inline badge polling: Adds a new polling section for ST/IL languages that scans POU source text for variable references (word-boundary regex match) and polls only those variables, including FB instance sub-variables
  • Debug badge model switching fix: Fixes a bug where opening multiple ST/IL function blocks (e.g., Manual_Override.st + State_Display.il) caused inline debug badges to show at wrong positions or disappear when switching tabs. Uses onDidChangeModel listener + URI guard to ensure the debugVarPositions memo always scans the correct Monaco model

Key changes

workspace-screen.tsx:

  • Replaces Section E (poll all POU variables) with targeted LD, FBD, and ST/IL sections
  • ST/IL section uses word-boundary regex to match POU variables in source text
  • Handles derived-type (FB instance) sub-variable polling for all languages
  • Refactored shouldPollNestedVariable for watched/expanded variable keys

monaco/index.tsx:

  • Added modelVersion state + onDidChangeModel listener to detect model switches
  • Added URI guard in debugVarPositions memo to prevent scanning stale models during tab transitions
  • Both ensure correct debug badge rendering when multiple ST/IL tabs are open

Test plan

  • ST program debug: inline badges appear and update correctly
  • IL program debug: inline badges appear and update correctly
  • ST function block debug: select instance, verify inline badges with FB context
  • Multiple ST/IL tabs open: switch between tabs, badges show correct positions for each
  • LD debug: contacts/coils show values for visible rungs
  • FBD debug: only visible node variables are polled
  • Watched variables (checkbox): always polled regardless of viewport/language
  • Forced variables: force functionality works correctly
  • POU switching: visible variable set updates correctly when changing active POU

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of debug variable position calculations when switching between editor tabs.
    • Enhanced variable monitoring to properly track nested variables, function block instances, and variables across different language types for more consistent debugging support.

MatthewReed303 and others added 6 commits March 4, 2026 14:07
Add an ST/IL section to the debugger polling tick that scans the POU
source text for variable references and adds them to debugVariableKeys.
This follows the same pattern as the LD/FBD sections — only variables
that actually appear in the code are polled, not every declared variable.

Also polls FB instance sub-variables (e.g., TON0.ET, TON0.Q) when the
instance name appears in the source text.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… mixing

When multiple ST/IL function blocks are open in tabs, switching between them
causes the debugVarPositions memo to run with the new POU name but the old
Monaco model (since @monaco-editor/react reuses the component with
keepCurrentModel). This resets editorMounted to false on name change so the
memo returns null until handleEditorDidMount fires with the correct model.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The previous fix (resetting editorMounted on name change) didn't work
because @monaco-editor/react's onMount only fires once on initial mount,
not on subsequent path/model switches with keepCurrentModel={true}.

New approach:
- Listen to editor.onDidChangeModel to detect when the library switches
  models (tab change), then bump a modelVersion counter to trigger the
  debugVarPositions memo recomputation.
- Add a URI guard inside the memo that verifies the current model matches
  the expected POU path, preventing position scanning against a stale
  model during the render before the model switch completes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 13, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0ea2fb1c-9027-466a-aaea-1ca07df9fe5d

📥 Commits

Reviewing files that changed from the base of the PR and between 6e1daaf and 681f519.

📒 Files selected for processing (2)
  • src/renderer/components/_features/[workspace]/editor/monaco/index.tsx
  • src/renderer/screens/workspace-screen.tsx

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


Walkthrough

This PR enhances debugger variable polling and Monaco editor safety. Changes track model switches in the Monaco editor to prevent race conditions when recomputing debug variable positions, and significantly refactor workspace variable polling to support hierarchical nested variables, function-block instances with context-aware keys, and ST/IL source-based variable detection at arbitrary nesting depths.

Changes

Cohort / File(s) Summary
Monaco Editor Model Tracking
src/renderer/components/_features/[workspace]/editor/monaco/index.tsx
Added modelVersion state and effect to detect Monaco model changes; guarded debug variable position computation paths with model URI validation to prevent races during tab/model switches.
Variable Polling Refactoring
src/renderer/screens/workspace-screen.tsx
Reworked nested variable polling with hierarchical path computation, expanded FB/IL/ST variable handling including function-block instances with context-aware composite keys, added source-based polling for ST/IL languages, and generalized polling for arbitrary nesting depth with ancestor expansion checks.

Sequence Diagram(s)

sequenceDiagram
    actor Editor as Editor (User)
    participant POU as POU/Source
    participant Poller as Variable Polling Logic
    participant Debugger as Debugger Backend
    participant VarTree as Variable Hierarchy
    
    Editor->>POU: Switch/Edit POU (FB, ST, IL)
    POU->>Poller: Trigger polling for variables
    
    Poller->>VarTree: Extract variable path (dot/bracket notation)
    VarTree-->>Poller: Hierarchical path + deepest ancestor
    
    Poller->>VarTree: Check ancestor expansion status
    alt Ancestor not expanded
        VarTree-->>Poller: Expand path
    end
    
    Poller->>Poller: Generate composite key (context-aware)
    Note over Poller: FB instances, outputs, nested depth
    
    Poller->>Debugger: Poll variable with composite key
    Debugger-->>Poller: Variable value + position
    
    Poller->>Editor: Update debug display (inline positions)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • #639: Also modifies Monaco editor file to recompute debug variable positions during editor lifecycle changes; this PR adds model-switch guards to prevent races with that feature.
  • #614: Modifies workspace-screen.tsx variable polling and ST/IL debug handling including nested/UDT/FB polling logic.
  • #635: Modifies debugger variable polling in workspace-screen.tsx covering function-block/temp outputs and forced variable polling.

Suggested labels

enhancement

Suggested reviewers

  • JoaoGSP
  • DanielBorgesDev

Poem

🐰 Model switches tick, we guard them tight,
Nested variables dance in debug light,
Function blocks bloom through hierarchies deep,
Safe polling flows while Monaco's watchers keep! 🌙✨

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/debugger-viewport-polling-st-il
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@thiagoralves thiagoralves deleted the feat/debugger-viewport-polling-st-il branch March 13, 2026 01:21
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.

2 participants