Skip to content

Commit

Permalink
Remove unwanted API (#14726)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Nov 15, 2023
1 parent ca1be55 commit 599729d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 21 deletions.
7 changes: 0 additions & 7 deletions src/api.unstable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ declare module './api' {
* There are a specific set of extensions that are currently allowed to access this API.
*/
getKernelService(): Promise<IExportedKernelService | undefined>;
/**
* Opens a notebook with a specific kernel as the active kernel.
* @param {Uri} uri Uri of the notebook to open.
* @param {String} kernel The kernel returned by the API kernels.getKernel(uri)
* @returns {Promise<NotebookDocument>} Promise that resolves to the notebook document.
*/
openNotebook(uri: Uri, kernel: Kernel): Promise<NotebookDocument>;
/**
* Opens a notebook with a specific kernel as the active kernel.
* @param {Uri} uri Uri of the notebook to open.
Expand Down
7 changes: 1 addition & 6 deletions src/kernels/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Telemetry, sendTelemetryEvent } from '../../telemetry';
// Each extension gets its own instance of the API.
const apiCache = new Map<string, Promise<boolean>>();
const kernelCache = new WeakMap<IKernel, Kernel>();
const mappedKernelId = new WeakMap<Kernel, string>();

// This is only temporary for testing purposes. Even with the prompt other extensions will not be allowed to use this API.
// By the end of the iteartion we will have a proposed API and this will be removed.
Expand Down Expand Up @@ -49,6 +48,7 @@ export function getKernelsApi(extensionId: string): Kernels {
});
return;
}
// Check and prompt for access only if we know we have a kernel.
accessAllowed = await requestKernelAccess(extensionId);
sendTelemetryEvent(Telemetry.NewJupyterKernelsApiUsage, undefined, {
extensionId,
Expand All @@ -61,16 +61,11 @@ export function getKernelsApi(extensionId: string): Kernels {

let wrappedKernel = kernelCache.get(kernel) || createKernelApiForExtension(extensionId, kernel);
kernelCache.set(kernel, wrappedKernel);
mappedKernelId.set(wrappedKernel, kernel.id);
return wrappedKernel;
}
};
}

export function getKernelId(kernel: Kernel) {
return mappedKernelId.get(kernel);
}

async function requestKernelAccess(extensionId: string): Promise<boolean> {
if (extensionId === JVSC_EXTENSION_ID_FOR_TESTS) {
// Our own extension can use this API (used in tests)
Expand Down
11 changes: 3 additions & 8 deletions src/standalone/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ import {
IJupyterUriProvider,
JupyterServerCollection,
JupyterServerCommandProvider,
JupyterServerProvider,
Kernel
JupyterServerProvider
} from '../../api';
import { stripCodicons } from '../../platform/common/helpers';
import { jupyterServerUriToCollection } from '../../kernels/jupyter/connection/jupyterServerProviderRegistry';
import { getKernelId, getKernelsApi } from '../../kernels/api/api';
import { getKernelsApi } from '../../kernels/api/api';

export const IExportedKernelServiceFactory = Symbol('IExportedKernelServiceFactory');
export interface IExportedKernelServiceFactory {
Expand Down Expand Up @@ -186,15 +185,11 @@ export function buildApi(
await selector.addJupyterServer({ id: providerId, handle, extensionId });
await controllerCreatedPromise;
},
openNotebook: async (uri: Uri, kernelIdOrKernel: string | Kernel) => {
openNotebook: async (uri: Uri, kernelId: string) => {
sendTelemetryEvent(Telemetry.JupyterApiUsage, undefined, {
clientExtId: extensions.determineExtensionFromCallStack().extensionId,
pemUsed: 'openNotebook'
});
const kernelId = typeof kernelIdOrKernel === 'string' ? kernelIdOrKernel : getKernelId(kernelIdOrKernel);
if (!kernelId) {
throw new Error(`Kernel instance ${kernelId} not found.`);
}
const controllers = serviceContainer.get<IControllerRegistration>(IControllerRegistration);
const id = controllers.all.find((controller) => controller.id === kernelId)?.id;
if (!id) {
Expand Down

0 comments on commit 599729d

Please sign in to comment.