Skip to content

fix: display global variable values consistently across all programs#597

Merged
JoaoGSP merged 1 commit into
developmentfrom
fix/global-variables-debugger
Feb 11, 2026
Merged

fix: display global variable values consistently across all programs#597
JoaoGSP merged 1 commit into
developmentfrom
fix/global-variables-debugger

Conversation

@JoaoGSP
Copy link
Copy Markdown
Member

@JoaoGSP JoaoGSP commented Feb 10, 2026

Summary

  • Bug: Global (external) variables that are TRUE in one program (e.g. _FBD) were not displaying their value in other programs (e.g. main) during debugging, even though the PLC runtime processes them correctly.
  • Root cause: variableInfoMap was Map<number, VariableInfo> — keyed by debug index with a single entry. Global variables share a single debug index (CONFIG0__VAR_NAME) across programs, so the last program processed would overwrite the previous entry.
  • Fix: Changed the map to Map<number, VariableInfo[]> to support multiple entries per debug index. When a value is polled, it is now written to all composite keys for that index, ensuring global variables display their state in every program that uses them.

Resolves DOPE-162
Closes #529

Test plan

  • Open a multi-program project with shared global variables (e.g. the MEGA.zip from Online signal display of global variables #529)
  • Start the debugger and set a global variable to TRUE in one program
  • Verify the variable shows TRUE in all other programs that use it
  • Verify the debugger panel displays correct values for global variables
  • Verify local and FB variables still work correctly (no regression)

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Fixed variable display and polling to correctly handle cases where multiple variables share debugging information, ensuring values and errors are consistently propagated across functions and programs.

Global (external) variables share a single debug index (CONFIG0__VAR_NAME)
across programs. The variableInfoMap was keyed by index with a single entry,
so when multiple programs used the same global variable, only the last
program processed would display the value. Changed the map to support
multiple entries per debug index and write parsed values to all composite
keys, ensuring global variables show their state in every program.

Resolves: DOPE-162

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

coderabbitai Bot commented Feb 10, 2026

Walkthrough

Updated variableInfoMap structure from mapping a single VariableInfo per debug index to arrays of VariableInfo entries. Modified polling, error handling, filtering, and nested variable logic to process multiple variables sharing a debug index, enabling consistent display and value propagation for shared global/external variables.

Changes

Cohort / File(s) Summary
Variable Tracking Structure and Polling Logic
src/renderer/screens/workspace-screen.tsx
Changed variableInfoMapRef to map debug indices to arrays of VariableInfo entries. Added addVariableInfo() helper for deduplication. Updated polling logic to iterate over all entries per index, derive composite keys for each, and propagate values/errors to all related keys. Modified error handling to assign 'ERR' to all composite keys for affected indices. Adapted filtering, mapping, and nested variable handling to process arrays instead of single entries.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • fix: Global variables support - types and debugger mapping #520: Changes debugger variable matching logic (CONFIG0__ vs RES0__) and exposes variableClass through matchVariableWithDebugEntry; this PR updates workspace-screen to correctly handle multiple variables per debug index, working together to fix global variable display across programs.

Suggested labels

bug

Suggested reviewers

  • vmleroy

Poem

🐰 Through indices and arrays, one rabbit did hop,
Where global signals once fell through the gap,
Now multiple entries dance in arrays so fine,
Each variable's value stays perfectly aligned,
The debugger rejoices—bugs fixed in one bound! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title concisely and clearly describes the main fix: enabling consistent display of global variable values across programs.
Description check ✅ Passed The description explains the bug, root cause, and fix clearly. However, it lacks the DOD checklist completion and test coverage percentage mentioned in the template.
Linked Issues check ✅ Passed The code changes directly address #529 by refactoring variableInfoMap to support multiple entries per debug index, ensuring global variables display consistently across all programs.
Out of Scope Changes check ✅ Passed All changes in workspace-screen.tsx focus on the variableInfoMap refactoring to support multiple VariableInfo entries per debug index, which is directly scoped to the linked issue requirements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/global-variables-debugger

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
src/renderer/screens/workspace-screen.tsx (1)

989-1001: Extract a helper to reduce the repeated map-iteration pattern.

The pattern Array.from(variableInfoMapRef.current.entries()).forEach(([_, varInfos]) => { for (const varInfo of varInfos) { if (...) debugVariableKeys.add(...) } }) appears ~10 times in the polling function, each with a slightly different predicate. This bloats the function and makes it harder to maintain.

Consider extracting a helper like:

♻️ Suggested helper
const addMatchingKeys = (
  map: Map<number, VariableInfo[]>,
  predicate: (info: VariableInfo) => boolean,
  keys: Set<string>,
) => {
  for (const varInfos of map.values()) {
    for (const varInfo of varInfos) {
      if (predicate(varInfo)) {
        keys.add(`${varInfo.pouName}:${varInfo.variable.name}`)
      }
    }
  }
}

This also avoids the Array.from(...entries()) overhead on each call — iterating map.values() directly is cheaper.

Also applies to: 1068-1100, 1210-1242

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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.

@claude
Copy link
Copy Markdown

claude Bot commented Feb 10, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

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.

Online signal display of global variables

1 participant