Skip to content

refactor: declarative command registry (-196 net lines)#65

Open
CompN3rd wants to merge 2 commits into
mainfrom
refactor/command-registry
Open

refactor: declarative command registry (-196 net lines)#65
CompN3rd wants to merge 2 commits into
mainfrom
refactor/command-registry

Conversation

@CompN3rd
Copy link
Copy Markdown
Owner

Changes

New: src/commands/commandRegistry.ts

CommandRegistry class with three helpers:

  • add(id, handler) — plain command.
  • addGuarded(id, handler) — runs ensureSignedIn first; aborts silently if not signed in.
  • addRefreshing(id, handler, refresh) — guarded; calls refresh() when handler returns truthy.

Refactored src/extension.ts

All 64 command registrations migrated. Removes the context.subscriptions.push(vscode.commands.registerCommand(...)) boilerplate and the repetitive if (!(await ensureSignedIn())) { return; } / if (updated) refresh() blocks.

Impact

  • extension.ts: 1186 → 930 lines (-256 lines in the file, -196 net including the new registry).
  • Bundle: 1.3 mb → 1.2 mb after minification.
  • Zero behavior change. Same command IDs, same handler signatures, same semantics.

Verification

  • npm run compile — both tsc passes + esbuild bundles green.
  • npm run lint — 0 warnings, 0 errors.

Notes

  • Custom-shaped commands (e.g. signIn with optional arg, setWorkItemFilter with input box flow, addPullRequestComment with try/catch) stay on plain add() since their bodies don't match the guarded/refreshing shape; the win there is just removing the wrapper boilerplate.
  • mcpManager is still declared after signOut is registered — preserved by JS closure capture, same as before this refactor.

Adds src/commands/commandRegistry.ts with three helpers (add, addGuarded, addRefreshing) that fold the common command shapes: plain commands, sign-in-gated commands, and gated+refresh-on-truthy commands.

Migrates all 64 command registrations in extension.ts to use the registry. Net savings: 256 lines (1186 -> 930).

No behavior change. All command IDs, signatures, and semantics preserved.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors command registration in the extension activation path by introducing a small CommandRegistry helper and migrating command registrations in src/extension.ts to a more declarative style, reducing repeated boilerplate around registerCommand, ensureSignedIn, and “refresh if updated” patterns.

Changes:

  • Add CommandRegistry (add, addGuarded, addRefreshing) to centralize common command wrapper patterns.
  • Migrate command registrations in src/extension.ts to use CommandRegistry, reducing repeated context.subscriptions.push(registerCommand(...)) and guard/refresh wrappers.
  • Register all command disposables at the end via registry.registerAll(context).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/extension.ts Migrates command registrations to CommandRegistry and centralizes registration/disposal.
src/commands/commandRegistry.ts Introduces CommandRegistry with helpers for plain/guarded/refreshing command shapes.

Comment thread src/extension.ts Outdated
workItemProvider.refresh();
})
);
registry.addGuarded('adoext.refreshWorkItems', () => {
Comment thread src/extension.ts Outdated
if (!choice || choice.value === current) {
return;
}
registry.addGuarded('adoext.refreshBacklog', () => {
Comment thread src/extension.ts Outdated
boardProvider.refresh();
})
);
registry.addGuarded('adoext.refreshSprints', () => {
Comment thread src/extension.ts Outdated
await PlanningPanel.show(context, 'backlog', client, config, refreshAllViews);
})
);
registry.addGuarded('adoext.refreshBoards', () => {
Comment thread src/extension.ts Outdated
pullRequestProvider.refresh();
})
);
registry.addGuarded('adoext.refreshPullRequests', () => {
Comment thread src/extension.ts Outdated
pipelinesProvider.refresh();
})
);
registry.addGuarded('adoext.refreshPipelines', () => {
Pre-refactor behavior was that 'adoext.refresh*' commands always invoked
the provider's refresh() regardless of sign-in state, which let the tree
transition into its setup / signed-out node.

After moving them to addGuarded, refresh() was suppressed on sign-in
failure and the tree kept whatever stale content it had. Reviewer flagged
six commands: refreshWorkItems, refreshBacklog, refreshSprints,
refreshBoards, refreshPullRequests, refreshPipelines.

Add CommandRegistry.addRefresh() for the 'fire-and-forget view refresh'
shape and switch all six over.
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