sourcegraph/client/shared/src/extensions/createSyncLoadedController.ts
Quinn Slack e99c4145f7
remove enableLegacyExtensions and all now-unreachable code (#47517)
This is part of the extension API deprecation
(https://docs.google.com/document/d/10vtoe-kpNvVZ8Etrx34bSCoTaCCHxX8o3ncCmuErPZo/edit).

There are a lot more refactors to do after this, but this removes the
admin-facing `enableLegacyExtensions` setting and some of the root-level
instantiation and usage of the extensions controller API.

## Test plan

Check that hovers still work on dotcom.
2023-02-25 10:28:43 -08:00

69 lines
2.5 KiB
TypeScript

import { from, Subscription } from 'rxjs'
import { switchMap } from 'rxjs/operators'
import { createExtensionHostClientConnection } from '../api/client/connection'
import type { InitData } from '../api/extension/extensionHost'
import { syncPromiseSubscription } from '../api/util'
import type { PlatformContext } from '../platform/context'
import type { Controller } from './controller'
/**
* Creates the controller, which handles all communication between the client application and extensions.
*
* There should only be a single controller for the entire client application. The controller's model represents
* all of the client application state that the client needs to know.
*
* The implementation (`createExtensionHostClientConnection`) is lazy loaded to avoid adding bytes when
* the extension system is disabled
*/
export function createController(
context: Pick<
PlatformContext,
| 'updateSettings'
| 'settings'
| 'getGraphQLClient'
| 'requestGraphQL'
| 'showMessage'
| 'showInputBox'
| 'getStaticExtensions'
| 'telemetryService'
| 'clientApplication'
| 'sourcegraphURL'
| 'createExtensionHost'
>
): Controller {
const subscriptions = new Subscription()
const initData: Omit<InitData, 'initialSettings'> = {
sourcegraphURL: context.sourcegraphURL,
clientApplication: context.clientApplication,
}
const extensionHostClientPromise = createExtensionHostClientConnection(
context.createExtensionHost(),
initData,
context
)
subscriptions.add(() => extensionHostClientPromise.then(({ subscription }) => subscription.unsubscribe()))
// TODO: Debug helpers, logging
return {
executeCommand: (parameters, suppressNotificationOnError) =>
extensionHostClientPromise.then(({ exposedToClient }) =>
exposedToClient.executeCommand(parameters, suppressNotificationOnError)
),
commandErrors: from(extensionHostClientPromise).pipe(
switchMap(({ exposedToClient }) => exposedToClient.commandErrors)
),
registerCommand: entryToRegister =>
syncPromiseSubscription(
extensionHostClientPromise.then(({ exposedToClient }) =>
exposedToClient.registerCommand(entryToRegister)
)
),
extHostAPI: extensionHostClientPromise.then(({ api }) => api),
unsubscribe: () => subscriptions.unsubscribe(),
}
}