Skip to content

Reshape automation bridge as typed rstudio.* namespaces (commands, prefs, documents) #17725

Closed

Description

@kevinushey

Summary

The current automation bridge (window.rstudioCallbacks, exposed by --automation-agent via ApplicationAutomation.java) is a flat bag of camelCased verbs:

window.rstudioCallbacks.commandExecute(id)
window.rstudioCallbacks.commandList()
window.rstudioCallbacks.commandIsChecked(id)
window.rstudioCallbacks.commandIsEnabled(id)
window.rstudioCallbacks.documentCloseAllNoSave()
window.rstudioCallbacks.prefGet(name)
window.rstudioCallbacks.prefSet(name, value)
window.rstudioCallbacks.prefClear(name)

Names are stringly-typed -- the caller has to know command IDs and pref names verbatim, and there's nothing the editor / TypeScript can autocomplete against. Adding more callbacks scales linearly with verb-prefix collisions (commandX, documentY, prefZ).

Proposed shape

Replace with a single window.rstudio root and per-domain namespaces. Commands become directly callable functions keyed by id; prefs become typed objects keyed by camelCase accessor name:

// Commands: each AppCommand is a callable with predicate helpers.
window.rstudio.commands.newProject()
window.rstudio.commands.newProject.isChecked()
window.rstudio.commands.newProject.isEnabled()
window.rstudio.commands.list                  // getter -> string[]

// Prefs: each pref is a typed object with explicit get/set/clear verbs.
// Keys are camelCase, matching the GWT accessor (UserPrefsAccessor.java).
window.rstudio.prefs.defaultProjectLocation.get()
window.rstudio.prefs.defaultProjectLocation.set(\"/some/path\")
window.rstudio.prefs.defaultProjectLocation.clear()

// Documents: small enough to keep flat for now.
window.rstudio.documents.closeAllNoSave()

Why this shape

  • One global: window.rstudio reads cleanly. The *Callbacks suffix doesn't add information.
  • Commands as callables: rstudio.commands.newProject() is shorter and self-documenting vs. commands.execute('newProject'). Predicate helpers (isChecked, isEnabled) attach naturally as function properties.
  • Prefs with explicit verbs: .get() / .set(v) / .clear() keeps persistence-side-effects visible. Getter/setter property syntax (rstudio.prefs.foo = x) would be terser but loses that, and has nowhere to put clear().
  • camelCase keys: aligns with the GWT accessor naming and avoids JS-side bracket quoting (rstudio.prefs['default-project-location'] -- ugly).
  • Discoverable: TypeScript declarations can be generated against the full command list and the user-prefs schema, giving editor autocomplete and compile-time pref-name checking in test code.

Implementation notes

  • Enumerate commands_.getCommands() once at initializeAgent() time and register a JSNI function per command id.
  • Enumerate userPrefs_.allPrefs() once and register a { get, set, clear } object per pref name. This warm-up incidentally fixes the silent-failure bug tracked in Automation bridge: prefSet/prefGet/prefClear silently fail for prefs not yet registered #17724 -- every pref ends up in Prefs.values_ from the outset.
  • Generate a .d.ts for the JS-side test code -- both command ids and pref names are already known statically (Commands.cmd.xml, user-prefs-schema.json).

Migration

Breaking change for the bridge surface. Affects all consumers under e2e/rstudio/ (utils/commands.ts, actions/*.ts, fixtures). Migration is mechanical -- rewrite the call sites to the new namespaces. The old flat callbacks can be removed in the same PR since --automation-agent isn't a stable public API.

Related

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    developerenhancementnew

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions