Skip to content

Clean up SelectedInfo.lua#7052

Open
lL1l1 wants to merge 7 commits intoFAForever:developfrom
lL1l1:annotations/selectedinfo
Open

Clean up SelectedInfo.lua#7052
lL1l1 wants to merge 7 commits intoFAForever:developfrom
lL1l1:annotations/selectedinfo

Conversation

@lL1l1
Copy link
Copy Markdown
Contributor

@lL1l1 lL1l1 commented Feb 25, 2026

Description of the proposed changes

  • Annotate GetUnitRolloverInfo
  • Fix warning of unnecessary argument
  • Move legacy code to backwards compatibility section at bottom of file

Testing done on the proposed changes

No warning from intellisense.

Checklist

Summary by CodeRabbit

  • New Features

    • Added richer unit rollover info showing blueprint, health, fuel/shield, economy, progress, kills, missile silo details, focus chain, and custom name for clearer in-game tooltips.
  • Refactor

    • Moved legacy configuration into a backward-compatibility layer to streamline logic and maintain stable behavior.
  • Documentation

    • Added a changelog entry describing these updates.

@lL1l1 lL1l1 added area: code style code refactoring area: ui Anything to do with the User Interface of the Game labels Feb 25, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 25, 2026

📝 Walkthrough

Walkthrough

Adds a new public function GetUnitRolloverInfo(unit, skipFocus) that aggregates unit rollover data, moves module initialization locals into a backwards-compatibility block, and updates UserUnit:GetCustomName to accept a filler parameter.

Changes

Cohort / File(s) Summary
Changelog Entry
changelog/snippets/other.7052.md
Adds changelog note for issue #7052 describing style cleanup and annotations in SelectedInfo.lua.
Unit Rollover Info & module init
lua/keymap/selectedinfo.lua
Adds GetUnitRolloverInfo(unit, skipFocus) returning a detailed RolloverInfo (blueprintId, econ, health, shield/fuel, work progress, focus chain, kills, missile silo info, customName, unit ref, army index). Removes top-file locals and reintroduces them in a bottom "Backwards compatibility" block.
UserUnit API change
engine/User/UserUnit.lua
Updates method signature function UserUnit:GetCustomName()function UserUnit:GetCustomName(filler); adds ---@param filler any annotation; return type unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • clyfordv
  • Hdt80bro

Poem

🐰 I hop through code with nimble feet,
I gather rollovers tidy and neat,
I tuck old locals safe below,
A new name parameter helped me grow,
Hooray for changes—carrots to eat!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly summarizes the main changes—adding annotations and reorganizing code in SelectedInfo.lua with related updates to UserUnit.lua.
Description check ✅ Passed The description covers key changes, testing, and checklist items. However, it lacks specific detail about the functional changes and doesn't explicitly link to issue #7052 as required by the template.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 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.

@lL1l1 lL1l1 requested a review from Basilisk3 March 1, 2026 20:13
@lL1l1 lL1l1 marked this pull request as ready for review March 1, 2026 20:13
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lua/keymap/selectedinfo.lua (1)

47-58: ⚠️ Potential issue | 🟡 Minor

Potential nil access on first-iteration cycle detection.

If the focus chain loops back to the original unit on the first iteration (i.e., unit:GetFocus():GetEntityId() == unit:GetEntityId()), then info.focus hasn't been assigned yet and info.focus.focus = nil on line 50 will error.

🐛 Proposed fix
         while focus do
             local id = focus:GetEntityId()
             if visited[id] then
-                info.focus.focus = nil
+                if info.focus then
+                    info.focus.focus = nil
+                end
                 break
             end
             visited[id] = true
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/keymap/selectedinfo.lua` around lines 47 - 58, The loop can detect a
cycle on the first iteration where info.focus is still nil; replace the
unconditional assignment info.focus.focus = nil with a nil-safe write: check if
info.focus then set info.focus.focus = nil else set info.focus = nil, so the
cycle-break path doesn't attempt to index a nil. Update the code around the
while loop using the symbols focus, visited, info.focus, and
focusingInfo/GetUnitRolloverInfo to apply this conditional assignment before
breaking.
🧹 Nitpick comments (1)
lua/keymap/selectedinfo.lua (1)

19-21: Missing @param annotation for skipFocus.

The skipFocus parameter is not documented. Add an annotation for completeness.

📝 Proposed fix
 ---@param unit UserUnit
+---@param skipFocus? boolean
 ---@return RolloverInfo
 function GetUnitRolloverInfo(unit, skipFocus)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/keymap/selectedinfo.lua` around lines 19 - 21, Add a missing LuaDoc
`@param` annotation for the skipFocus parameter on the GetUnitRolloverInfo
function: update the comment block above GetUnitRolloverInfo to include a line
like "@param skipFocus boolean? — skip focusing logic when true" (or use the
appropriate type and short description used in this project) so the function
signature documents both unit and skipFocus consistently with existing
annotations.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lua/keymap/selectedinfo.lua`:
- Around line 79-90: Remove the dead local variables by deleting the unused
import/assignment and table: drop the local Prefs =
import("/lua/user/prefs.lua") and the subsequent local options =
Prefs.GetFromCurrentProfile('options') if Prefs is only used for options, and
remove the unused local selectionOverlay table (symbols: Prefs, options,
selectionOverlay); if Prefs is used elsewhere keep the import but remove only
the options assignment and the selectionOverlay block to eliminate dead code and
leftover backwards-compatibility comments.

---

Outside diff comments:
In `@lua/keymap/selectedinfo.lua`:
- Around line 47-58: The loop can detect a cycle on the first iteration where
info.focus is still nil; replace the unconditional assignment info.focus.focus =
nil with a nil-safe write: check if info.focus then set info.focus.focus = nil
else set info.focus = nil, so the cycle-break path doesn't attempt to index a
nil. Update the code around the while loop using the symbols focus, visited,
info.focus, and focusingInfo/GetUnitRolloverInfo to apply this conditional
assignment before breaking.

---

Nitpick comments:
In `@lua/keymap/selectedinfo.lua`:
- Around line 19-21: Add a missing LuaDoc `@param` annotation for the skipFocus
parameter on the GetUnitRolloverInfo function: update the comment block above
GetUnitRolloverInfo to include a line like "@param skipFocus boolean? — skip
focusing logic when true" (or use the appropriate type and short description
used in this project) so the function signature documents both unit and
skipFocus consistently with existing annotations.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 72a00be and 1d9db33.

📒 Files selected for processing (2)
  • changelog/snippets/other.7052.md
  • lua/keymap/selectedinfo.lua

Comment on lines +79 to +90
--#region Backwards compatibility
local Prefs = import("/lua/user/prefs.lua")
local options = Prefs.GetFromCurrentProfile('options')

local selectionOverlay = {
key = 'selection',
Label = "<LOC map_options_0006>Selection",
Pref = 'range_RenderSelected',
Type = 3,
Tooltip = "overlay_selection",
}
--#endregion
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if options and selectionOverlay are used in selectedinfo.lua

echo "=== Checking usage of 'options' in selectedinfo.lua ==="
rg -n '\boptions\b' lua/keymap/selectedinfo.lua

echo ""
echo "=== Checking usage of 'selectionOverlay' in selectedinfo.lua ==="
rg -n '\bselectionOverlay\b' lua/keymap/selectedinfo.lua

Repository: FAForever/fa

Length of output: 265


Remove unused options and selectionOverlay variables.

Both variables are defined but never used in the file. The options variable on line 81 and selectionOverlay table on lines 83-89 appear only at their definition points and have no other references. Since they're local, they cannot provide backwards compatibility to external code. Remove these dead code assignments.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/keymap/selectedinfo.lua` around lines 79 - 90, Remove the dead local
variables by deleting the unused import/assignment and table: drop the local
Prefs = import("/lua/user/prefs.lua") and the subsequent local options =
Prefs.GetFromCurrentProfile('options') if Prefs is only used for options, and
remove the unused local selectionOverlay table (symbols: Prefs, options,
selectionOverlay); if Prefs is used elsewhere keep the import but remove only
the options assignment and the selectionOverlay block to eliminate dead code and
leftover backwards-compatibility comments.

info.tacticalSiloMaxStorageCount = missileInfo.tacticalSiloMaxStorageCount
info.tacticalSiloStorageCount = missileInfo.tacticalSiloStorageCount

info.customName = unit:GetCustomName(unit)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does it work? There was an engine bug that I fixed, but I remember @Garanas complained about it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It doesn't work, you're right.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lua/keymap/selectedinfo.lua (1)

49-51: ⚠️ Potential issue | 🔴 Critical

Fix cycle handling nil-dereference in focus traversal.

At Line 50, info.focus is not guaranteed to exist. A self-referential focus can crash here. Use the current tail node (focusingInfo) instead.

Proposed fix
             if visited[id] then
-                info.focus.focus = nil
+                focusingInfo.focus = nil
                 break
             end
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/keymap/selectedinfo.lua` around lines 49 - 51, The cycle handling in the
focus traversal can nil-dereference because info.focus may not exist; update the
visited-check branch to operate on the current tail node (focusingInfo) instead
of directly using info.focus: when visited[id] is true, set focusingInfo.focus =
nil (or clear the focus on the current focusingInfo node after verifying it
exists) and then break to stop traversal. Ensure you reference and null-check
focusingInfo before mutating its .focus to avoid the self-referential crash.
🧹 Nitpick comments (1)
lua/keymap/selectedinfo.lua (1)

19-21: Document skipFocus in the function contract.

GetUnitRolloverInfo(unit, skipFocus) currently documents only unit. Adding skipFocus intent/behavior will make usage clearer and avoid guesswork.

Proposed doc update
 ---@param unit UserUnit
+---@param skipFocus? boolean -- when true, omit focus-chain expansion
 ---@return RolloverInfo
 function GetUnitRolloverInfo(unit, skipFocus)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/keymap/selectedinfo.lua` around lines 19 - 21, The function
GetUnitRolloverInfo(unit, skipFocus) documents only the unit parameter; add
documentation for the skipFocus parameter in the function contract by describing
its type (boolean), default behavior, and effect on rollover behavior (e.g.,
when true, do not change or focus the UI/selection or suppress related focus
side-effects), and include its return impact if any; update the function
signature comment block above GetUnitRolloverInfo to include `@param` skipFocus
and a short sentence about its intent and expected values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@lua/keymap/selectedinfo.lua`:
- Around line 49-51: The cycle handling in the focus traversal can
nil-dereference because info.focus may not exist; update the visited-check
branch to operate on the current tail node (focusingInfo) instead of directly
using info.focus: when visited[id] is true, set focusingInfo.focus = nil (or
clear the focus on the current focusingInfo node after verifying it exists) and
then break to stop traversal. Ensure you reference and null-check focusingInfo
before mutating its .focus to avoid the self-referential crash.

---

Nitpick comments:
In `@lua/keymap/selectedinfo.lua`:
- Around line 19-21: The function GetUnitRolloverInfo(unit, skipFocus) documents
only the unit parameter; add documentation for the skipFocus parameter in the
function contract by describing its type (boolean), default behavior, and effect
on rollover behavior (e.g., when true, do not change or focus the UI/selection
or suppress related focus side-effects), and include its return impact if any;
update the function signature comment block above GetUnitRolloverInfo to include
`@param` skipFocus and a short sentence about its intent and expected values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d419cf00-0e9c-42f0-aff6-504647312db8

📥 Commits

Reviewing files that changed from the base of the PR and between 1d9db33 and a1c107e.

📒 Files selected for processing (2)
  • engine/User/UserUnit.lua
  • lua/keymap/selectedinfo.lua

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: code style code refactoring area: ui Anything to do with the User Interface of the Game

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants