Skip to content

Commit

Permalink
Revert "Updated with a few changes"
Browse files Browse the repository at this point in the history
This reverts commit 797958d.
  • Loading branch information
DonJayamanne committed Jan 20, 2025
1 parent 797958d commit 380f4c5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/standalone/api/kernels/backgroundExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function execCodeInBackgroundThread<T>(
) {
const counter = executionCounters.get(kernel) || 0;
executionCounters.set(kernel, counter + 1);
const api = createKernelApiForExtension(JVSC_EXTENSION_ID, kernel);
const { api } = createKernelApiForExtension(JVSC_EXTENSION_ID, kernel);
const mime = `application/vnd.vscode.bg.execution.${counter}`;
const mimeFinalResult = `application/vnd.vscode.bg.execution.${counter}.result`;
const mimeErrorResult = `application/vnd.vscode.bg.execution.${counter}.error`;
Expand Down
15 changes: 10 additions & 5 deletions src/standalone/api/kernels/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { createDeferredFromPromise } from '../../../platform/common/utils/async'
import { logger } from '../../../platform/logging';
import { StopWatch } from '../../../platform/common/utils/stopWatch';
import { sendKernelTelemetryEvent } from '../../../kernels/telemetry/sendKernelTelemetryEvent';
import { KernelExecutionProgressIndicator } from './kernelProgressIndicator';

const extensionAPICache = new Map<
string,
Expand All @@ -26,16 +27,17 @@ const extensionAPICache = new Map<
waitUntil(thenable: Thenable<unknown>): void;
}>
| undefined;
// Kernel cache needs to be scoped per extension
kernels: WeakMap<IKernel, Kernel>;
// Kernel cache needs to be scoped per extension to make sure that the progress messages
// show accurately which extension is actually using it.
kernels: WeakMap<IKernel, { api: Kernel; progress: KernelExecutionProgressIndicator }>;
}
>();

function getOrCreateExtensionAPI(extensionId: string) {
if (!extensionAPICache.has(extensionId)) {
extensionAPICache.set(extensionId, {
onDidStart: undefined,
kernels: new WeakMap<IKernel, Kernel>()
kernels: new WeakMap<IKernel, { api: Kernel; progress: KernelExecutionProgressIndicator }>()
});
}
return extensionAPICache.get(extensionId)!;
Expand Down Expand Up @@ -72,7 +74,8 @@ export function getKernelsApi(extensionId: string): Kernels {
kernel.kernelConnectionMetadata
);
}
return getWrappedKernel(kernel, extensionId);
const { api } = getWrappedKernel(kernel, extensionId);
return api;
},
get onDidStart() {
if (![JVSC_EXTENSION_ID, DATA_WRANGLER_EXTENSION_ID].includes(extensionId)) {
Expand All @@ -94,7 +97,7 @@ export function getKernelsApi(extensionId: string): Kernels {
disposableRegistry.push(
extensionAPI.onDidStart,
kernelProvider.onDidPostInitializeKernel(({ kernel, token, waitUntil }) => {
const api = getWrappedKernel(kernel, extensionId);
const { api, progress } = getWrappedKernel(kernel, extensionId);
extensionAPI.onDidStart?.fire({
uri: kernel.uri,
kernel: api,
Expand All @@ -106,6 +109,7 @@ export function getKernelsApi(extensionId: string): Kernels {
// it is effectively preventing access to it.
const deferrable = createDeferredFromPromise(Promise.resolve(thenable));
waitUntil(thenable);
const disposable = progress.show();
const stopWatch = new StopWatch();
void deferrable.promise.finally(() => {
logger.trace(
Expand All @@ -117,6 +121,7 @@ export function getKernelsApi(extensionId: string): Kernels {
{ duration: stopWatch.elapsedTime },
{ extensionId }
);
disposable.dispose();
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/standalone/api/kernels/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class WrappedKernelPerExtension extends DisposableBase implements Kernel {
) {
const wrapper = new WrappedKernelPerExtension(extensionId, kernel, execution, controller);
ServiceContainer.instance.get<IDisposableRegistry>(IDisposableRegistry).push(wrapper);
return wrapper._api;
return { api: wrapper._api, progress: wrapper.progress };
}

private async checkAccess() {
Expand Down
2 changes: 1 addition & 1 deletion src/standalone/api/kernels/kernel.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ suite('Kernel Api', () => {

test('Verify Access Denied error message has expected value for the property `name`', async () => {
try {
const api = createKernelApiForExtension('xyz', instance(kernel));
const { api } = createKernelApiForExtension('xyz', instance(kernel));
for await (const x of api.executeCode('bogus', token)) {
assert.fail(`Should have failed without producing any value such as ${x}`);
}
Expand Down

0 comments on commit 380f4c5

Please sign in to comment.