Skip to content

[Feature] Encapsulate debug config provider with controlled getter #2792

Description

@EmmaYuan1015

Problem

The debugConfigProvider is exported as a global nullable variable, leading to:

  • Null check dispersal: Every consumer must check for null before usage
  • Lifecycle risk: Race conditions at extension activation/deactivation boundaries
  • Type safety: Non-null assertions required despite nullable type union
  • Maintenance burden: Hard to track all null checks across codebase

Related code:

Solution

Replace export global variable with controlled getter pattern:

  • Private state: debugConfigProvider
  • Public API: getDebugConfigProvider() - throws if not initialized
  • Internal setter: setDebugConfigProvider() - used only during lifecycle

Benefits

✅ Centralized null validation (single point of check)
✅ Clear initialization contract (throws with descriptive error)
✅ Type-safe for consumers (non-null guarantee)
✅ Improved code maintainability (fewer defensive checks)
✅ Better lifecycle management

Changes

  • src/extension/rn-extension.ts: Added getter/setter pattern
  • src/extension/commands/selectAndInsertDebugConfiguration.ts: Use getter, remove null check

Testing

✅ Build passes: 0 errors, 161 warnings (pre-existing)
✅ TypeScript: No compilation errors
✅ Formatter: All Prettier checks passed

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions